feature/FA-misc_ServersidedChapterReader #61
@@ -33,10 +33,10 @@
|
||||
let error: string | null = $state(null);
|
||||
|
||||
// Track which lists the novel is in (by list ID)
|
||||
let novelInLists = $state(new SvelteSet<number>());
|
||||
let novelInLists = new SvelteSet<number>();
|
||||
|
||||
// Track loading state for individual list toggles
|
||||
let loadingListIds = $state(new SvelteSet<number>());
|
||||
let loadingListIds = new SvelteSet<number>();
|
||||
|
||||
// Quick-create state
|
||||
let showQuickCreate = $state(false);
|
||||
@@ -75,13 +75,12 @@
|
||||
if (result.data) {
|
||||
readingLists = result.data.readingLists;
|
||||
// Build the set of list IDs that contain this novel
|
||||
const inLists = new SvelteSet<number>();
|
||||
novelInLists.clear();
|
||||
for (const list of readingLists) {
|
||||
if (list.items.some((item) => item.novelId === novelId)) {
|
||||
inLists.add(list.id);
|
||||
novelInLists.add(list.id);
|
||||
}
|
||||
}
|
||||
novelInLists = inLists;
|
||||
}
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'Failed to load reading lists';
|
||||
@@ -92,7 +91,7 @@
|
||||
|
||||
async function toggleNovelInList(listId: number) {
|
||||
const isInList = novelInLists.has(listId);
|
||||
loadingListIds = new SvelteSet([...loadingListIds, listId]);
|
||||
loadingListIds.add(listId);
|
||||
|
||||
try {
|
||||
if (isInList) {
|
||||
@@ -115,7 +114,7 @@
|
||||
|
||||
if (result.data?.removeFromReadingList?.readingListPayload?.success) {
|
||||
// Update local state
|
||||
novelInLists = new SvelteSet([...novelInLists].filter((id) => id !== listId));
|
||||
novelInLists.delete(listId);
|
||||
// Update item count in list
|
||||
readingLists = readingLists.map((list) =>
|
||||
list.id === listId
|
||||
@@ -143,7 +142,7 @@
|
||||
|
||||
if (result.data?.addToReadingList?.readingListPayload?.success) {
|
||||
// Update local state
|
||||
novelInLists = new SvelteSet([...novelInLists, listId]);
|
||||
novelInLists.add(listId);
|
||||
// Update item count in list
|
||||
readingLists = readingLists.map((list) =>
|
||||
list.id === listId
|
||||
@@ -159,7 +158,7 @@
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'An error occurred';
|
||||
} finally {
|
||||
loadingListIds = new SvelteSet([...loadingListIds].filter((id) => id !== listId));
|
||||
loadingListIds.delete(listId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +217,7 @@
|
||||
items: [{ novelId, order: 0, addedTime: new Date().toISOString() }]
|
||||
};
|
||||
readingLists = [...readingLists, fullNewList];
|
||||
novelInLists = new SvelteSet([...novelInLists, newList.id]);
|
||||
novelInLists.add(newList.id);
|
||||
|
||||
// Reset quick-create form
|
||||
showQuickCreate = false;
|
||||
|
||||
@@ -35,7 +35,7 @@ if (token) {
|
||||
} else {
|
||||
const result = await response.json();
|
||||
|
||||
if (result.errors?.some((e: any) => e.extensions?.code === 'AUTH_NOT_AUTHENTICATED')) {
|
||||
if (result.errors?.some((e: { extensions?: { code?: string } }) => e.extensions?.code === 'AUTH_NOT_AUTHENTICATED')) {
|
||||
authFailed = true;
|
||||
} else if (result.data?.chapter) {
|
||||
chapter = result.data.chapter;
|
||||
|
||||
Reference in New Issue
Block a user