Skip to content

Commit 7301691

Browse files
authored
Update UploadFlow.tsx
1 parent c7ed758 commit 7301691

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/components/dashboard/UploadFlow.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525
} from "@/lib/firebase/firestore";
2626

2727
import { FolderPlus } from "lucide-react";
28-
import { uploadFile } from "@/lib/supabase/storage";
28+
import { uploadFile as uploadToSupabase } from "@/lib/supabase/storage";
29+
import { uploadFile as uploadToFirebase } from "@/lib/firebase/storage";
2930
import { useAuth } from "@/lib/firebase/auth";
3031
import { useToast } from "@/context/ToastContext";
3132
import { CONFIG, isAllowedFileType, sanitizeInput } from "@/lib/config";
@@ -291,7 +292,15 @@ export default function UploadFlow() {
291292
const safeName = file.name.replace(/\s+/g, "_");
292293
const path = `uploads/${user.uid}/${Date.now()}_${uniqueId}_${safeName}`;
293294

294-
const url = await uploadFile(file, path);
295+
let url: string;
296+
try {
297+
// Try Supabase first
298+
url = await uploadToSupabase(file, path);
299+
} catch (supabaseError: any) {
300+
console.warn(`Supabase upload failed for ${file.name}, falling back to Firebase:`, supabaseError.message);
301+
// Fallback to Firebase Storage
302+
url = await uploadToFirebase(file, path);
303+
}
295304

296305
await createNote({
297306
departmentId: selectedDept,
@@ -308,7 +317,10 @@ export default function UploadFlow() {
308317
newProgress[file.name] = "success";
309318
} catch (error) {
310319
console.error(`Failed to upload ${file.name}`, error);
320+
const errorMsg = error instanceof Error ? error.message : 'Unknown error';
321+
console.error(`Error details for ${file.name}:`, errorMsg);
311322
newProgress[file.name] = "error";
323+
addToast(`Failed to upload ${file.name}: ${errorMsg}`, "error");
312324
}
313325

314326
setProgress({ ...newProgress });

0 commit comments

Comments
 (0)