fix: error when editing collection

This commit is contained in:
Sonny
2024-05-25 17:36:45 +02:00
committed by Sonny
parent 8b161dcf49
commit 9481b0ad7d
7 changed files with 20 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ import type Collection from '#models/collection';
import styled from '@emotion/styled';
import { Link } from '@inertiajs/react';
import { route } from '@izzyjs/route/client';
import { useEffect, useRef } from 'react';
import { AiFillFolderOpen, AiOutlineFolder } from 'react-icons/ai';
import TextEllipsis from '~/components/common/text_ellipsis';
import { Item } from '~/components/dashboard/side_nav/nav_item';
@@ -29,14 +30,22 @@ export default function CollectionItem({
}: {
collection: Collection;
}) {
const itemRef = useRef<HTMLDivElement>(null);
const { activeCollection } = useActiveCollection();
const isActiveCollection = collection.id === activeCollection?.id;
const FolderIcon = isActiveCollection ? AiFillFolderOpen : AiOutlineFolder;
useEffect(() => {
if (collection.id === activeCollection?.id) {
itemRef.current?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
}, [collection.id, activeCollection?.id]);
return (
<CollectionItemLink
href={appendCollectionId(route('dashboard').url, collection.id)}
isActive={isActiveCollection}
ref={itemRef}
>
<FolderIcon css={{ minWidth: '24px' }} size={24} />
<TextEllipsis>{collection.name}</TextEllipsis>

View File

@@ -23,9 +23,11 @@ export default function LinkList({ links }: { links: Link[] }) {
return (
<LinkListStyle>
{links.map((link) => (
<LinkItem link={link} key={link.id} showUserControls />
))}
{links
.sort((a, b) => (a.created_at > b.created_at ? 1 : -1))
.map((link) => (
<LinkItem link={link} key={link.id} showUserControls />
))}
</LinkListStyle>
);
}