Cleanup. Stuff from yesterday idk

This commit is contained in:
2025-06-06 08:43:18 -05:00
parent a776c5a30a
commit 35e019558f
29 changed files with 866 additions and 694 deletions

View File

@ -1,14 +1,13 @@
'use client'
'use client';
import { useState, useRef } from 'react';
import { replaceFile, uploadFile } from '@/lib/hooks';
import { toast } from 'sonner';
import { useAuth } from '@/components/context/auth';
import { resizeImage } from '@/lib/hooks';
import type { Result } from '.';
export type Replace =
| { replace: true, path: string }
| false;
export type Replace = { replace: true; path: string } | false;
export type uploadToStorageProps = {
file: File;
@ -33,7 +32,7 @@ export const useFileUpload = () => {
resize = false,
options = {},
replace = false,
}: uploadToStorageProps) => {
}: uploadToStorageProps): Promise<Result<string>> => {
try {
if (!isAuthenticated) throw new Error('User is not authenticated');
@ -48,10 +47,9 @@ export const useFileUpload = () => {
},
});
if (!updateResult.success) {
console.error('Error updating file:', updateResult.error);
return { success: false, error: updateResult.error };
} else {
console.log('We used the new update function hopefully it worked!');
return { success: true, path: updateResult.data };
return { success: true, data: updateResult.data };
}
}
@ -77,15 +75,21 @@ export const useFileUpload = () => {
throw new Error(uploadResult.error || `Failed to upload to ${bucket}`);
}
return { success: true, path: uploadResult.data };
return { success: true, data: uploadResult.data };
} catch (error) {
console.error(`Error uploading to ${bucket}:`, error);
toast.error(
error instanceof Error
? error.message
: `Failed to upload to ${bucket}`,
);
return { success: false, error };
return {
success: false,
error: `Error: ${
error instanceof Error
? error.message
: `Failed to upload to ${bucket}`
}`,
};
} finally {
setIsUploading(false);
// Clear the input value so the same file can be selected again