* - Changed the value in Manga from 960 to 900( md breakpooint) - The CicularLoader in About and Reader screens is now centered to the whole screen - Changed relative imports in About screen to absolute imports - removed changed styles from Browse Screen, PageNumber * Migrated Source Card, Extension Card and LoadingPlaceHolder to MUI system * Migrated CategorySelect and LandSelect to using the sx prop * migrated ReaderNavbar to mui 5 * - Removed Unused Styles from Page - Migrated DoublePage, doublePagedPager, PagedPager, Vertical Pager and Horizontal Pager. * Replaced style prop with sx prop * removed useStyles completely from the project except for the Manga Screen * added a comment * Fixed the Source Card Buttons padding * Removed the trailing backspace Co-authored-by: Sascha Hahne <ntbm@users.noreply.github.com> Co-authored-by: Sascha Hahne <ntbm@users.noreply.github.com>
135 lines
4.2 KiB
TypeScript
135 lines
4.2 KiB
TypeScript
/*
|
|
* 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 React, { useState } from 'react';
|
|
import Card from '@mui/material/Card';
|
|
import CardContent from '@mui/material/CardContent';
|
|
import Button from '@mui/material/Button';
|
|
import Avatar from '@mui/material/Avatar';
|
|
import Typography from '@mui/material/Typography';
|
|
import client from 'util/client';
|
|
import useLocalStorage from 'util/useLocalStorage';
|
|
import { Box } from '@mui/system';
|
|
|
|
interface IProps {
|
|
extension: IExtension
|
|
notifyInstall: () => void
|
|
}
|
|
|
|
export default function ExtensionCard(props: IProps) {
|
|
const {
|
|
extension: {
|
|
name, lang, versionName, installed, hasUpdate, obsolete, pkgName, iconUrl,
|
|
},
|
|
notifyInstall,
|
|
} = props;
|
|
const [installedState, setInstalledState] = useState<string>(
|
|
() => {
|
|
if (obsolete) { return 'obsolete'; }
|
|
if (hasUpdate) { return 'update'; }
|
|
return (installed ? 'uninstall' : 'install');
|
|
},
|
|
);
|
|
|
|
const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
|
|
const [useCache] = useLocalStorage<boolean>('useCache', true);
|
|
|
|
const langPress = lang === 'all' ? 'All' : lang.toUpperCase();
|
|
|
|
function install() {
|
|
setInstalledState('installing');
|
|
client.get(`/api/v1/extension/install/${pkgName}`)
|
|
.then(() => {
|
|
setInstalledState('uninstall');
|
|
notifyInstall();
|
|
});
|
|
}
|
|
|
|
function update() {
|
|
setInstalledState('updating');
|
|
client.get(`/api/v1/extension/update/${pkgName}`)
|
|
.then(() => {
|
|
setInstalledState('uninstall');
|
|
notifyInstall();
|
|
});
|
|
}
|
|
|
|
function uninstall() {
|
|
setInstalledState('uninstalling');
|
|
client.get(`/api/v1/extension/uninstall/${pkgName}`)
|
|
.then(() => {
|
|
// setInstalledState('install');
|
|
notifyInstall();
|
|
});
|
|
}
|
|
|
|
function handleButtonClick() {
|
|
switch (installedState) {
|
|
case 'install':
|
|
install();
|
|
break;
|
|
case 'update':
|
|
update();
|
|
break;
|
|
case 'obsolete':
|
|
uninstall();
|
|
setTimeout(() => window.location.reload(), 3000);
|
|
break;
|
|
case 'uninstall':
|
|
uninstall();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Card sx={{ margin: '10px' }}>
|
|
<CardContent sx={{
|
|
display: 'flex',
|
|
justifyContent: 'space-between',
|
|
alignItems: 'center',
|
|
p: 2,
|
|
}}
|
|
>
|
|
<Box sx={{ display: 'flex' }}>
|
|
<Avatar
|
|
variant="rounded"
|
|
sx={{
|
|
width: '56px',
|
|
height: '56px',
|
|
flex: '0 0 auto',
|
|
mr: 2,
|
|
}}
|
|
alt={name}
|
|
src={`${serverAddress}${iconUrl}?useCache=${useCache}`}
|
|
/>
|
|
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
|
|
<Typography variant="h5" component="h2">
|
|
{name}
|
|
</Typography>
|
|
<Typography variant="caption" display="block" gutterBottom>
|
|
{langPress}
|
|
{' '}
|
|
{versionName}
|
|
</Typography>
|
|
</Box>
|
|
</Box>
|
|
|
|
<Button
|
|
variant="outlined"
|
|
style={{ color: installedState === 'obsolete' ? 'red' : 'inherit' }}
|
|
onClick={() => handleButtonClick()}
|
|
>
|
|
{installedState}
|
|
|
|
</Button>
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|