Files
ReadMeABook/src/lib/hooks/useGoodreadsShelves.ts
T
kikootwo 98c89db0a7 Add per-shelf autoRequest toggle
Introduce an autoRequest boolean on Goodreads and Hardcover shelves (default true) so users can pause/resume automatic request creation. Schema, API handlers, hooks and types were updated to accept and persist autoRequest when creating or updating shelves; add endpoints only trigger an immediate resync when the feed/token changes. The shelf sync core and service code now respect autoRequest (skipping request creation and annotating logs when disabled). UI updates include an AddShelf toggle, manage/update payload changes, shelf list props, and visual indicators + toggle actions in the shelf cards.
2026-03-11 09:55:00 -04:00

49 lines
1.2 KiB
TypeScript

/**
* Component: Goodreads Shelves Hook
* Documentation: documentation/frontend/components.md
*/
'use client';
import { createShelfHooks, ShelfBook } from './createShelfHooks';
export type { ShelfBook };
export interface GoodreadsShelf {
id: string;
name: string;
rssUrl: string;
lastSyncAt: string | null;
createdAt: string;
bookCount: number | null;
autoRequest: boolean;
books: ShelfBook[];
}
const { useList, useAdd, useDelete, useUpdate } =
createShelfHooks<GoodreadsShelf>('/api/user/goodreads-shelves');
export const useGoodreadsShelves = useList;
export function useAddGoodreadsShelf() {
const { addShelf: addGeneric, isLoading, error } = useAdd();
const addShelf = async (rssUrl: string, autoRequest: boolean = true) => {
return addGeneric({ rssUrl, autoRequest });
};
return { addShelf, isLoading, error };
}
export const useDeleteGoodreadsShelf = useDelete;
export function useUpdateGoodreadsShelf() {
const { updateShelf: updateGeneric, isLoading, error } = useUpdate();
const updateShelf = async (shelfId: string, updates: { rssUrl?: string; autoRequest?: boolean }) => {
return updateGeneric(shelfId, updates);
};
return { updateShelf, isLoading, error };
}