better profile photo update logic
This commit is contained in:
+2
-12
@@ -1,6 +1,5 @@
|
||||
import { create } from "zustand";
|
||||
import { AccountSettings } from "@/types/global";
|
||||
import avatarExists from "@/lib/client/avatarExists";
|
||||
|
||||
type AccountStore = {
|
||||
account: AccountSettings;
|
||||
@@ -8,13 +7,6 @@ type AccountStore = {
|
||||
updateAccount: (user: AccountSettings) => Promise<boolean>;
|
||||
};
|
||||
|
||||
const determineProfilePicSource = async (data: any) => {
|
||||
const path = `/api/avatar/${data.response.id}`;
|
||||
const imageExists = await avatarExists(path);
|
||||
if (imageExists) return path + "?" + Date.now();
|
||||
else return null;
|
||||
};
|
||||
|
||||
const useAccountStore = create<AccountStore>()((set) => ({
|
||||
account: {} as AccountSettings,
|
||||
setAccount: async (email) => {
|
||||
@@ -22,7 +14,7 @@ const useAccountStore = create<AccountStore>()((set) => ({
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
const profilePic = await determineProfilePicSource(data);
|
||||
const profilePic = `/api/avatar/${data.response.id}?${Date.now()}`;
|
||||
|
||||
if (response.ok) set({ account: { ...data.response, profilePic } });
|
||||
},
|
||||
@@ -39,9 +31,7 @@ const useAccountStore = create<AccountStore>()((set) => ({
|
||||
|
||||
console.log(data);
|
||||
|
||||
const profilePic = await determineProfilePicSource(data);
|
||||
|
||||
if (response.ok) set({ account: { ...data.response, profilePic } });
|
||||
if (response.ok) set({ account: { ...data.response } });
|
||||
|
||||
return response.ok;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user