-
) : leftPanelView === 'toolPicker' ? (
// Tool Picker View
-
+
+
{/* Close Button - Only show in preview mode */}
{onClose && previewFile && (
{
+ const currentSelection = stateRef.current.ui.selectedFileIds;
+ const newFileIds = addedFilesWithIds.map(({ id }) => id);
+ dispatch({ type: 'SET_SELECTED_FILES', payload: { fileIds: [...currentSelection, ...newFileIds] } });
+ }
+
// File operations using unified addFiles helper with persistence
- const addRawFiles = useCallback(async (files: File[], options?: { insertAfterPageId?: string }): Promise => {
+ const addRawFiles = useCallback(async (files: File[], options?: { insertAfterPageId?: string; selectFiles?: boolean }): Promise => {
const addedFilesWithIds = await addFiles('raw', { files, ...options }, stateRef, filesRef, dispatch, lifecycleManager);
+
+ // Auto-select the newly added files if requested
+ if (options?.selectFiles && addedFilesWithIds.length > 0) {
+ selectFiles(addedFilesWithIds);
+ }
+
// Persist to IndexedDB if enabled
if (indexedDB && enablePersistence && addedFilesWithIds.length > 0) {
await Promise.all(addedFilesWithIds.map(async ({ file, id, thumbnail }) => {
@@ -94,8 +106,14 @@ function FileContextInner({
return result.map(({ file }) => file);
}, []);
- const addStoredFiles = useCallback(async (filesWithMetadata: Array<{ file: File; originalId: FileId; metadata: any }>): Promise => {
+ const addStoredFiles = useCallback(async (filesWithMetadata: Array<{ file: File; originalId: FileId; metadata: any }>, options?: { selectFiles?: boolean }): Promise => {
const result = await addFiles('stored', { filesWithMetadata }, stateRef, filesRef, dispatch, lifecycleManager);
+
+ // Auto-select the newly added files if requested
+ if (options?.selectFiles && result.length > 0) {
+ selectFiles(result);
+ }
+
return result.map(({ file }) => file);
}, []);
diff --git a/frontend/src/contexts/file/fileActions.ts b/frontend/src/contexts/file/fileActions.ts
index d0c565783..8d91f8855 100644
--- a/frontend/src/contexts/file/fileActions.ts
+++ b/frontend/src/contexts/file/fileActions.ts
@@ -88,6 +88,12 @@ interface AddFileOptions {
insertAfterPageId?: string;
}
+export interface AddedFile {
+ file: File;
+ id: FileId;
+ thumbnail?: string;
+}
+
/**
* Unified file addition helper - replaces addFiles/addProcessedFiles/addStoredFiles
*/
@@ -98,13 +104,13 @@ export async function addFiles(
filesRef: React.MutableRefObject