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