bug fixed

This commit is contained in:
daniel31x13
2024-11-09 23:07:01 -05:00
parent 9c9fd969bc
commit 836360f99d
2 changed files with 40 additions and 26 deletions
+5 -12
View File
@@ -29,7 +29,7 @@ const CollectionListing = () => {
const updateCollection = useUpdateCollection();
const { data: collections = [], isLoading } = useCollections();
const { data: user = {} } = useUser();
const { data: user = {}, refetch } = useUser();
const updateUser = useUpdateUser();
const router = useRouter();
@@ -38,10 +38,7 @@ const CollectionListing = () => {
const [tree, setTree] = useState<TreeData | undefined>();
const initialTree = useMemo(() => {
if (
// !tree &&
collections.length > 0
) {
if (collections.length > 0) {
return buildTreeFromCollections(
collections,
router,
@@ -52,12 +49,12 @@ const CollectionListing = () => {
}, [collections, user, router]);
useEffect(() => {
// if (!tree)
setTree(initialTree);
}, [initialTree]);
useEffect(() => {
if (user.username) {
refetch();
if (
(!user.collectionOrder || user.collectionOrder.length === 0) &&
collections.length > 0
@@ -65,11 +62,7 @@ const CollectionListing = () => {
updateUser.mutate({
...user,
collectionOrder: collections
.filter(
(e) =>
e.parentId === null ||
!collections.find((i) => i.id === e.parentId)
) // Filter out collections with non-null parentId
.filter((e) => e.parentId === null)
.map((e) => e.id as number),
});
else {
@@ -103,7 +96,7 @@ const CollectionListing = () => {
}
}
}
}, [collections]);
}, [user, collections]);
const onExpand = (movedCollectionId: ItemId) => {
setTree((currentTree) =>