mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 15:35:35 +00:00
feat: recreate favorite list/item
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: light-dark(--mantine-color-gray-1, rgb(50, 58, 71));
|
background-color: light-dark(var(--mantine-color-gray-1), rgb(50, 58, 71));
|
||||||
padding: 0.75em 1em;
|
padding: 0.75em 1em;
|
||||||
border-radius: var(--border-radius);
|
border-radius: var(--border-radius);
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ export default function CollectionItem({
|
|||||||
}
|
}
|
||||||
}, [collection.id, activeCollection?.id]);
|
}, [collection.id, activeCollection?.id]);
|
||||||
|
|
||||||
const linksCount = activeCollection?.links.length ?? 0;
|
const linksCount = collection?.links.length ?? 0;
|
||||||
|
const showLinks = linksCount > 0;
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
className={classes.link}
|
className={classes.link}
|
||||||
@@ -34,10 +35,10 @@ export default function CollectionItem({
|
|||||||
ref={itemRef}
|
ref={itemRef}
|
||||||
>
|
>
|
||||||
<FolderIcon className={classes.linkIcon} />
|
<FolderIcon className={classes.linkIcon} />
|
||||||
<Text lineClamp={1} maw="160px">
|
<Text lineClamp={1} maw={showLinks ? '160px' : '200px'}>
|
||||||
{collection.name}
|
{collection.name}
|
||||||
</Text>
|
</Text>
|
||||||
{linksCount > 0 && (
|
{showLinks && (
|
||||||
<Text c="var(--mantine-color-gray-5)" ml="xs">
|
<Text c="var(--mantine-color-gray-5)" ml="xs">
|
||||||
— {linksCount}
|
— {linksCount}
|
||||||
</Text>
|
</Text>
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ import {
|
|||||||
Divider,
|
Divider,
|
||||||
Group,
|
Group,
|
||||||
NavLink,
|
NavLink,
|
||||||
|
rem,
|
||||||
ScrollArea,
|
ScrollArea,
|
||||||
Skeleton,
|
|
||||||
Stack,
|
|
||||||
Text,
|
Text,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@@ -18,6 +17,7 @@ import { IoAdd, IoShieldHalfSharp } from 'react-icons/io5';
|
|||||||
import { PiGearLight } from 'react-icons/pi';
|
import { PiGearLight } from 'react-icons/pi';
|
||||||
import { MantineUserCard } from '~/components/common/mantine_user_card';
|
import { MantineUserCard } from '~/components/common/mantine_user_card';
|
||||||
import useUser from '~/hooks/use_user';
|
import useUser from '~/hooks/use_user';
|
||||||
|
import { FavoriteList } from '~/mantine/components/dashboard/favorite/favorite_list';
|
||||||
|
|
||||||
interface DashboardNavbarProps {
|
interface DashboardNavbarProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -32,7 +32,10 @@ export function DashboardNavbar({ isOpen, toggle }: DashboardNavbarProps) {
|
|||||||
active: true,
|
active: true,
|
||||||
styles: {
|
styles: {
|
||||||
label: {
|
label: {
|
||||||
fontSize: '16px',
|
fontSize: rem(16),
|
||||||
|
},
|
||||||
|
root: {
|
||||||
|
borderRadius: rem(5),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -55,10 +58,10 @@ export function DashboardNavbar({ isOpen, toggle }: DashboardNavbarProps) {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<NavLink
|
<NavLink
|
||||||
|
{...common}
|
||||||
label={t('settings')}
|
label={t('settings')}
|
||||||
leftSection={<PiGearLight size="1.5rem" />}
|
leftSection={<PiGearLight size="1.5rem" />}
|
||||||
variant="subtle"
|
color="var(--mantine-color-gray-7)"
|
||||||
styles={common.styles}
|
|
||||||
/>
|
/>
|
||||||
<NavLink
|
<NavLink
|
||||||
{...common}
|
{...common}
|
||||||
@@ -68,28 +71,19 @@ export function DashboardNavbar({ isOpen, toggle }: DashboardNavbarProps) {
|
|||||||
<NavLink
|
<NavLink
|
||||||
{...common}
|
{...common}
|
||||||
component={Link}
|
component={Link}
|
||||||
href={route('collection.create-form').url}
|
href={route('link.create-form').url}
|
||||||
label={t('collection.create')}
|
label={t('link.create')}
|
||||||
leftSection={<IoAdd size="1.5rem" />}
|
leftSection={<IoAdd size="1.5rem" />}
|
||||||
/>
|
/>
|
||||||
<NavLink
|
<NavLink
|
||||||
{...common}
|
{...common}
|
||||||
component={Link}
|
component={Link}
|
||||||
href={route('link.create-form').url}
|
href={route('collection.create-form').url}
|
||||||
label={t('link.create')}
|
label={t('collection.create')}
|
||||||
leftSection={<AiOutlineFolderAdd size="1.5rem" />}
|
leftSection={<AiOutlineFolderAdd size="1.5rem" />}
|
||||||
/>
|
/>
|
||||||
<Text c="dimmed" mt="xs" ml="md" mb="sm">
|
|
||||||
{t('favorite')} • {0}
|
|
||||||
</Text>
|
|
||||||
<AppShell.Section grow component={ScrollArea}>
|
<AppShell.Section grow component={ScrollArea}>
|
||||||
<Stack gap="xs">
|
<FavoriteList />
|
||||||
{Array(15)
|
|
||||||
.fill(0)
|
|
||||||
.map((_, index) => (
|
|
||||||
<Skeleton key={index} h={28} animate={false} />
|
|
||||||
))}
|
|
||||||
</Stack>
|
|
||||||
</AppShell.Section>
|
</AppShell.Section>
|
||||||
</AppShell.Navbar>
|
</AppShell.Navbar>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
.sideMenu {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
gap: 0.35em;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.listContainer {
|
||||||
|
height: 100%;
|
||||||
|
min-height: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.collectionList {
|
||||||
|
padding: 1px;
|
||||||
|
padding-right: 5px;
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
gap: 0.35em;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noFavorite {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { Box, Group, ScrollArea, Stack, Text } from '@mantine/core';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import useFavorites from '~/hooks/use_favorites';
|
||||||
|
import { FavoriteItem } from '~/mantine/components/dashboard/favorite/item/favorite_item';
|
||||||
|
import styles from './favorite_list.module.css';
|
||||||
|
|
||||||
|
export function FavoriteList() {
|
||||||
|
const { t } = useTranslation('common');
|
||||||
|
const { favorites } = useFavorites();
|
||||||
|
|
||||||
|
if (favorites.length === 0) {
|
||||||
|
return (
|
||||||
|
<Group justify="center">
|
||||||
|
<Text c="dimmed" size="sm" mt="sm">
|
||||||
|
{t('favorites-appears-here')}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box className={styles.sideMenu}>
|
||||||
|
<Box className={styles.listContainer}>
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
||||||
|
<Text c="dimmed" mt="xs" ml="md" mb={4}>
|
||||||
|
{t('favorite')} • {favorites.length}
|
||||||
|
</Text>
|
||||||
|
<ScrollArea className={styles.collectionList}>
|
||||||
|
<Stack gap={4}>
|
||||||
|
{favorites.map((link) => (
|
||||||
|
<FavoriteItem link={link} key={link.id} />
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
</ScrollArea>
|
||||||
|
</div>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
.linkWrapper {
|
||||||
|
user-select: none;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
background-color: light-dark(var(--mantine-color-gray-1), rgb(50, 58, 71));
|
||||||
|
padding: 0.25em 0.5em !important;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
border: 1px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.linkWrapper:hover {
|
||||||
|
border: 1px solid var(--mantine-color-blue-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.linkName {
|
||||||
|
width: 100%;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.linkDescription {
|
||||||
|
margin-top: 0.5em;
|
||||||
|
font-size: 0.8em;
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.linkUrl {
|
||||||
|
width: 100%;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 0.8em;
|
||||||
|
transition: opacity 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.linkWrapper:hover .linkUrlPathname {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.linkUrlPathname {
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.3s;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { Card, Group, Text } from '@mantine/core'; // Import de Mantine
|
||||||
|
import { ExternalLinkStyled } from '~/components/common/external_link_styled';
|
||||||
|
import LinkFavicon from '~/components/dashboard/link/link_favicon';
|
||||||
|
import { LinkWithCollection } from '~/types/app';
|
||||||
|
import styles from './favorite_item.module.css';
|
||||||
|
|
||||||
|
export const FavoriteItem = ({
|
||||||
|
link: { name, url, collection },
|
||||||
|
}: {
|
||||||
|
link: LinkWithCollection;
|
||||||
|
}) => (
|
||||||
|
<Card className={styles.linkWrapper} radius="sm" withBorder>
|
||||||
|
<Group justify="center" gap="xs">
|
||||||
|
<LinkFavicon url={url} />
|
||||||
|
<ExternalLinkStyled href={url} style={{ flex: 1 }}>
|
||||||
|
<div className={styles.linkName}>
|
||||||
|
<Text lineClamp={1}>{name} </Text>
|
||||||
|
</div>
|
||||||
|
<Text c="gray" size="xs" lineClamp={1}>
|
||||||
|
{collection.name}
|
||||||
|
</Text>
|
||||||
|
</ExternalLinkStyled>
|
||||||
|
</Group>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user