mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-08-02 13:48:15 +02:00
clean up 2
This commit is contained in:
parent
f7cfccd391
commit
f821a364cb
@ -22,6 +22,7 @@ import { useEnhancedProcessedFiles } from '../hooks/useEnhancedProcessedFiles';
|
|||||||
import { fileStorage } from '../services/fileStorage';
|
import { fileStorage } from '../services/fileStorage';
|
||||||
import { enhancedPDFProcessingService } from '../services/enhancedPDFProcessingService';
|
import { enhancedPDFProcessingService } from '../services/enhancedPDFProcessingService';
|
||||||
import { thumbnailGenerationService } from '../services/thumbnailGenerationService';
|
import { thumbnailGenerationService } from '../services/thumbnailGenerationService';
|
||||||
|
import { getFileId } from '../utils/fileUtils';
|
||||||
|
|
||||||
// Initial state
|
// Initial state
|
||||||
const initialViewerConfig: ViewerConfig = {
|
const initialViewerConfig: ViewerConfig = {
|
||||||
@ -98,7 +99,7 @@ function fileContextReducer(state: FileContextState, action: FileContextAction):
|
|||||||
|
|
||||||
case 'REMOVE_FILES':
|
case 'REMOVE_FILES':
|
||||||
const remainingFiles = state.activeFiles.filter(file => {
|
const remainingFiles = state.activeFiles.filter(file => {
|
||||||
const fileId = (file as File & { id?: string }).id || file.name;
|
const fileId = getFileId(file);
|
||||||
return !action.payload.includes(fileId);
|
return !action.payload.includes(fileId);
|
||||||
});
|
});
|
||||||
const safeSelectedFileIds = Array.isArray(state.selectedFileIds) ? state.selectedFileIds : [];
|
const safeSelectedFileIds = Array.isArray(state.selectedFileIds) ? state.selectedFileIds : [];
|
||||||
@ -498,7 +499,7 @@ export function FileContextProvider({
|
|||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
try {
|
try {
|
||||||
// Check if file already has an ID (already in IndexedDB)
|
// Check if file already has an ID (already in IndexedDB)
|
||||||
const fileId = (file as File & { id?: string }).id;
|
const fileId = getFileId(file);
|
||||||
if (!fileId) {
|
if (!fileId) {
|
||||||
// File doesn't have ID, store it and get the ID
|
// File doesn't have ID, store it and get the ID
|
||||||
const storedFile = await fileStorage.storeFile(file);
|
const storedFile = await fileStorage.storeFile(file);
|
||||||
@ -680,7 +681,7 @@ export function FileContextProvider({
|
|||||||
// Utility functions
|
// Utility functions
|
||||||
const getFileById = useCallback((fileId: string): File | undefined => {
|
const getFileById = useCallback((fileId: string): File | undefined => {
|
||||||
return state.activeFiles.find(file => {
|
return state.activeFiles.find(file => {
|
||||||
const actualFileId = (file as File & { id?: string }).id || file.name;
|
const actualFileId = getFileId(file);
|
||||||
return actualFileId === fileId;
|
return actualFileId === fileId;
|
||||||
});
|
});
|
||||||
}, [state.activeFiles]);
|
}, [state.activeFiles]);
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import { FileWithUrl } from "../types/file";
|
import { FileWithUrl } from "../types/file";
|
||||||
import { StoredFile, fileStorage } from "../services/fileStorage";
|
import { StoredFile, fileStorage } from "../services/fileStorage";
|
||||||
|
|
||||||
|
export function getFileId(file: File): string {
|
||||||
|
return (file as File & { id?: string }).id || file.name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consolidated file size formatting utility
|
* Consolidated file size formatting utility
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user