refactor account store + much smoother collection listing updates

This commit is contained in:
daniel31x13
2024-07-30 23:19:29 -04:00
parent d1ed33b532
commit 5c5dd967c4
31 changed files with 260 additions and 259 deletions
+6 -7
View File
@@ -1,13 +1,12 @@
import useAccountStore from "@/store/account";
import { Member } from "@/types/global";
import { useEffect, useState } from "react";
import { useCollections } from "./store/collections";
import { useUser } from "./store/users";
export default function useCollectivePermissions(collectionIds: number[]) {
const { data: { response: collections } = { response: [] } } =
useCollections();
const { data: collections = [] } = useCollections();
const { account } = useAccountStore();
const { data: user = [] } = useUser();
const [permissions, setPermissions] = useState<Member | true>();
useEffect(() => {
@@ -16,7 +15,7 @@ export default function useCollectivePermissions(collectionIds: number[]) {
if (collection) {
let getPermission: Member | undefined = collection.members.find(
(e) => e.userId === account.id
(e) => e.userId === user.id
);
if (
@@ -26,10 +25,10 @@ export default function useCollectivePermissions(collectionIds: number[]) {
)
getPermission = undefined;
setPermissions(account.id === collection.ownerId || getPermission);
setPermissions(user.id === collection.ownerId || getPermission);
}
}
}, [account, collections, collectionIds]);
}, [user, collections, collectionIds]);
return permissions;
}