feat: stop force redirect to create collection form

This commit is contained in:
Sonny
2025-08-21 02:46:44 +02:00
parent 4ef2b639b6
commit 23ad1fda75
6 changed files with 61 additions and 54 deletions

View File

@@ -19,10 +19,6 @@ export default class ShowCollectionsController {
this.linkService.getFavoriteLinksForAuthenticatedUser(),
]);
if (collections.length === 0) {
return response.redirectToNamedRoute('collection.create-form');
}
const activeCollection = collections.find(
(c) => c.id === activeCollectionId
);

View File

@@ -1,5 +1,5 @@
import { DisplayPreferences } from '#shared/types/index';
import { SimpleGrid, Stack, StyleProp, useCombobox } from '@mantine/core';
import { SimpleGrid, Stack, StyleProp } from '@mantine/core';
import { LinkItem } from '~/components/dashboard/link/item/link_item';
import { NoLink } from '~/components/dashboard/link/no_link/no_link';
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
@@ -15,13 +15,9 @@ export function LinkList({ hideMenu = false }: LinkListProps) {
const favoriteLinks = useFavoriteLinks();
const { displayPreferences } = useDisplayPreferences();
const combobox = useCombobox({
onDropdownClose: () => combobox.resetSelectedOption(),
});
const links = activeCollection?.links || favoriteLinks;
if (activeCollection?.links.length === 0) {
if (links.length === 0) {
return <NoLink hideMenu={hideMenu} />;
}

View File

@@ -12,21 +12,27 @@ interface NoLinkProps extends LinkListProps {}
export function NoLink({ hideMenu }: NoLinkProps) {
const { t } = useTranslation('common');
const activeCollection = useActiveCollection();
const isFavorite = !activeCollection?.id;
const noLinkForCollection = t(
'home:no-link',
{ name: activeCollection?.name ?? '' } as any,
{
interpolation: { escapeValue: false },
}
);
const noLinkForFavorite = t('home:no-link-favorite');
return (
<Box className={styles.noCollection} p="xl">
<Text
className={styles.text}
dangerouslySetInnerHTML={{
__html: t(
'home:no-link',
{ name: activeCollection?.name ?? '' } as any,
{
interpolation: { escapeValue: false },
}
),
__html: isFavorite ? noLinkForFavorite : noLinkForCollection,
}}
/>
{!hideMenu && (
{!hideMenu && !isFavorite && (
<Anchor
component={Link}
href={appendCollectionId(

View File

@@ -1,5 +1,6 @@
{
"select-collection": "Please select a collection",
"or-create-one": "or create one",
"no-link": "No link for <b>{{name}}</b>"
"select-collection": "Please select a collection",
"or-create-one": "or create one",
"no-link": "No link for <b>{{name}}</b>",
"no-link-favorite": "No favorite link"
}

View File

@@ -1,5 +1,6 @@
{
"select-collection": "Veuillez sélectionner une collection",
"or-create-one": "ou en créer une",
"no-link": "Aucun lien pour <b>{{name}}</b>"
"select-collection": "Veuillez sélectionner une collection",
"or-create-one": "ou en créer une",
"no-link": "Aucun lien pour <b>{{name}}</b>",
"no-link-favorite": "Aucun lien dans les favoris"
}

View File

@@ -39,24 +39,27 @@ export default function Dashboard() {
disabled
/>
</Tooltip>
{!isFavorite && (
<Group>
{activeCollection?.visibility === Visibility.PUBLIC && (
<SharedCollectionCopyLink />
<Group>
{!isFavorite &&
activeCollection?.visibility === Visibility.PUBLIC && (
<>
<SharedCollectionCopyLink />
<Divider orientation="vertical" />
</>
)}
<Divider orientation="vertical" />
<Button
variant="outline"
component={Link}
href={appendCollectionId(
route('collection.create-form').path,
activeCollection?.id
)}
size="xs"
>
{t('collection.create')}
</Button>
<Button
variant="outline"
component={Link}
href={appendCollectionId(
route('collection.create-form').path,
activeCollection?.id
)}
size="xs"
>
{t('collection.create')}
</Button>
{!isFavorite && (
<Button
variant="outline"
component={Link}
@@ -68,21 +71,25 @@ export default function Dashboard() {
>
{t('collection.edit')}
</Button>
)}
<Divider orientation="vertical" />
<Button
variant="light"
component={Link}
href={appendCollectionId(
route('link.create-form').path,
activeCollection?.id
)}
size="xs"
>
{t('link.create')}
</Button>
</Group>
)}
{!isFavorite && (
<>
<Divider orientation="vertical" />
<Button
variant="light"
component={Link}
href={appendCollectionId(
route('link.create-form').path,
activeCollection?.id
)}
size="xs"
>
{t('link.create')}
</Button>
</>
)}
</Group>
</Group>
{displayPreferences.collectionListDisplay === 'inline' && !isMobile && (
<InlineCollectionList />