Files
suwayomi-material-you-webui/src/modules/settings/screens/About.tsx

184 lines
7.8 KiB
TypeScript
Raw Normal View History

/*
* 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 { useContext, useLayoutEffect } from 'react';
2021-09-09 17:51:22 +04:30
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
import ListItemText from '@mui/material/ListItemText';
import { useTranslation } from 'react-i18next';
import ListSubheader from '@mui/material/ListSubheader';
import Divider from '@mui/material/Divider';
import { requestManager } from '@/lib/requests/RequestManager.ts';
2024-10-05 16:09:34 +02:00
import { ListItemLink } from '@/modules/core/components/ListItemLink.tsx';
import { NavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx';
2024-10-05 16:09:34 +02:00
import { LoadingPlaceholder } from '@/modules/core/components/placeholder/LoadingPlaceholder.tsx';
import { UpdateState } from '@/lib/graphql/generated/graphql.ts';
2024-10-05 16:09:34 +02:00
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
import { EmptyViewAbsoluteCentered } from '@/modules/core/components/placeholder/EmptyViewAbsoluteCentered.tsx';
import { getBuildTime, getVersion } from '@/modules/app-updates/services/AppUpdateChecker.tsx';
import { VersionInfo } from '@/modules/app-updates/components/VersionInfo.tsx';
2021-05-25 21:06:27 +04:30
2023-10-28 00:32:02 +02:00
export function About() {
const { t } = useTranslation();
2023-10-28 00:32:02 +02:00
const { setTitle, setAction } = useContext(NavBarContext);
2021-05-25 21:06:27 +04:30
useLayoutEffect(() => {
setTitle(t('settings.about.title'));
setAction(null);
return () => {
setTitle('');
setAction(null);
};
}, [t]);
2021-05-25 21:06:27 +04:30
2024-04-27 22:28:55 +02:00
const { data, loading, error, refetch } = requestManager.useGetAbout({ notifyOnNetworkStatusChange: true });
2021-05-25 21:06:27 +04:30
const {
data: serverUpdateCheckData,
loading: isCheckingForServerUpdate,
refetch: checkForServerUpdate,
error: serverUpdateCheckError,
} = requestManager.useCheckForServerUpdate({ notifyOnNetworkStatusChange: true });
const {
data: webUIUpdateData,
loading: isCheckingForWebUIUpdate,
refetch: checkForWebUIUpdate,
error: orgWebUIUpdateCheckError,
} = requestManager.useCheckForWebUIUpdate({ notifyOnNetworkStatusChange: true });
const webUIUpdateCheckError = orgWebUIUpdateCheckError || webUIUpdateData?.checkForWebUIUpdate.tag === '';
const { data: webUIUpdateStatusData } = requestManager.useGetWebUIUpdateStatus();
const { state: webUIUpdateState, progress: webUIUpdateProgress } = webUIUpdateStatusData?.getWebUIUpdateStatus ?? {
state: UpdateState.Idle,
progress: 0,
};
2024-04-27 16:24:55 +02:00
if (loading) {
return <LoadingPlaceholder />;
}
2024-04-27 22:28:55 +02:00
if (error) {
return (
2024-04-29 15:29:33 +02:00
<EmptyViewAbsoluteCentered
2024-04-27 22:28:55 +02:00
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('About::refetch'))}
/>
);
}
2024-05-05 00:36:16 +02:00
const { aboutServer, aboutWebUI } = data!;
const selectedServerChannelInfo = serverUpdateCheckData?.checkForServerUpdates?.find(
(channel) => channel.channel === aboutServer.buildType,
);
const isServerUpdateAvailable =
!!selectedServerChannelInfo?.tag && selectedServerChannelInfo.tag !== getVersion(aboutServer);
const isWebUIUpdateAvailable = !!webUIUpdateData?.checkForWebUIUpdate.updateAvailable;
2021-05-25 21:06:27 +04:30
return (
2024-09-05 00:34:13 +02:00
<List sx={{ pt: 0 }}>
<List
sx={{ padding: 0 }}
subheader={
<ListSubheader component="div" id="about-server-info">
{t('settings.server.title.server')}
</ListSubheader>
}
>
<ListItem>
<ListItemText
primary={t('settings.server.title.server')}
secondary={`${aboutServer.name} ${aboutServer.buildType}`}
/>
</ListItem>
<ListItem>
<ListItemText
primary={t('settings.about.server.label.version')}
secondary={
<VersionInfo
version={getVersion(aboutServer)}
isCheckingForUpdate={isCheckingForServerUpdate}
isUpdateAvailable={isServerUpdateAvailable}
updateCheckError={serverUpdateCheckError}
checkForUpdate={checkForServerUpdate}
downloadAsLink
url={selectedServerChannelInfo?.url ?? ''}
/>
}
/>
</ListItem>
<ListItem>
<ListItemText
primary={t('settings.about.server.label.build_time')}
secondary={getBuildTime(aboutServer)}
/>
</ListItem>
</List>
<Divider />
<List
sx={{ padding: 0 }}
subheader={
<ListSubheader component="div" id="about-webui-info">
{t('settings.webui.title.webui')}
</ListSubheader>
}
>
2024-04-21 12:51:08 +02:00
<ListItem>
<ListItemText
primary={t('settings.about.webui.label.channel')}
secondary={aboutWebUI.channel.toLocaleUpperCase()}
/>
</ListItem>
<ListItem>
<ListItemText
primary={t('settings.about.webui.label.version')}
secondary={
<VersionInfo
version={aboutWebUI.tag}
isCheckingForUpdate={isCheckingForWebUIUpdate}
isUpdateAvailable={isWebUIUpdateAvailable}
updateCheckError={webUIUpdateCheckError}
checkForUpdate={checkForWebUIUpdate}
triggerUpdate={() =>
requestManager
.updateWebUI()
.response.catch(defaultPromiseErrorHandler('About::updateWebUI'))
}
progress={webUIUpdateProgress}
updateState={webUIUpdateState}
/>
}
/>
</ListItem>
</List>
<Divider />
<List
subheader={
<ListSubheader component="div" id="about-links">
{t('global.label.links')}
</ListSubheader>
}
>
2024-05-04 23:54:33 +02:00
<ListItemLink to={aboutServer.github} target="_blank" rel="noreferrer">
<ListItemText primary={t('settings.about.server.label.github')} secondary={aboutServer.github} />
</ListItemLink>
2024-05-04 23:54:33 +02:00
<ListItemLink to="https://github.com/Suwayomi/Suwayomi-WebUI" target="_blank" rel="noreferrer">
<ListItemText
primary={t('settings.about.webui.label.github')}
secondary="https://github.com/Suwayomi/Suwayomi-WebUI"
/>
</ListItemLink>
2024-05-04 23:54:33 +02:00
<ListItemLink to={aboutServer.discord} target="_blank" rel="noreferrer">
<ListItemText primary={t('global.label.discord')} secondary={aboutServer.discord} />
</ListItemLink>
</List>
2021-05-25 21:06:27 +04:30
</List>
);
}