Skip to content

Commit

Permalink
add some options for add/remove from library
Browse files Browse the repository at this point in the history
  • Loading branch information
Robonau authored and Robonau committed Jul 3, 2024
1 parent f223d5b commit c7fc4fd
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 12 deletions.
Binary file modified bun.lockb
Binary file not shown.
5 changes: 4 additions & 1 deletion src/lib/simpleStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ const trueDefaults = {
password: '',
Authorization: ''
},
libraryCategoryTotalCounts: false
libraryCategoryTotalCounts: false,
DownloadAllChaptersOnAddToLibrary: false,
DeleteAllChaptersOnRemoveFromLibrary: false,
RemoveChaptersFromDownloadQueueOnRemoveFromLibrary: false
};

type globalMeta = typeof trueDefaults;
Expand Down
47 changes: 42 additions & 5 deletions src/routes/(app)/manga/[MangaID]/(manga)/InfoSide.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
type Pausable
} from '@urql/svelte';
import { type ResultOf } from '$lib/gql/graphql';
import { updateMangas } from '$lib/gql/Mutations';
import type { MangaMeta } from '$lib/simpleStores';
import {
deleteDownloadedChapters,
dequeueChapterDownloads,
enqueueChapterDownloads,
updateMangas
} from '$lib/gql/Mutations';
import { type MangaMeta, Meta } from '$lib/simpleStores';
import NotesModal from './NotesModal.svelte';
import { getToastStore } from '$lib/components/Toast/stores';
import { longPress } from '$lib/press';
Expand All @@ -35,8 +40,40 @@
export let MangaID: number;
export let mangaMeta: ReturnType<typeof MangaMeta>;
async function libtoggle() {
await client
function libToggle() {
if (
$Meta.DownloadAllChaptersOnAddToLibrary &&
!$manga.data?.manga?.inLibrary
) {
client
.mutation(enqueueChapterDownloads, {
ids: $manga.data?.manga?.chapters.nodes?.map((e) => e.id) ?? []
})
.toPromise();
}
if (
$manga.data?.manga?.inLibrary &&
$Meta.DeleteAllChaptersOnRemoveFromLibrary
) {
client
.mutation(deleteDownloadedChapters, {
ids: $manga.data?.manga?.chapters.nodes?.map((e) => e.id) ?? []
})
.toPromise();
}
if (
$manga.data?.manga?.inLibrary &&
$Meta.RemoveChaptersFromDownloadQueueOnRemoveFromLibrary
) {
client
.mutation(dequeueChapterDownloads, {
ids: $manga.data?.manga?.chapters.nodes?.map((e) => e.id) ?? []
})
.toPromise();
}
client
.mutation(updateMangas, {
ids: [MangaID],
inLibrary: !$manga.data?.manga?.inLibrary
Expand Down Expand Up @@ -183,7 +220,7 @@
<MediaQuery query="(min-width: {screens.sm})" let:matches>
<div class="grid grid-cols-2 gap-1">
<button
on:click={libtoggle}
on:click={libToggle}
class="variant-soft btn flex h-12 items-center px-2 sm:px-5"
>
<IconWrapper
Expand Down
22 changes: 16 additions & 6 deletions src/routes/(app)/manga/[MangaID]/(manga)/chaptersSide.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
type OperationResultStore,
type Pausable
} from '@urql/svelte';
import { getSingleChapter, type getManga } from '$lib/gql/Queries';
import { getSingleChapter, getManga } from '$lib/gql/Queries';
import { type ResultOf } from '$lib/gql/graphql';
import { downloadsOnChapters } from '$lib/gql/Subscriptions';
import {
Expand Down Expand Up @@ -61,14 +61,23 @@
}
function checkinNeedRefresh() {
lastDownloads?.downloadChanged.queue
.filter((e) =>
$manga?.data?.manga.chapters.nodes.find((ee) => ee.id === e.chapter.id)
)
.forEach((element) => {
let filtered = lastDownloads?.downloadChanged.queue.filter(
(e) =>
!$downloads?.data?.downloadChanged.queue.find(
(ee) => ee.chapter.id === e.chapter.id
)
);
console.log(filtered);
if ((filtered?.length ?? 0) > 2) {
client
.query(getManga, { id: MangaID }, { requestPolicy: 'network-only' })
.toPromise();
} else {
filtered?.forEach((element) => {
const existingDownload = $downloads?.data?.downloadChanged.queue.find(
(e) => e.chapter.id === element.chapter.id
);
console.log(element.chapter, existingDownload);
if (!existingDownload) {
client
.query(
Expand All @@ -79,6 +88,7 @@
.toPromise();
}
});
}
}
$: chaptersInfo = $manga?.data?.manga?.chapters.nodes;
Expand Down
19 changes: 19 additions & 0 deletions src/routes/(app)/settings/MangaSettingsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,30 @@
import { enumKeys } from '$lib/util';
import TriStateSlide from '$lib/components/TriStateSlide.svelte';
import ModalTemplate from '$lib/components/ModalTemplate.svelte';
import Slide from '$lib/components/Slide.svelte';
const modalStore = getModalStore();
</script>

{#if $modalStore[0]}
<ModalTemplate title="Manga Settings Defaults">
<Slide
bind:checked={$Meta.DownloadAllChaptersOnAddToLibrary}
class="my-1 p-1 pl-2 hover:variant-glass-surface focus:outline-0"
>
Download all chapters when add manga to library
</Slide>
<Slide
bind:checked={$Meta.DeleteAllChaptersOnRemoveFromLibrary}
class="my-1 p-1 pl-2 hover:variant-glass-surface focus:outline-0"
>
Delete all chapters when remove manga from library
</Slide>
<Slide
bind:checked={$Meta.RemoveChaptersFromDownloadQueueOnRemoveFromLibrary}
class="my-1 p-1 pl-2 hover:variant-glass-surface focus:outline-0"
>
Remove chapters from download queue when remove manga from library
</Slide>
<h2 class="h4 mb-1 border-b border-surface-700">Filters</h2>
<TriStateSlide
bind:state={$Meta.mangaMetaDefaults.ChapterUnread}
Expand Down

0 comments on commit c7fc4fd

Please sign in to comment.