Not even sure but I'm sure it's better

This commit is contained in:
2025-05-20 16:38:40 -05:00
parent 259aa46ef8
commit 0f92f7eb7f
19 changed files with 331 additions and 575 deletions

View File

@ -9,11 +9,11 @@ export const useFileUpload = () => {
const uploadToStorage = async (file: File, bucket: string) => {
try {
setIsUploading(true);
// Generate a unique filename to avoid collisions
const fileExt = file.name.split('.').pop();
const fileName = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}.${fileExt}`;
// Upload the file to Supabase storage
const uploadResult = await uploadFile({
bucket,
@ -24,15 +24,19 @@ export const useFileUpload = () => {
contentType: file.type,
},
});
if (!uploadResult.success) {
throw new Error(uploadResult.error || `Failed to upload to ${bucket}`);
}
return { success: true, path: uploadResult.data };
} catch (error) {
console.error(`Error uploading to ${bucket}:`, error);
toast.error(error instanceof Error ? error.message : `Failed to upload to ${bucket}`);
toast.error(
error instanceof Error
? error.message
: `Failed to upload to ${bucket}`,
);
return { success: false, error };
} finally {
setIsUploading(false);
@ -46,4 +50,4 @@ export const useFileUpload = () => {
fileInputRef,
uploadToStorage,
};
}
};