PDF document hook refactor
This commit is contained in:
parent
737ab5f919
commit
f800c12fb7
3 changed files with 6 additions and 8 deletions
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
import { useState, useCallback } from 'react';
|
import { useState, useCallback } from 'react';
|
||||||
import { useDropzone } from 'react-dropzone';
|
import { useDropzone } from 'react-dropzone';
|
||||||
import { usePDF } from '@/contexts/PDFContext';
|
|
||||||
import { UploadIcon } from '@/components/icons/Icons';
|
import { UploadIcon } from '@/components/icons/Icons';
|
||||||
|
import { usePDFDocuments } from '@/hooks/pdf/usePDFDocuments';
|
||||||
|
|
||||||
interface PDFUploaderProps {
|
interface PDFUploaderProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PDFUploader({ className = '' }: PDFUploaderProps) {
|
export function PDFUploader({ className = '' }: PDFUploaderProps) {
|
||||||
const { addDocument } = usePDF();
|
const { addDocument } = usePDFDocuments();
|
||||||
const [isUploading, setIsUploading] = useState(false);
|
const [isUploading, setIsUploading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ import { usePDFURLConversion } from '@/hooks/pdf/usePDFURLConversion';
|
||||||
interface PDFContextType {
|
interface PDFContextType {
|
||||||
// Documents management
|
// Documents management
|
||||||
documents: PDFDocument[];
|
documents: PDFDocument[];
|
||||||
addDocument: (file: File) => Promise<string>;
|
|
||||||
removeDocument: (id: string) => Promise<void>;
|
removeDocument: (id: string) => Promise<void>;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
|
||||||
|
|
@ -74,7 +73,6 @@ const PDFContext = createContext<PDFContextType | undefined>(undefined);
|
||||||
* Handles document loading, text processing, and integration with TTS.
|
* Handles document loading, text processing, and integration with TTS.
|
||||||
*/
|
*/
|
||||||
export function PDFProvider({ children }: { children: ReactNode }) {
|
export function PDFProvider({ children }: { children: ReactNode }) {
|
||||||
const { isDBReady } = useConfig();
|
|
||||||
const {
|
const {
|
||||||
setText: setTTSText,
|
setText: setTTSText,
|
||||||
currDocPage,
|
currDocPage,
|
||||||
|
|
@ -83,7 +81,7 @@ export function PDFProvider({ children }: { children: ReactNode }) {
|
||||||
} = useTTS();
|
} = useTTS();
|
||||||
|
|
||||||
// Initialize hooks
|
// Initialize hooks
|
||||||
const { documents, isLoading, addDocument, removeDocument } = usePDFDocuments(isDBReady);
|
const { documents, isLoading, removeDocument } = usePDFDocuments();
|
||||||
const { extractTextFromPDF } = usePDFTextProcessing();
|
const { extractTextFromPDF } = usePDFTextProcessing();
|
||||||
const { highlightPattern, clearHighlights } = usePDFHighlighting();
|
const { highlightPattern, clearHighlights } = usePDFHighlighting();
|
||||||
const { handleTextClick } = usePDFTextClick();
|
const { handleTextClick } = usePDFTextClick();
|
||||||
|
|
@ -160,7 +158,6 @@ export function PDFProvider({ children }: { children: ReactNode }) {
|
||||||
const contextValue = useMemo(
|
const contextValue = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
documents,
|
documents,
|
||||||
addDocument,
|
|
||||||
removeDocument,
|
removeDocument,
|
||||||
isLoading,
|
isLoading,
|
||||||
onDocumentLoadSuccess,
|
onDocumentLoadSuccess,
|
||||||
|
|
@ -177,7 +174,6 @@ export function PDFProvider({ children }: { children: ReactNode }) {
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
documents,
|
documents,
|
||||||
addDocument,
|
|
||||||
removeDocument,
|
removeDocument,
|
||||||
isLoading,
|
isLoading,
|
||||||
onDocumentLoadSuccess,
|
onDocumentLoadSuccess,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import { useState, useCallback, useEffect } from 'react';
|
import { useState, useCallback, useEffect } from 'react';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { indexedDBService, type PDFDocument } from '@/services/indexedDB';
|
import { indexedDBService, type PDFDocument } from '@/services/indexedDB';
|
||||||
|
import { useConfig } from '@/contexts/ConfigContext';
|
||||||
|
|
||||||
export function usePDFDocuments(isDBReady: boolean) {
|
export function usePDFDocuments() {
|
||||||
|
const { isDBReady } = useConfig();
|
||||||
const [documents, setDocuments] = useState<PDFDocument[]>([]);
|
const [documents, setDocuments] = useState<PDFDocument[]>([]);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue