Implement tracker login and logout
This commit is contained in:
@@ -28,6 +28,7 @@ import WebIcon from '@mui/icons-material/Web';
|
||||
import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
|
||||
import ExploreOutlinedIcon from '@mui/icons-material/ExploreOutlined';
|
||||
import DevicesIcon from '@mui/icons-material/Devices';
|
||||
import SyncIcon from '@mui/icons-material/Sync';
|
||||
import { langCodeToName } from '@/util/language';
|
||||
import { useLocalStorage } from '@/util/useLocalStorage';
|
||||
import { ListItemLink } from '@/components/util/ListItemLink';
|
||||
@@ -94,6 +95,12 @@ export function Settings() {
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={t('download.title')} />
|
||||
</ListItemLink>
|
||||
<ListItemLink to="/settings/trackingSettings">
|
||||
<ListItemIcon>
|
||||
<SyncIcon />
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={t('tracking.title')} />
|
||||
</ListItemLink>
|
||||
<ListItemLink to="/settings/backup">
|
||||
<ListItemIcon>
|
||||
<BackupIcon />
|
||||
|
||||
52
src/screens/TrackerOAuthLogin.tsx
Normal file
52
src/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/RequestManager.ts';
|
||||
import { makeToast } from '@/components/util/Toast.tsx';
|
||||
|
||||
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;
|
||||
};
|
||||
52
src/screens/settings/TrackingSettings.tsx
Normal file
52
src/screens/settings/TrackingSettings.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 { useTranslation } from 'react-i18next';
|
||||
import { useContext, useEffect } from 'react';
|
||||
import List from '@mui/material/List';
|
||||
|
||||
import ListSubheader from '@mui/material/ListSubheader';
|
||||
import { NavBarContext } from '@/components/context/NavbarContext.tsx';
|
||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||
import { EmptyView } from '@/components/util/EmptyView.tsx';
|
||||
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
|
||||
import { SettingsTrackerCard } from '@/components/tracker/SettingsTrackerCard.tsx';
|
||||
|
||||
export const TrackingSettings = () => {
|
||||
const { t } = useTranslation();
|
||||
const { setTitle } = useContext(NavBarContext);
|
||||
|
||||
useEffect(() => {
|
||||
setTitle(t('tracking.settings.title.settings'));
|
||||
}, [t]);
|
||||
|
||||
const { data, loading, error } = requestManager.useGetTrackerList();
|
||||
const trackers = data?.trackers.nodes ?? [];
|
||||
|
||||
if (error) {
|
||||
return <EmptyView message={error.message ?? error} />;
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <LoadingPlaceholder />;
|
||||
}
|
||||
|
||||
return (
|
||||
<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