mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 22:53:25 +00:00
feat: add collection list
This commit is contained in:
@@ -8,35 +8,39 @@ import useClickOutside from '~/hooks/use_click_outside';
|
||||
import useGlobalHotkeys from '~/hooks/use_global_hotkeys';
|
||||
import useToggle from '~/hooks/use_modal';
|
||||
|
||||
const DropdownStyle = styled.div<{ opened: boolean }>(({ opened, theme }) => ({
|
||||
cursor: 'pointer',
|
||||
userSelect: 'none',
|
||||
position: 'relative',
|
||||
minWidth: 'fit-content',
|
||||
width: 'fit-content',
|
||||
maxWidth: '250px',
|
||||
backgroundColor: opened ? theme.colors.secondary : theme.colors.background,
|
||||
padding: '4px',
|
||||
borderRadius: theme.border.radius,
|
||||
const DropdownStyle = styled.div<{ opened: boolean; svgSize?: number }>(
|
||||
({ opened, theme, svgSize = 24 }) => ({
|
||||
cursor: 'pointer',
|
||||
userSelect: 'none',
|
||||
position: 'relative',
|
||||
minWidth: 'fit-content',
|
||||
width: 'fit-content',
|
||||
maxWidth: '250px',
|
||||
backgroundColor: opened ? theme.colors.secondary : theme.colors.background,
|
||||
padding: '4px',
|
||||
borderRadius: theme.border.radius,
|
||||
|
||||
'&:hover': {
|
||||
backgroundColor: theme.colors.secondary,
|
||||
},
|
||||
'&:hover': {
|
||||
backgroundColor: theme.colors.secondary,
|
||||
},
|
||||
|
||||
'& svg': {
|
||||
height: '24px',
|
||||
width: '24px',
|
||||
},
|
||||
}));
|
||||
'& svg': {
|
||||
height: `${svgSize}px`,
|
||||
width: `${svgSize}px`,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
export default function Dropdown({
|
||||
children,
|
||||
label,
|
||||
className,
|
||||
svgSize,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
label: ReactNode | string;
|
||||
className?: string;
|
||||
svgSize?: number;
|
||||
}) {
|
||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||
const { isShowing, toggle, close } = useToggle();
|
||||
@@ -55,6 +59,7 @@ export default function Dropdown({
|
||||
onClick={toggle}
|
||||
ref={dropdownRef}
|
||||
className={className}
|
||||
svgSize={svgSize}
|
||||
>
|
||||
<DropdownLabel>{label}</DropdownLabel>
|
||||
<DropdownContainer show={isShowing}>{children}</DropdownContainer>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import styled from '@emotion/styled';
|
||||
import { Link } from '@inertiajs/react';
|
||||
import { RxHamburgerMenu } from 'react-icons/rx';
|
||||
import CollectionControls from '~/components/dashboard/collection/collection_controls';
|
||||
import CollectionDescription from '~/components/dashboard/collection/collection_description';
|
||||
import CollectionHeader from '~/components/dashboard/collection/collection_header';
|
||||
import CollectionControls from '~/components/dashboard/collection/header/collection_controls';
|
||||
import CollectionDescription from '~/components/dashboard/collection/header/collection_description';
|
||||
import CollectionHeader from '~/components/dashboard/collection/header/collection_header';
|
||||
import LinkList from '~/components/dashboard/link/link_list';
|
||||
import { NoCollection } from '~/components/dashboard/link/no_item';
|
||||
import Footer from '~/components/footer/footer';
|
||||
|
||||
@@ -7,7 +7,7 @@ import Dropdown from '~/components/common/dropdown/dropdown';
|
||||
import { DropdownItemLink } from '~/components/common/dropdown/dropdown_item';
|
||||
|
||||
const CollectionControls = () => (
|
||||
<Dropdown label={<BsThreeDotsVertical />}>
|
||||
<Dropdown label={<BsThreeDotsVertical />} svgSize={18}>
|
||||
<DropdownItemLink href={PATHS.LINK.CREATE}>
|
||||
<IoIosAddCircleOutline /> Add
|
||||
</DropdownItemLink>
|
||||
@@ -0,0 +1,8 @@
|
||||
import styled from '@emotion/styled';
|
||||
import { Item } from '~/components/dashboard/side_nav/nav_item';
|
||||
|
||||
const CollectionItem = styled(Item)(({ theme }) => ({
|
||||
backgroundColor: theme.colors.secondary,
|
||||
}));
|
||||
|
||||
export default CollectionItem;
|
||||
@@ -0,0 +1,66 @@
|
||||
import { useTheme } from '@emotion/react';
|
||||
import styled from '@emotion/styled';
|
||||
import { AiFillFolderOpen, AiOutlineFolder } from 'react-icons/ai';
|
||||
import TextEllipsis from '~/components/common/text_ellipsis';
|
||||
import CollectionItem from '~/components/dashboard/collection/list/collection_item';
|
||||
import CollectionListContainer from '~/components/dashboard/collection/list/collection_list_container';
|
||||
import useActiveCollection from '~/hooks/use_active_collection';
|
||||
import useCollections from '~/hooks/use_collections';
|
||||
|
||||
const SideMenu = styled.nav(({ theme }) => ({
|
||||
height: '100%',
|
||||
paddingLeft: '10px',
|
||||
marginLeft: '5px',
|
||||
borderLeft: `1px solid ${theme.colors.lightGrey}`,
|
||||
display: 'flex',
|
||||
gap: '.35em',
|
||||
flexDirection: 'column',
|
||||
}));
|
||||
|
||||
const CollectionLabel = styled.p(({ theme }) => ({
|
||||
color: theme.colors.grey,
|
||||
}));
|
||||
const CollectionListStyle = styled.div({
|
||||
padding: '1px',
|
||||
paddingRight: '5px',
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
gap: '.35em',
|
||||
flexDirection: 'column',
|
||||
overflow: 'auto',
|
||||
});
|
||||
|
||||
export default function CollectionList() {
|
||||
const { activeCollection, setActiveCollection } = useActiveCollection();
|
||||
const { collections } = useCollections();
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<SideMenu>
|
||||
<CollectionListContainer>
|
||||
<CollectionLabel>Collections • {collections.length}</CollectionLabel>
|
||||
<CollectionListStyle>
|
||||
{collections.map((collection) => (
|
||||
<CollectionItem
|
||||
css={{
|
||||
cursor: 'pointer',
|
||||
color:
|
||||
activeCollection?.id === collection.id
|
||||
? theme.colors.primary
|
||||
: theme.colors.font,
|
||||
}}
|
||||
onClick={() => setActiveCollection(collection)}
|
||||
key={collection.id}
|
||||
>
|
||||
{collection.id === activeCollection?.id ? (
|
||||
<AiFillFolderOpen size={24} />
|
||||
) : (
|
||||
<AiOutlineFolder size={24} />
|
||||
)}
|
||||
<TextEllipsis>{collection.name}</TextEllipsis>
|
||||
</CollectionItem>
|
||||
))}
|
||||
</CollectionListStyle>
|
||||
</CollectionListContainer>
|
||||
</SideMenu>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
const CollectionListContainer = styled.div({
|
||||
height: '100%',
|
||||
minHeight: 0,
|
||||
paddingInline: '10px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
});
|
||||
|
||||
export default CollectionListContainer;
|
||||
@@ -66,6 +66,7 @@ export default function LinkControls({ link }: { link: Link }) {
|
||||
<Dropdown
|
||||
label={<BsThreeDotsVertical css={{ color: theme.colors.grey }} />}
|
||||
css={{ backgroundColor: theme.colors.secondary }}
|
||||
svgSize={18}
|
||||
>
|
||||
<StartItem onClick={onFavorite}>
|
||||
{!link.favorite ? (
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Link } from '@inertiajs/react';
|
||||
export const Item = styled.div(({ theme }) => ({
|
||||
userSelect: 'none',
|
||||
height: '40px',
|
||||
width: '280px',
|
||||
width: '250px',
|
||||
color: theme.colors.font,
|
||||
backgroundColor: theme.colors.background,
|
||||
padding: '8px 12px',
|
||||
|
||||
@@ -8,7 +8,12 @@ export default function UserCard() {
|
||||
return (
|
||||
isAuthenticated && (
|
||||
<Item className="disable-hover">
|
||||
<RoundedImage src={user.avatarUrl} width={24} alt={altImage} />
|
||||
<RoundedImage
|
||||
src={user.avatarUrl}
|
||||
width={24}
|
||||
alt={altImage}
|
||||
referrerPolicy="no-referrer"
|
||||
/>
|
||||
{user.nickName}
|
||||
</Item>
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ import { ReactNode, useEffect, useMemo, useState } from 'react';
|
||||
import { useHotkeys } from 'react-hotkeys-hook';
|
||||
import { useSwipeable } from 'react-swipeable';
|
||||
import CollectionContainer from '~/components/dashboard/collection/collection_container';
|
||||
import CollectionList from '~/components/dashboard/collection/list/collection_list';
|
||||
import SideNavigation from '~/components/dashboard/side_nav/side_navigation';
|
||||
import SwiperHandler from '~/components/dashboard/swiper_handler';
|
||||
import DashboardLayout from '~/components/layouts/dashboard_layout';
|
||||
@@ -55,6 +56,7 @@ export default function DashboardPage(props: Readonly<DashboardPageProps>) {
|
||||
</SideBar>
|
||||
)}
|
||||
<CollectionContainer isMobile={isMobile} openSideMenu={open} />
|
||||
<CollectionList />
|
||||
</SwiperHandler>
|
||||
</DashboardProviders>
|
||||
</DashboardLayout>
|
||||
|
||||
Reference in New Issue
Block a user