FileLibrary selection in download dialog

This commit is contained in:
2025-09-04 23:02:53 +02:00
parent 19920fb507
commit 9aca50aa15
2 changed files with 38 additions and 10 deletions

View File

@@ -12,7 +12,7 @@ import {
Typography, Typography,
} from '@mui/joy' } from '@mui/joy'
import ModalClose from '@mui/joy/ModalClose' import ModalClose from '@mui/joy/ModalClose'
import { Manga, MangaConnectorId } from './api/data-contracts.ts' import { FileLibrary, Manga, MangaConnectorId } from './api/data-contracts.ts'
import { ApiContext } from './contexts/ApiContext.tsx' import { ApiContext } from './contexts/ApiContext.tsx'
import { MangaContext } from './contexts/MangaContext.tsx' import { MangaContext } from './contexts/MangaContext.tsx'
import { FileLibraryContext } from './contexts/FileLibraryContext.tsx' import { FileLibraryContext } from './contexts/FileLibraryContext.tsx'
@@ -27,6 +27,7 @@ export default function MangaDownloadDrawer(
const Libraries = useContext(FileLibraryContext) const Libraries = useContext(FileLibraryContext)
const [manga, setManga] = useState<Manga | undefined>(props.manga) const [manga, setManga] = useState<Manga | undefined>(props.manga)
const [library, setLibrary] = useState<FileLibrary | undefined>()
const [downloadFromMap, setDownloadFromMap] = useState< const [downloadFromMap, setDownloadFromMap] = useState<
Map<MangaConnectorId, boolean> Map<MangaConnectorId, boolean>
>(new Map()) >(new Map())
@@ -40,25 +41,43 @@ export default function MangaDownloadDrawer(
useEffect(() => { useEffect(() => {
const newMap = new Map() const newMap = new Map()
setLibrary(
Libraries.find((library) => library.key == manga?.fileLibraryId)
)
manga?.mangaConnectorIds.forEach((id) => { manga?.mangaConnectorIds.forEach((id) => {
newMap.set(id, id.useForDownload) newMap.set(id, id.useForDownload)
}) })
setDownloadFromMap(newMap) setDownloadFromMap(newMap)
}, [manga]) }, [manga])
const setDownload = (): Promise<void> => { const setDownload = async (): Promise<void> => {
if (!manga) return Promise.reject() if (!manga) return Promise.reject()
downloadFromMap.forEach(async (download, id) => { if (library) {
const result = await Api.mangaSetAsDownloadFromCreate( const s = await Api.mangaChangeLibraryCreate(
manga?.key, manga.key,
id.mangaConnectorName, library?.key
download
) )
if (!result.ok) return Promise.reject() .then((result) => result.ok)
}) .catch(() => false)
if (!s) return Promise.reject()
}
for (const kv of downloadFromMap) {
const s = await Api.mangaSetAsDownloadFromCreate(
manga?.key,
kv[0].mangaConnectorName,
kv[1]
)
.then((result) => result.ok)
.catch(() => false)
if (!s) return Promise.reject()
}
return Promise.resolve() return Promise.resolve()
} }
const onLibraryChange = (_: any, value: string | null) => {
setLibrary(Libraries.find((library) => library.key == value))
}
return ( return (
<Drawer <Drawer
open={props.open} open={props.open}
@@ -75,7 +94,11 @@ export default function MangaDownloadDrawer(
<Typography> <Typography>
Select a Library to Download to: Select a Library to Download to:
</Typography> </Typography>
<Select placeholder={'Select a Library'}> <Select
placeholder={'Select a Library'}
value={library?.key}
onChange={onLibraryChange}
>
{Libraries.map((l) => ( {Libraries.map((l) => (
<Option key={l.key} value={l.key}> <Option key={l.key} value={l.key}>
{l.libraryName} ({l.basePath}) {l.libraryName} ({l.basePath})

View File

@@ -194,6 +194,11 @@ export interface Manga {
links: Link[] links: Link[]
/** Alt Titles of Manga */ /** Alt Titles of Manga */
altTitles: AltTitle[] altTitles: AltTitle[]
/**
* Id of the Library the Manga gets downloaded to
* @minLength 1
*/
fileLibraryId: string
/** /**
* Name of the Manga * Name of the Manga
* @minLength 1 * @minLength 1