fix: cleanup

This commit is contained in:
2026-06-04 06:42:27 -05:00
parent f989b144cf
commit 654cfec147
52 changed files with 290 additions and 540 deletions
-4
View File
@@ -1,4 +0,0 @@
export { usePaginatedQuery } from "./usePaginatedQuery";
export { useDebounce } from "./useDebounce";
export { useVoiceSearch } from "./useVoiceSearch";
export { useMediaQuery } from "./useMediaQuery";
+3 -6
View File
@@ -3,8 +3,8 @@
*/
import { useCallback, useEffect, useRef, useState } from "react";
import { booksApi } from "../api/books";
import { getReadingProgress, updateReadingProgress } from "../api/reader";
import { loadEbookWithProgress } from "../api/loadEbookWithProgress";
import { updateReadingProgress } from "../api/reader";
import type { ReadingProgress, ReadingSettings } from "../types/reader";
import {
applyRenditionSettings,
@@ -197,10 +197,7 @@ export function useEpubReader(
setIsLoading(true);
setError(null);
try {
const [progressData, blob] = await Promise.all([
getReadingProgress(bookId).catch(() => null),
booksApi.getEbookFile(bookId),
]);
const { progressData, blob } = await loadEbookWithProgress(bookId);
if (cancelled) return;
blobUrl = URL.createObjectURL(blob);
-69
View File
@@ -1,69 +0,0 @@
import { useState, useCallback, useRef, useEffect } from "react";
import type { PaginatedResponse } from "@/types";
interface UsePaginatedQueryOptions<T> {
fetchFn: (cursor?: string) => Promise<PaginatedResponse<T>>;
}
interface UsePaginatedQueryResult<T> {
items: T[];
loading: boolean;
error: string | null;
hasMore: boolean;
loadMore: () => Promise<void>;
refresh: () => Promise<void>;
}
/**
* Hook for paginated list fetching with infinite scroll support.
*/
export function usePaginatedQuery<T>({
fetchFn,
}: UsePaginatedQueryOptions<T>): UsePaginatedQueryResult<T> {
const [items, setItems] = useState<T[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [nextCursor, setNextCursor] = useState<string | null>(null);
const loadingRef = useRef(false);
const refresh = useCallback(async () => {
setLoading(true);
setError(null);
try {
const response = await fetchFn();
setItems(response.results);
setNextCursor(response.next);
} catch (err) {
setError(err instanceof Error ? err.message : "Failed to fetch data");
} finally {
setLoading(false);
}
}, [fetchFn]);
const loadMore = useCallback(async () => {
if (!nextCursor || loadingRef.current) return;
loadingRef.current = true;
try {
const response = await fetchFn(nextCursor);
setItems((prev) => [...prev, ...response.results]);
setNextCursor(response.next);
} catch (err) {
setError(err instanceof Error ? err.message : "Failed to load more");
} finally {
loadingRef.current = false;
}
}, [nextCursor, fetchFn]);
useEffect(() => {
refresh();
}, [refresh]);
return {
items,
loading,
error,
hasMore: nextCursor !== null,
loadMore,
refresh,
};
}
+3 -6
View File
@@ -3,8 +3,8 @@
*/
import { useCallback, useEffect, useRef, useState } from "react";
import { booksApi } from "../api/books";
import { getReadingProgress, updateReadingProgress } from "../api/reader";
import { loadEbookWithProgress } from "../api/loadEbookWithProgress";
import { updateReadingProgress } from "../api/reader";
import type { ReadingProgress } from "../types/reader";
import { parsePdfAnchor } from "../utils/pdfAnchor";
import { pdfjs, type PdfDocumentProxy } from "../utils/pdfjsSetup";
@@ -175,10 +175,7 @@ export function usePdfReader(
setIsLoading(true);
setError(null);
try {
const [progressData, blob] = await Promise.all([
getReadingProgress(bookId).catch(() => null),
booksApi.getEbookFile(bookId),
]);
const { progressData, blob } = await loadEbookWithProgress(bookId);
if (cancelled) return;
const loadingTask = pdfjs.getDocument({ data: await blob.arrayBuffer() });
@@ -0,0 +1,16 @@
import { useEffect } from "react";
import type { ReadingSettings } from "@/types/reader";
export function useReaderOrientationCss(orientationLock: ReadingSettings["orientation_lock"]): void {
useEffect(() => {
const root = document.documentElement;
if (orientationLock !== "auto") {
root.style.setProperty(
"--reader-orientation",
orientationLock === "portrait" ? "portrait" : "landscape",
);
} else {
root.style.removeProperty("--reader-orientation");
}
}, [orientationLock]);
}
+1 -1
View File
@@ -36,7 +36,7 @@ const DEFAULT_SETTINGS: ReadingSettings = {
const SAVE_DEBOUNCE_MS = 600;
export function applyReadingCssVariables(settings: ReadingSettings): void {
function applyReadingCssVariables(settings: ReadingSettings): void {
const root = document.documentElement;
root.style.setProperty("--reader-bg", settings.background_color);
root.style.setProperty("--reader-text", settings.text_color);