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

@ -17,9 +17,9 @@ export const useAvatar = (profile?: Profile) => {
url: profile.avatar_url,
transform: {
quality: 20,
}
},
});
if (response.success) {
setAvatarUrl(response.data);
}
@ -32,15 +32,18 @@ export const useAvatar = (profile?: Profile) => {
setAvatarUrl(undefined);
}
};
getAvatarUrl().catch((error) => {
toast.error(error instanceof Error ? error.message : 'Failed to get signed avatar url.');
});
getAvatarUrl().catch((error) => {
toast.error(
error instanceof Error
? error.message
: 'Failed to get signed avatar url.',
);
});
}, [profile]);
return {
avatarUrl,
isLoading,
};
}
};

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,
};
}
};

View File

@ -22,7 +22,9 @@ export const useProfile = () => {
}
};
fetchProfile().catch((error) => {
toast.error(error instanceof Error ? error.message : 'Failed to get profile');
toast.error(
error instanceof Error ? error.message : 'Failed to get profile',
);
});
}, []);
@ -42,7 +44,9 @@ export const useProfile = () => {
return { success: true, data: result.data };
} catch (error) {
console.error('Error updating profile: ', error);
toast.error(error instanceof Error ? error.message : 'Failed to update profile');
toast.error(
error instanceof Error ? error.message : 'Failed to update profile',
);
return { success: false, error };
} finally {
setIsLoading(false);
@ -54,4 +58,4 @@ export const useProfile = () => {
isLoading,
updateProfile: updateUserProfile,
};
}
};