bulk actions on tags page

This commit is contained in:
Isaac Wise
2024-02-11 00:19:59 -06:00
parent 8ecedf7cae
commit e753f1dded
4 changed files with 162 additions and 16 deletions
+34
View File
@@ -0,0 +1,34 @@
import useAccountStore from "@/store/account";
import useCollectionStore from "@/store/collections";
import { Member } from "@/types/global";
import { useEffect, useState } from "react";
export default function useCollectivePermissions(collectionIds: number[]) {
const { collections } = useCollectionStore();
const { account } = useAccountStore();
const [permissions, setPermissions] = useState<Member | true>();
useEffect(() => {
for (const collectionId of collectionIds) {
const collection = collections.find((e) => e.id === collectionId);
if (collection) {
let getPermission: Member | undefined = collection.members.find(
(e) => e.userId === account.id
);
if (
getPermission?.canCreate === false &&
getPermission?.canUpdate === false &&
getPermission?.canDelete === false
)
getPermission = undefined;
setPermissions(account.id === collection.ownerId || getPermission);
}
}
}, [account, collections, collectionIds]);
return permissions;
}
+6 -5
View File
@@ -1,13 +1,15 @@
import useAccountStore from "@/store/account";
import useCollectionStore from "@/store/collections";
import { Member } from "@/types/global";
import { useMemo } from "react";
import { useEffect, useState } from "react";
export default function usePermissions(collectionId: number) {
const { collections } = useCollectionStore();
const { account } = useAccountStore();
const permissions = useMemo(() => {
const [permissions, setPermissions] = useState<Member | true>();
useEffect(() => {
const collection = collections.find((e) => e.id === collectionId);
if (collection) {
@@ -19,11 +21,10 @@ export default function usePermissions(collectionId: number) {
getPermission?.canCreate === false &&
getPermission?.canUpdate === false &&
getPermission?.canDelete === false
) {
)
getPermission = undefined;
}
return account.id === collection.ownerId || getPermission;
setPermissions(account.id === collection.ownerId || getPermission);
}
}, [account, collections, collectionId]);