/* * 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 FavoriteIcon from '@mui/icons-material/Favorite'; import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder'; import PublicIcon from '@mui/icons-material/Public'; import { Typography } from '@mui/material'; import IconButton from '@mui/material/IconButton'; import { Theme } from '@mui/material/styles'; import makeStyles from '@mui/styles/makeStyles'; import React from 'react'; import { mutate } from 'swr'; import client from 'util/client'; import useLocalStorage from 'util/useLocalStorage'; import { IManga, ISource } from 'typings'; const useStyles = (inLibrary: boolean) => makeStyles((theme: Theme) => ({ root: { width: '100%', [theme.breakpoints.up('md')]: { position: 'sticky', top: '64px', left: '0px', width: '50vw', height: 'calc(100vh - 64px)', alignSelf: 'flex-start', overflowY: 'auto', }, }, top: { padding: '10px', // [theme.breakpoints.up('md')]: { // minWidth: '50%', // }, }, leftRight: { display: 'flex', }, leftSide: { '& img': { borderRadius: 4, maxWidth: '100%', minWidth: '100%', height: 'auto', }, maxWidth: '50%', // [theme.breakpoints.up('md')]: { // minWidth: '100px', // }, }, rightSide: { marginLeft: 15, maxWidth: '100%', '& span': { fontWeight: '400', }, [theme.breakpoints.up('lg')]: { fontSize: '1.3em', }, }, buttons: { display: 'flex', justifyContent: 'space-around', '& button': { color: inLibrary ? '#2196f3' : 'inherit', }, '& a': { textDecoration: 'none', color: '#858585', '& button': { color: 'inherit', }, }, }, bottom: { paddingLeft: '10px', paddingRight: '10px', [theme.breakpoints.up('md')]: { fontSize: '1.2em', // maxWidth: '50%', }, [theme.breakpoints.up('lg')]: { fontSize: '1.3em', }, }, description: { '& h4': { marginTop: '1em', marginBottom: 0, }, '& p': { textAlign: 'justify', textJustify: 'inter-word', }, }, genre: { display: 'flex', flexWrap: 'wrap', '& h5': { border: '2px solid #2196f3', borderRadius: '1.13em', marginRight: '1em', marginTop: 0, marginBottom: '10px', padding: '0.3em', color: '#2196f3', }, }, })); interface IProps { manga: IManga; } function getSourceName(source: ISource) { if (source.displayName !== null) { return source.displayName; } return source.id; } function getValueOrUnknown(val: string) { return val || 'UNKNOWN'; } const MangaDetails: React.FC = ({ manga }) => { const [serverAddress] = useLocalStorage('serverBaseURL', ''); const [useCache] = useLocalStorage('useCache', true); const classes = useStyles(manga.inLibrary)(); const addToLibrary = () => { mutate(`/api/v1/manga/${manga.id}/?onlineFetch=false`, { ...manga, inLibrary: true }, { revalidate: false }); client .get(`/api/v1/manga/${manga.id}/library/`) .then(() => mutate(`/api/v1/manga/${manga.id}/?onlineFetch=false`)); }; const removeFromLibrary = () => { mutate(`/api/v1/manga/${manga.id}/?onlineFetch=false`, { ...manga, inLibrary: false }, { revalidate: false }); client .delete(`/api/v1/manga/${manga.id}/library/`) .then(() => mutate(`/api/v1/manga/${manga.id}/?onlineFetch=false`)); }; return (
Manga Thumbnail

{manga.title}

{'Author: '} {getValueOrUnknown(manga.author)}

{'Artist: '} {getValueOrUnknown(manga.artist)}

{`Status: ${manga.status}`}

{`Source: ${getSourceName(manga.source)}`}

{manga.inLibrary ? : } {manga.inLibrary ? 'In Library' : 'Add To Library'}
Open Site

About

{manga.description}

{manga.genre.map((g) => (
{g}
))}
); }; export default MangaDetails;