diff --git a/app/controllers/collections_controller.ts b/app/controllers/collections_controller.ts index 17725ee..c0fcd19 100644 --- a/app/controllers/collections_controller.ts +++ b/app/controllers/collections_controller.ts @@ -15,7 +15,7 @@ export default class CollectionsController { return response.redirectToNamedRoute('collection.create-form'); } - const activeCollectionId = request.qs()?.collectionId ?? ''; + const activeCollectionId = Number(request.qs()?.collectionId ?? ''); const activeCollection = collections.find( (c) => c.id === activeCollectionId ); diff --git a/app/middleware/log_request.ts b/app/middleware/log_request.ts index 8371949..e86b63c 100644 --- a/app/middleware/log_request.ts +++ b/app/middleware/log_request.ts @@ -10,7 +10,7 @@ export default class LogRequest { !request.url().startsWith('/@react-refresh') && !request.url().includes('.ts') ) { - logger.info(`[${request.method()}]: ${request.url()}`); + logger.debug(`[${request.method()}]: ${request.url()}`); } await next(); } diff --git a/app/models/collection.ts b/app/models/collection.ts index ebaaa8f..b8139fe 100644 --- a/app/models/collection.ts +++ b/app/models/collection.ts @@ -16,7 +16,7 @@ export default class Collection extends AppBaseModel { declare visibility: Visibility; @column() - declare next_id: number; + declare nextId: number; @column() declare authorId: number; diff --git a/inertia/components/dashboard/collection/list/collection_item.tsx b/inertia/components/dashboard/collection/list/collection_item.tsx index 8a544fe..05b9e6d 100644 --- a/inertia/components/dashboard/collection/list/collection_item.tsx +++ b/inertia/components/dashboard/collection/list/collection_item.tsx @@ -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(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 ( {collection.name} diff --git a/inertia/components/dashboard/link/link_list.tsx b/inertia/components/dashboard/link/link_list.tsx index 137769a..7237440 100644 --- a/inertia/components/dashboard/link/link_list.tsx +++ b/inertia/components/dashboard/link/link_list.tsx @@ -23,9 +23,11 @@ export default function LinkList({ links }: { links: Link[] }) { return ( - {links.map((link) => ( - - ))} + {links + .sort((a, b) => (a.created_at > b.created_at ? 1 : -1)) + .map((link) => ( + + ))} ); } diff --git a/inertia/components/form/form_collection.tsx b/inertia/components/form/form_collection.tsx index 1c4661e..5b240e9 100644 --- a/inertia/components/form/form_collection.tsx +++ b/inertia/components/form/form_collection.tsx @@ -1,3 +1,4 @@ +import type Collection from '#models/collection'; import { FormEvent } from 'react'; import { useTranslation } from 'react-i18next'; import Checkbox from '~/components/common/form/checkbox'; @@ -10,6 +11,7 @@ export type FormCollectionData = { name: string; description: string | null; visibility: Visibility; + nextId: Collection['id']; }; interface FormCollectionProps { diff --git a/inertia/pages/collections/edit.tsx b/inertia/pages/collections/edit.tsx index 42f9299..8087bae 100644 --- a/inertia/pages/collections/edit.tsx +++ b/inertia/pages/collections/edit.tsx @@ -18,6 +18,7 @@ export default function EditCollectionPage({ name: collection.name, description: collection.description, visibility: collection.visibility, + nextId: collection.nextId, }); const canSubmit = useMemo(() => { const isFormEdited =