Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hooks/useLibraryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export function useLibraryData(initialFilters?: Partial<LibraryFilters>) {
const service = useMemo(() => libraryService, []);

// Create a stable query key based on filter values (excluding pagination.skip)
// Use queryKeys.library.books() as base to ensure consistency with refresh/invalidation
const queryKey = useMemo(() => [
'library-books',
...queryKeys.library.books(),
filters.status,
filters.search,
filters.tags,
Expand Down
6 changes: 6 additions & 0 deletions hooks/usePullToRefreshLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export function usePullToRefreshLogic() {

if (queryKey) {
await queryClient.invalidateQueries({ queryKey });
} else if (pathname === "/journal") {
// Special case: Invalidate both journal entries and archive using prefix matching
await Promise.all([
queryClient.invalidateQueries({ queryKey: queryKeys.journal.entriesBase() }),
queryClient.invalidateQueries({ queryKey: queryKeys.journal.archiveBase() }),
]);
Comment thread
masonfox marked this conversation as resolved.
} else {
// Fallback: invalidate all queries if we don't have specific keys
await queryClient.invalidateQueries();
Expand Down
16 changes: 8 additions & 8 deletions hooks/useShelfBooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function useShelfBooks(
? queryKeys.shelf.detail(shelfId, { orderBy, direction })
: ['shelf-empty'],
queryFn: async () => {
if (!shelfId) return null;
if (shelfId === null) return null;

const shelf = await shelfApi.get(shelfId, {
withBooks: true,
Expand All @@ -53,7 +53,7 @@ export function useShelfBooks(
*/
const addBooksMutation = useMutation({
mutationFn: async (bookIds: number[]) => {
if (!shelfId || bookIds.length === 0) {
if (shelfId === null || bookIds.length === 0) {
throw new Error("No shelf ID or book IDs provided");
}
return shelfApi.addBooks(shelfId, { bookIds });
Expand All @@ -73,7 +73,7 @@ export function useShelfBooks(
*/
const removeBookMutation = useMutation({
mutationFn: async (bookId: number) => {
if (!shelfId) {
if (shelfId === null) {
throw new Error("No shelf ID provided");
}
return shelfApi.removeBook(shelfId, bookId);
Expand Down Expand Up @@ -127,7 +127,7 @@ export function useShelfBooks(
*/
const removeBooksMutation = useMutation({
mutationFn: async (bookIds: number[]) => {
if (!shelfId || bookIds.length === 0) {
if (shelfId === null || bookIds.length === 0) {
throw new Error("No shelf ID or book IDs provided");
}
return shelfApi.removeBooks(shelfId, { bookIds });
Expand Down Expand Up @@ -182,7 +182,7 @@ export function useShelfBooks(
*/
const reorderBooksMutation = useMutation({
mutationFn: async (bookIds: number[]) => {
if (!shelfId) {
if (shelfId === null) {
throw new Error("No shelf ID provided");
}
return shelfApi.reorderBooks(shelfId, { bookIds });
Expand Down Expand Up @@ -245,7 +245,7 @@ export function useShelfBooks(
bookIds: number[];
targetShelfName?: string;
}) => {
if (!shelfId || bookIds.length === 0) {
if (shelfId === null || bookIds.length === 0) {
throw new Error("No shelf ID or book IDs provided");
}
return shelfApi.moveBooks(shelfId, targetShelfId, { bookIds });
Expand Down Expand Up @@ -329,7 +329,7 @@ export function useShelfBooks(
*/
const moveToTopMutation = useMutation({
mutationFn: async (bookId: number) => {
if (!shelfId) {
if (shelfId === null) {
throw new Error("No shelf ID provided");
}

Expand Down Expand Up @@ -399,7 +399,7 @@ export function useShelfBooks(

const moveToBottomMutation = useMutation({
mutationFn: async (bookId: number) => {
if (!shelfId) {
if (shelfId === null) {
throw new Error("No shelf ID provided");
}

Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/usePageTitle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLayoutEffect, useRef, useEffect } from "react";
import { useLayoutEffect, useEffect } from "react";

/**
* Custom hook to set the page title
Expand Down
6 changes: 6 additions & 0 deletions lib/query-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ export const queryKeys = {
// JOURNAL
// ============================================================================
journal: {
/** Base key for journal entries (prefix matching): ['journal-entries'] */
entriesBase: () => ['journal-entries'] as const,

/** Base key for journal archive (prefix matching): ['journal-archive'] */
archiveBase: () => ['journal-archive'] as const,

Comment on lines 199 to +205
/** Journal entries for timezone: ['journal-entries', timezone] */
entries: (timezone: string) => ['journal-entries', timezone] as const,

Expand Down
Loading