Refactor collection selection component and update navbar styling
This commit is contained in:
parent
4442ce8705
commit
f77ef58396
|
@ -15,7 +15,7 @@ type Props = {
|
||||||
links: boolean;
|
links: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const CollectionSelection = ({ links }: Props) => {
|
const CollectionListing = ({ links }: Props) => {
|
||||||
const { collections } = useCollectionStore();
|
const { collections } = useCollectionStore();
|
||||||
const { account, updateAccount } = useAccountStore();
|
const { account, updateAccount } = useAccountStore();
|
||||||
// Use local state to store the collection order so we don't have to wait for a response from the API to update the UI
|
// Use local state to store the collection order so we don't have to wait for a response from the API to update the UI
|
||||||
|
@ -29,30 +29,38 @@ const CollectionSelection = ({ links }: Props) => {
|
||||||
setActive(router.asPath);
|
setActive(router.asPath);
|
||||||
setLocalCollectionOrder(account.collectionOrder || []);
|
setLocalCollectionOrder(account.collectionOrder || []);
|
||||||
|
|
||||||
if (!account.collectionOrder || account.collectionOrder.length === 0) {
|
|
||||||
updateAccount({
|
|
||||||
...account,
|
|
||||||
collectionOrder: collections
|
|
||||||
.filter((e) => e.parentId === null) // Filter out collections with non-null parentId
|
|
||||||
.map((e) => e.id as number), // Use "as number" to assert that e.id is a number
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// if a collection wasn't in the collectionOrder, add it to the end
|
// if a collection wasn't in the collectionOrder, add it to the end
|
||||||
collections.forEach((collection) => {
|
if (account.username) {
|
||||||
if (
|
if (!account.collectionOrder || account.collectionOrder.length === 0)
|
||||||
!account.collectionOrder.includes(collection.id as number) &&
|
|
||||||
(!collection.parentId || collection.ownerId !== account.id)
|
|
||||||
) {
|
|
||||||
updateAccount({
|
updateAccount({
|
||||||
...account,
|
...account,
|
||||||
collectionOrder: [
|
collectionOrder: collections
|
||||||
...account.collectionOrder,
|
.filter((e) => e.parentId === null) // Filter out collections with non-null parentId
|
||||||
collection.id as number,
|
.map((e) => e.id as number), // Use "as number" to assert that e.id is a number
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
else {
|
||||||
|
const newCollectionOrder: number[] = [
|
||||||
|
...(account.collectionOrder || []),
|
||||||
|
];
|
||||||
|
|
||||||
|
collections?.forEach((collection) => {
|
||||||
|
if (
|
||||||
|
account.username &&
|
||||||
|
!newCollectionOrder.includes(collection.id as number) &&
|
||||||
|
(!collection.parentId || collection.ownerId !== account.id)
|
||||||
|
) {
|
||||||
|
newCollectionOrder.push(collection.id as number);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (newCollectionOrder.length > account.collectionOrder.length) {
|
||||||
|
updateAccount({
|
||||||
|
...account,
|
||||||
|
collectionOrder: newCollectionOrder,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}, [router, collections, account]);
|
}, [router, collections, account]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -119,7 +127,7 @@ const CollectionSelection = ({ links }: Props) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CollectionSelection;
|
export default CollectionListing;
|
||||||
|
|
||||||
const CollectionItem = ({
|
const CollectionItem = ({
|
||||||
collection,
|
collection,
|
||||||
|
@ -166,7 +174,7 @@ const CollectionItem = ({
|
||||||
{...props}
|
{...props}
|
||||||
className={`${
|
className={`${
|
||||||
active === `/collections/${collection.id}`
|
active === `/collections/${collection.id}`
|
||||||
? "bg-primary/20"
|
? "bg-primary/20 is-active"
|
||||||
: "hover:bg-neutral/20"
|
: "hover:bg-neutral/20"
|
||||||
} duration-100 rounded-md flex w-full items-center cursor-pointer mb-1 px-2 gap-1`}
|
} duration-100 rounded-md flex w-full items-center cursor-pointer mb-1 px-2 gap-1`}
|
||||||
>
|
>
|
||||||
|
|
|
@ -56,7 +56,7 @@ export default function Navbar() {
|
||||||
setSidebar(true);
|
setSidebar(true);
|
||||||
document.body.style.overflow = "hidden";
|
document.body.style.overflow = "hidden";
|
||||||
}}
|
}}
|
||||||
className="text-neutral btn btn-square btn-sm btn-ghost lg:hidden hidden sm:inline-flex"
|
className="text-neutral btn btn-square btn-sm btn-ghost lg:hidden sm:inline-flex"
|
||||||
>
|
>
|
||||||
<i className="bi-list text-2xl leading-none"></i>
|
<i className="bi-list text-2xl leading-none"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
Ŝarĝante…
Reference in New Issue