/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import Avatar from '@mui/material/Avatar';
import { useTranslation } from 'react-i18next';
import {
Box,
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
Divider,
IconButton,
Link,
ListItemButton,
MenuItem,
Stack,
Tooltip,
Typography,
} from '@mui/material';
import MoreVertIcon from '@mui/icons-material/MoreVert';
import PopupState, { bindDialog, bindMenu, bindTrigger } from 'material-ui-popup-state';
import { requestManager } from '@/lib/requests/RequestManager.ts';
import { Trackers, TTrackRecord, UNSET_DATE } from '@/lib/data/Trackers.ts';
import { ListPreference } from '@/components/sourceConfiguration/ListPreference.tsx';
import { NumberSetting } from '@/components/settings/NumberSetting.tsx';
import { DateSetting } from '@/components/settings/DateSetting.tsx';
import { makeToast } from '@/components/util/Toast.tsx';
import { Menu } from '@/components/menu/Menu';
import { CARD_STYLING } from '@/components/tracker/constants.ts';
import { TypographyMaxLines } from '@/components/atoms/TypographyMaxLines.tsx';
const TrackerActiveLink = ({ children, url }: { children: React.ReactNode; url: string }) => (
{children}
);
const TrackerActiveRemoveBind = ({
trackRecord: { tracker, ...trackRecord },
onClick,
onClose,
}: {
trackRecord: TTrackRecord;
onClick: () => void;
onClose: () => void;
}) => {
const { t } = useTranslation();
// TODO - enable once server supports removing track binding on tracker source
// const [removeRemoteTracking, setRemoveRemoteTracking] = useState(false);
const removeBind = () => {
onClose();
requestManager
.updateTrackerBind(trackRecord.id, { unbind: true })
.response.then(() => makeToast(t('manga.action.track.remove.label.success'), 'success'))
.catch(() => makeToast(t('manga.action.track.remove.label.error'), 'error'));
};
return (
{(popupState) => (
<>
>
)}
);
};
const TrackerActiveHeader = ({
trackRecord: { tracker, ...trackRecord },
openSearch,
}: {
trackRecord: TTrackRecord;
openSearch: () => void;
}) => {
const { t } = useTranslation();
return (
{trackRecord.title}
{(popupState) => (
<>
>
)}
);
};
const TrackerActiveCardInfoRow = ({ children }: { children: React.ReactNode }) => (
{children}
);
export const TrackerActiveCard = ({
trackRecord: { tracker, ...trackRecord },
onClick,
}: {
trackRecord: TTrackRecord;
onClick: () => void;
}) => {
const { t } = useTranslation();
const updateTrackerBind = (patch: Parameters[1]) => {
requestManager
.updateTrackerBind(trackRecord.id, patch)
.response.catch(() => makeToast(t('global.error.label.failed_to_save_changes'), 'error'));
};
return (
status.name)}
key="status"
type="ListPreference"
entryValues={tracker.statuses.map((status) => `${status.value}`)}
ListPreferenceCurrentValue={`${trackRecord.status}`}
updateValue={(_, status) =>
updateTrackerBind({ status: status as unknown as number })
}
summary="%s"
/>
updateTrackerBind({ lastChapterRead })}
/>
updateTrackerBind({
scoreString:
newScore === 0
? tracker.scores[0]
: tracker.scores.find((score) => Number(score) === newScore),
})
}
/>
updateTrackerBind({ startDate: startDate ?? UNSET_DATE })
}
/>
updateTrackerBind({ finishDate: finishDate ?? UNSET_DATE })
}
/>
);
};