mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 15:05:35 +00:00
fix: error when editing collection
This commit is contained in:
@@ -15,7 +15,7 @@ export default class CollectionsController {
|
|||||||
return response.redirectToNamedRoute('collection.create-form');
|
return response.redirectToNamedRoute('collection.create-form');
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeCollectionId = request.qs()?.collectionId ?? '';
|
const activeCollectionId = Number(request.qs()?.collectionId ?? '');
|
||||||
const activeCollection = collections.find(
|
const activeCollection = collections.find(
|
||||||
(c) => c.id === activeCollectionId
|
(c) => c.id === activeCollectionId
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export default class LogRequest {
|
|||||||
!request.url().startsWith('/@react-refresh') &&
|
!request.url().startsWith('/@react-refresh') &&
|
||||||
!request.url().includes('.ts')
|
!request.url().includes('.ts')
|
||||||
) {
|
) {
|
||||||
logger.info(`[${request.method()}]: ${request.url()}`);
|
logger.debug(`[${request.method()}]: ${request.url()}`);
|
||||||
}
|
}
|
||||||
await next();
|
await next();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export default class Collection extends AppBaseModel {
|
|||||||
declare visibility: Visibility;
|
declare visibility: Visibility;
|
||||||
|
|
||||||
@column()
|
@column()
|
||||||
declare next_id: number;
|
declare nextId: number;
|
||||||
|
|
||||||
@column()
|
@column()
|
||||||
declare authorId: number;
|
declare authorId: number;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type Collection from '#models/collection';
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { Link } from '@inertiajs/react';
|
import { Link } from '@inertiajs/react';
|
||||||
import { route } from '@izzyjs/route/client';
|
import { route } from '@izzyjs/route/client';
|
||||||
|
import { useEffect, useRef } from 'react';
|
||||||
import { AiFillFolderOpen, AiOutlineFolder } from 'react-icons/ai';
|
import { AiFillFolderOpen, AiOutlineFolder } from 'react-icons/ai';
|
||||||
import TextEllipsis from '~/components/common/text_ellipsis';
|
import TextEllipsis from '~/components/common/text_ellipsis';
|
||||||
import { Item } from '~/components/dashboard/side_nav/nav_item';
|
import { Item } from '~/components/dashboard/side_nav/nav_item';
|
||||||
@@ -29,14 +30,22 @@ export default function CollectionItem({
|
|||||||
}: {
|
}: {
|
||||||
collection: Collection;
|
collection: Collection;
|
||||||
}) {
|
}) {
|
||||||
|
const itemRef = useRef<HTMLDivElement>(null);
|
||||||
const { activeCollection } = useActiveCollection();
|
const { activeCollection } = useActiveCollection();
|
||||||
const isActiveCollection = collection.id === activeCollection?.id;
|
const isActiveCollection = collection.id === activeCollection?.id;
|
||||||
const FolderIcon = isActiveCollection ? AiFillFolderOpen : AiOutlineFolder;
|
const FolderIcon = isActiveCollection ? AiFillFolderOpen : AiOutlineFolder;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (collection.id === activeCollection?.id) {
|
||||||
|
itemRef.current?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||||||
|
}
|
||||||
|
}, [collection.id, activeCollection?.id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CollectionItemLink
|
<CollectionItemLink
|
||||||
href={appendCollectionId(route('dashboard').url, collection.id)}
|
href={appendCollectionId(route('dashboard').url, collection.id)}
|
||||||
isActive={isActiveCollection}
|
isActive={isActiveCollection}
|
||||||
|
ref={itemRef}
|
||||||
>
|
>
|
||||||
<FolderIcon css={{ minWidth: '24px' }} size={24} />
|
<FolderIcon css={{ minWidth: '24px' }} size={24} />
|
||||||
<TextEllipsis>{collection.name}</TextEllipsis>
|
<TextEllipsis>{collection.name}</TextEllipsis>
|
||||||
|
|||||||
@@ -23,9 +23,11 @@ export default function LinkList({ links }: { links: Link[] }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<LinkListStyle>
|
<LinkListStyle>
|
||||||
{links.map((link) => (
|
{links
|
||||||
<LinkItem link={link} key={link.id} showUserControls />
|
.sort((a, b) => (a.created_at > b.created_at ? 1 : -1))
|
||||||
))}
|
.map((link) => (
|
||||||
|
<LinkItem link={link} key={link.id} showUserControls />
|
||||||
|
))}
|
||||||
</LinkListStyle>
|
</LinkListStyle>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type Collection from '#models/collection';
|
||||||
import { FormEvent } from 'react';
|
import { FormEvent } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import Checkbox from '~/components/common/form/checkbox';
|
import Checkbox from '~/components/common/form/checkbox';
|
||||||
@@ -10,6 +11,7 @@ export type FormCollectionData = {
|
|||||||
name: string;
|
name: string;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
visibility: Visibility;
|
visibility: Visibility;
|
||||||
|
nextId: Collection['id'];
|
||||||
};
|
};
|
||||||
|
|
||||||
interface FormCollectionProps {
|
interface FormCollectionProps {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export default function EditCollectionPage({
|
|||||||
name: collection.name,
|
name: collection.name,
|
||||||
description: collection.description,
|
description: collection.description,
|
||||||
visibility: collection.visibility,
|
visibility: collection.visibility,
|
||||||
|
nextId: collection.nextId,
|
||||||
});
|
});
|
||||||
const canSubmit = useMemo<boolean>(() => {
|
const canSubmit = useMemo<boolean>(() => {
|
||||||
const isFormEdited =
|
const isFormEdited =
|
||||||
|
|||||||
Reference in New Issue
Block a user