Manga Remove button

This commit is contained in:
2025-09-05 16:31:16 +02:00
parent c6e667d429
commit e2926cddbc
5 changed files with 53 additions and 35 deletions

View File

@@ -1,8 +1,8 @@
import Sheet from '@mui/joy/Sheet';
import Header from './Header.tsx';
import Settings from './Components/Settings/Settings.tsx';
import ApiProvider from './contexts/ApiContext.tsx';
import { useEffect, useState } from 'react';
import ApiProvider, { ApiContext } from './contexts/ApiContext.tsx';
import { useContext, useEffect, useState } from 'react';
import { ApiConfig } from './api/http-client.ts';
import MangaProvider from './contexts/MangaContext.tsx';
import MangaList from './Components/Mangas/MangaList.tsx';
@@ -10,8 +10,9 @@ import { Search } from './Search.tsx';
import MangaConnectorProvider from './contexts/MangaConnectorContext.tsx';
import LibraryProvider from './contexts/FileLibraryContext.tsx';
import MangaDetail from './Components/Mangas/Detail/MangaDetail.tsx';
import TButton from './Components/Inputs/TButton.tsx';
export default function App() {
export function App() {
const [apiUri, setApiUri] = useState<string>(
localStorage.getItem('apiUri') ??
window.location.href.substring(0, window.location.href.lastIndexOf('/')) + '/api'
@@ -21,16 +22,30 @@ export default function App() {
setApiConfig({ baseUrl: apiUri });
}, [apiUri]);
const Api = useContext(ApiContext);
const [searchOpen, setSearchOpen] = useState<boolean>(false);
const [downloadDrawerOpen, setDownloadDrawerOpen] = useState(false);
const [selectedMangaKey, setSelectedMangaKey] = useState<string>();
const [downloadSectionOpen, setDownloadSectionOpen] = useState(false);
function openMangaDownloadDrawer(mangaKey: string, downloadSectionOpen?: boolean) {
setDownloadDrawerOpen(true);
setSelectedMangaKey(mangaKey);
setDownloadSectionOpen(downloadSectionOpen ?? false);
}
const removeManga = async (mangaKey?: string): Promise<void> => {
if (!mangaKey) return Promise.reject();
try {
let r = await Api.mangaDelete(mangaKey);
if (r.ok) return Promise.resolve();
else return Promise.reject();
} catch (reason) {
return await Promise.reject(reason);
}
};
return (
<ApiProvider apiConfig={apiConfig}>
<MangaConnectorProvider>
@@ -54,8 +69,11 @@ export default function App() {
open={downloadDrawerOpen}
setOpen={setDownloadDrawerOpen}
mangaKey={selectedMangaKey}
downloadOpen={downloadSectionOpen}
/>
downloadOpen={downloadSectionOpen}>
<TButton completionAction={() => removeManga(selectedMangaKey)}>
Remove
</TButton>
</MangaDetail>
</Sheet>
</Sheet>
</MangaProvider>

View File

@@ -5,16 +5,17 @@ import {
Box,
Checkbox,
List,
ListItem, Option,
ListItem,
Option,
Select,
Stack,
Typography
} from "@mui/joy";
import {ReactNode, useContext} from "react";
import TButton from "../../Inputs/TButton.tsx";
import MangaConnectorIcon from "../MangaConnectorIcon.tsx";
import {FileLibrary, Manga, MangaConnectorId} from "../../../api/data-contracts.ts";
import {FileLibraryContext} from "../../../contexts/FileLibraryContext.tsx";
Typography,
} from '@mui/joy';
import { ReactNode, useContext } from 'react';
import TButton from '../../Inputs/TButton.tsx';
import MangaConnectorIcon from '../MangaConnectorIcon.tsx';
import { FileLibrary, Manga, MangaConnectorId } from '../../../api/data-contracts.ts';
import { FileLibraryContext } from '../../../contexts/FileLibraryContext.tsx';
export default function DownloadSection(props: DownloadSectionProps): ReactNode {
const Libraries = useContext(FileLibraryContext);
@@ -64,13 +65,9 @@ export default function DownloadSection (props: DownloadSectionProps) : ReactNod
gap: 5,
}}>
<MangaConnectorIcon
mangaConnectorName={
id.mangaConnectorName
}
mangaConnectorName={id.mangaConnectorName}
/>
<Typography>
{id.mangaConnectorName}
</Typography>
<Typography>{id.mangaConnectorName}</Typography>
</div>
}
/>

View File

@@ -1,21 +1,12 @@
import { Dispatch, ReactNode, useContext, useEffect, useState } from 'react';
import {
Card,
CardCover,
Chip,
Modal,
ModalDialog,
Stack,
Typography,
useTheme,
} from '@mui/joy';
import { Card, CardCover, Chip, Modal, ModalDialog, Stack, Typography, useTheme } from '@mui/joy';
import ModalClose from '@mui/joy/ModalClose';
import { FileLibrary, Manga, MangaConnectorId } from '../../../api/data-contracts.ts';
import { ApiContext } from '../../../contexts/ApiContext.tsx';
import { MangaContext } from '../../../contexts/MangaContext.tsx';
import { FileLibraryContext } from '../../../contexts/FileLibraryContext.tsx';
import MarkdownPreview from '@uiw/react-markdown-preview';
import DownloadSection from "./DownloadSection.tsx";
import DownloadSection from './DownloadSection.tsx';
export default function MangaDetail(props: MangaDetailProps): ReactNode {
const Api = useContext(ApiContext);
@@ -139,9 +130,20 @@ export default function MangaDetail(props: MangaDetailProps): ReactNode {
overflowY: 'auto',
}}
/>
<Stack
direction={'row-reverse'}
gap={1}>
{props.children}
</Stack>
</Stack>
<DownloadSection downloadOpen={props.downloadOpen??false} library={library} onLibraryChange={onLibraryChange} downloadFromMap={downloadFromMap} setDownload={setDownload} />
</Stack>
<DownloadSection
downloadOpen={props.downloadOpen ?? false}
library={library}
onLibraryChange={onLibraryChange}
downloadFromMap={downloadFromMap}
setDownload={setDownload}
/>
</ModalDialog>
</Modal>
);
@@ -153,4 +155,5 @@ export interface MangaDetailProps {
open: boolean;
setOpen: Dispatch<boolean>;
downloadOpen?: boolean;
children?: ReactNode;
}

View File

@@ -1,6 +1,6 @@
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App.tsx';
import { App } from './App.tsx';
// @ts-expect-error font
import '@fontsource/inter';
import { CssVarsProvider } from '@mui/joy/styles';