Move tracker files into new folder
This commit is contained in:
52
src/modules/tracker/screens/TrackerOAuthLogin.tsx
Normal file
52
src/modules/tracker/screens/TrackerOAuthLogin.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 { useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { requestManager } from '@/lib/requests/requests/RequestManager.ts';
|
||||
import { makeToast } from '@/lib/ui/Toast.ts';
|
||||
|
||||
export const TrackerOAuthLogin = () => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const url = new URL(window.location.href);
|
||||
const { trackerId, trackerName }: { trackerId: number; trackerName: string } = JSON.parse(
|
||||
url.searchParams.get('state') ?? '{}',
|
||||
);
|
||||
|
||||
const [loginTrackerOAuth, { loading: isLoginInProgress }] = requestManager.useLoginToTrackerOauth();
|
||||
|
||||
useEffect(() => {
|
||||
const login = async () => {
|
||||
try {
|
||||
await loginTrackerOAuth({
|
||||
variables: {
|
||||
input: {
|
||||
callbackUrl: window.location.href,
|
||||
trackerId,
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
makeToast(t('tracking.action.login.label.failure', { name: trackerName }), 'error');
|
||||
}
|
||||
|
||||
navigate('/settings/trackingSettings', { replace: true });
|
||||
};
|
||||
|
||||
login();
|
||||
}, [trackerId]);
|
||||
|
||||
if (isLoginInProgress) {
|
||||
return t('tracking.action.login.label.progress', { name: trackerName });
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
124
src/modules/tracker/screens/TrackingSettings.tsx
Normal file
124
src/modules/tracker/screens/TrackingSettings.tsx
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 { useTranslation } from 'react-i18next';
|
||||
import { useContext, useLayoutEffect } from 'react';
|
||||
import List from '@mui/material/List';
|
||||
|
||||
import ListSubheader from '@mui/material/ListSubheader';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import ListItemText from '@mui/material/ListItemText';
|
||||
import Switch from '@mui/material/Switch';
|
||||
import { NavBarContext } from '@/components/context/NavbarContext.tsx';
|
||||
import { requestManager } from '@/lib/requests/requests/RequestManager.ts';
|
||||
import { EmptyViewAbsoluteCentered } from '@/modules/core/components/placeholder/EmptyViewAbsoluteCentered.tsx';
|
||||
import { LoadingPlaceholder } from '@/modules/core/components/placeholder/LoadingPlaceholder.tsx';
|
||||
import { SettingsTrackerCard } from '@/modules/tracker/components/cards/SettingsTrackerCard.tsx';
|
||||
import {
|
||||
createUpdateMetadataServerSettings,
|
||||
useMetadataServerSettings,
|
||||
} from '@/lib/metadata/metadataServerSettings.ts';
|
||||
import { makeToast } from '@/lib/ui/Toast.ts';
|
||||
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
|
||||
import { GET_TRACKERS_SETTINGS } from '@/lib/graphql/queries/TrackerQuery.ts';
|
||||
import { GetTrackersSettingsQuery } from '@/lib/graphql/generated/graphql.ts';
|
||||
import { MetadataTrackingSettings } from '@/modules/tracker/Tracker.types.ts';
|
||||
|
||||
export const TrackingSettings = () => {
|
||||
const { t } = useTranslation();
|
||||
const { setTitle } = useContext(NavBarContext);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
setTitle(t('tracking.settings.title.settings'));
|
||||
}, [t]);
|
||||
|
||||
const {
|
||||
settings: { updateProgressAfterReading, updateProgressManualMarkRead },
|
||||
loading: areMetadataServerSettingsLoading,
|
||||
request: { error: metadataServerSettingsError, refetch: refetchServerMetadataSettings },
|
||||
} = useMetadataServerSettings();
|
||||
const updateTrackingSettings = createUpdateMetadataServerSettings<keyof MetadataTrackingSettings>(() =>
|
||||
makeToast(t('global.error.label.failed_to_save_changes'), 'error'),
|
||||
);
|
||||
|
||||
const {
|
||||
data,
|
||||
loading: areTrackersLoading,
|
||||
error: trackersError,
|
||||
refetch: refetchTrackersList,
|
||||
} = requestManager.useGetTrackerList<GetTrackersSettingsQuery>(GET_TRACKERS_SETTINGS, {
|
||||
notifyOnNetworkStatusChange: true,
|
||||
});
|
||||
const trackers = data?.trackers.nodes ?? [];
|
||||
|
||||
const loading = areMetadataServerSettingsLoading || areTrackersLoading;
|
||||
const error = metadataServerSettingsError ?? trackersError;
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<EmptyViewAbsoluteCentered
|
||||
message={t('global.error.label.failed_to_load_data')}
|
||||
messageExtra={error.message}
|
||||
retry={() => {
|
||||
if (metadataServerSettingsError) {
|
||||
refetchServerMetadataSettings().catch(
|
||||
defaultPromiseErrorHandler('TrackingSettings::refetchMetadataServerSettings'),
|
||||
);
|
||||
}
|
||||
|
||||
if (trackersError) {
|
||||
refetchTrackersList().catch(
|
||||
defaultPromiseErrorHandler('TrackingSettings::refetchTrackersList'),
|
||||
);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <LoadingPlaceholder />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<List sx={{ pt: 0 }}>
|
||||
<ListItem>
|
||||
<ListItemText primary={t('tracking.settings.label.update_progress_reading')} />
|
||||
<Switch
|
||||
edge="end"
|
||||
checked={updateProgressAfterReading}
|
||||
onChange={(e) => updateTrackingSettings('updateProgressAfterReading', e.target.checked)}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText
|
||||
primary={t('tracking.settings.label.update_progress_manual')}
|
||||
secondary={t('tracking.settings.label.update_progress_reading_description')}
|
||||
/>
|
||||
<Switch
|
||||
edge="end"
|
||||
checked={updateProgressManualMarkRead}
|
||||
onChange={(e) => updateTrackingSettings('updateProgressManualMarkRead', e.target.checked)}
|
||||
/>
|
||||
</ListItem>
|
||||
</List>
|
||||
<List
|
||||
subheader={
|
||||
<ListSubheader component="div" id="tracking-trackers">
|
||||
{t('tracking.settings.title.trackers')}
|
||||
</ListSubheader>
|
||||
}
|
||||
>
|
||||
{trackers.map((tracker) => (
|
||||
<SettingsTrackerCard key={tracker.id} tracker={tracker} />
|
||||
))}
|
||||
</List>
|
||||
</>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user