mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +00:00
refactor: use tabs instead of spaces
This commit is contained in:
@@ -7,33 +7,33 @@ import Footer from '~/components/footer/footer';
|
||||
import useActiveCollection from '~/hooks/use_active_collection';
|
||||
|
||||
export interface CollectionHeaderProps {
|
||||
showButtons: boolean;
|
||||
showControls?: boolean;
|
||||
openNavigationItem?: ReactNode;
|
||||
openCollectionItem?: ReactNode;
|
||||
showButtons: boolean;
|
||||
showControls?: boolean;
|
||||
openNavigationItem?: ReactNode;
|
||||
openCollectionItem?: ReactNode;
|
||||
}
|
||||
|
||||
const CollectionContainerStyle = styled.div({
|
||||
height: '100%',
|
||||
minWidth: 0,
|
||||
padding: '0.5em 0.5em 0',
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
minWidth: 0,
|
||||
padding: '0.5em 0.5em 0',
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
flexDirection: 'column',
|
||||
});
|
||||
|
||||
export default function CollectionContainer(props: CollectionHeaderProps) {
|
||||
const { activeCollection } = useActiveCollection();
|
||||
const { activeCollection } = useActiveCollection();
|
||||
|
||||
if (activeCollection === null) {
|
||||
return <NoCollection />;
|
||||
}
|
||||
if (activeCollection === null) {
|
||||
return <NoCollection />;
|
||||
}
|
||||
|
||||
return (
|
||||
<CollectionContainerStyle>
|
||||
<CollectionHeader {...props} />
|
||||
<LinkList links={activeCollection.links} />
|
||||
<Footer css={{ paddingBottom: 0 }} />
|
||||
</CollectionContainerStyle>
|
||||
);
|
||||
return (
|
||||
<CollectionContainerStyle>
|
||||
<CollectionHeader {...props} />
|
||||
<LinkList links={activeCollection.links} />
|
||||
<Footer css={{ paddingBottom: 0 }} />
|
||||
</CollectionContainerStyle>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,33 +10,33 @@ import { appendCollectionId } from '~/lib/navigation';
|
||||
import { Collection } from '~/types/app';
|
||||
|
||||
export default function CollectionControls({
|
||||
collectionId,
|
||||
collectionId,
|
||||
}: {
|
||||
collectionId: Collection['id'];
|
||||
collectionId: Collection['id'];
|
||||
}) {
|
||||
const { t } = useTranslation('common');
|
||||
return (
|
||||
<Dropdown label={<BsThreeDotsVertical />} svgSize={18}>
|
||||
<DropdownItemLink href={route('link.create-form').url}>
|
||||
<IoIosAddCircleOutline /> {t('link.create')}
|
||||
</DropdownItemLink>
|
||||
<DropdownItemLink
|
||||
href={appendCollectionId(
|
||||
route('collection.edit-form').url,
|
||||
collectionId
|
||||
)}
|
||||
>
|
||||
<GoPencil /> {t('collection.edit')}
|
||||
</DropdownItemLink>
|
||||
<DropdownItemLink
|
||||
href={appendCollectionId(
|
||||
route('collection.delete-form').url,
|
||||
collectionId
|
||||
)}
|
||||
danger
|
||||
>
|
||||
<IoTrashOutline /> {t('collection.delete')}
|
||||
</DropdownItemLink>
|
||||
</Dropdown>
|
||||
);
|
||||
const { t } = useTranslation('common');
|
||||
return (
|
||||
<Dropdown label={<BsThreeDotsVertical />} svgSize={18}>
|
||||
<DropdownItemLink href={route('link.create-form').url}>
|
||||
<IoIosAddCircleOutline /> {t('link.create')}
|
||||
</DropdownItemLink>
|
||||
<DropdownItemLink
|
||||
href={appendCollectionId(
|
||||
route('collection.edit-form').url,
|
||||
collectionId
|
||||
)}
|
||||
>
|
||||
<GoPencil /> {t('collection.edit')}
|
||||
</DropdownItemLink>
|
||||
<DropdownItemLink
|
||||
href={appendCollectionId(
|
||||
route('collection.delete-form').url,
|
||||
collectionId
|
||||
)}
|
||||
danger
|
||||
>
|
||||
<IoTrashOutline /> {t('collection.delete')}
|
||||
</DropdownItemLink>
|
||||
</Dropdown>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@ import TextEllipsis from '~/components/common/text_ellipsis';
|
||||
import useActiveCollection from '~/hooks/use_active_collection';
|
||||
|
||||
const CollectionDescriptionStyle = styled.div({
|
||||
width: '100%',
|
||||
fontSize: '0.85rem',
|
||||
marginBottom: '0.5rem',
|
||||
width: '100%',
|
||||
fontSize: '0.85rem',
|
||||
marginBottom: '0.5rem',
|
||||
});
|
||||
|
||||
export default function CollectionDescription() {
|
||||
const { activeCollection } = useActiveCollection();
|
||||
return (
|
||||
<CollectionDescriptionStyle>
|
||||
<TextEllipsis lines={3}>{activeCollection!.description}</TextEllipsis>
|
||||
</CollectionDescriptionStyle>
|
||||
);
|
||||
const { activeCollection } = useActiveCollection();
|
||||
return (
|
||||
<CollectionDescriptionStyle>
|
||||
<TextEllipsis lines={3}>{activeCollection!.description}</TextEllipsis>
|
||||
</CollectionDescriptionStyle>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,76 +12,76 @@ const paddingLeft = '1.25em';
|
||||
const paddingRight = '1.65em';
|
||||
|
||||
const CollectionHeaderWrapper = styled.div(({ theme }) => ({
|
||||
minWidth: 0,
|
||||
width: '100%',
|
||||
paddingInline: `${paddingLeft} ${paddingRight}`,
|
||||
marginBottom: '0.5em',
|
||||
minWidth: 0,
|
||||
width: '100%',
|
||||
paddingInline: `${paddingLeft} ${paddingRight}`,
|
||||
marginBottom: '0.5em',
|
||||
|
||||
[`@media (max-width: ${theme.media.tablet})`]: {
|
||||
paddingInline: 0,
|
||||
marginBottom: '1rem',
|
||||
},
|
||||
[`@media (max-width: ${theme.media.tablet})`]: {
|
||||
paddingInline: 0,
|
||||
marginBottom: '1rem',
|
||||
},
|
||||
}));
|
||||
|
||||
const CollectionHeaderStyle = styled.div({
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
|
||||
'& > svg': {
|
||||
display: 'flex',
|
||||
},
|
||||
'& > svg': {
|
||||
display: 'flex',
|
||||
},
|
||||
});
|
||||
|
||||
const CollectionName = styled.h2(({ theme }) => ({
|
||||
width: `calc(100% - (${paddingLeft} + ${paddingRight}))`,
|
||||
color: theme.colors.primary,
|
||||
display: 'flex',
|
||||
gap: '0.35em',
|
||||
alignItems: 'center',
|
||||
width: `calc(100% - (${paddingLeft} + ${paddingRight}))`,
|
||||
color: theme.colors.primary,
|
||||
display: 'flex',
|
||||
gap: '0.35em',
|
||||
alignItems: 'center',
|
||||
|
||||
[`@media (max-width: ${theme.media.tablet})`]: {
|
||||
width: `calc(100% - (${paddingLeft} + ${paddingRight} + 1.75em))`,
|
||||
},
|
||||
[`@media (max-width: ${theme.media.tablet})`]: {
|
||||
width: `calc(100% - (${paddingLeft} + ${paddingRight} + 1.75em))`,
|
||||
},
|
||||
}));
|
||||
|
||||
const LinksCount = styled.div(({ theme }) => ({
|
||||
minWidth: 'fit-content',
|
||||
fontWeight: 300,
|
||||
fontSize: '0.8em',
|
||||
color: theme.colors.grey,
|
||||
minWidth: 'fit-content',
|
||||
fontWeight: 300,
|
||||
fontSize: '0.8em',
|
||||
color: theme.colors.grey,
|
||||
}));
|
||||
|
||||
export default function CollectionHeader({
|
||||
showButtons,
|
||||
showControls = true,
|
||||
openNavigationItem,
|
||||
openCollectionItem,
|
||||
showButtons,
|
||||
showControls = true,
|
||||
openNavigationItem,
|
||||
openCollectionItem,
|
||||
}: CollectionHeaderProps) {
|
||||
const { t } = useTranslation('common');
|
||||
const { activeCollection } = useActiveCollection();
|
||||
const { t } = useTranslation('common');
|
||||
const { activeCollection } = useActiveCollection();
|
||||
|
||||
if (!activeCollection) return <Fragment />;
|
||||
if (!activeCollection) return <Fragment />;
|
||||
|
||||
const { name, links, visibility } = activeCollection;
|
||||
return (
|
||||
<CollectionHeaderWrapper>
|
||||
<CollectionHeaderStyle>
|
||||
{showButtons && openNavigationItem && openNavigationItem}
|
||||
<CollectionName title={name}>
|
||||
<TextEllipsis>{name}</TextEllipsis>
|
||||
{links.length > 0 && <LinksCount> — {links.length}</LinksCount>}
|
||||
<VisibilityBadge
|
||||
label={t('collection.visibility')}
|
||||
visibility={visibility}
|
||||
/>
|
||||
</CollectionName>
|
||||
{showControls && (
|
||||
<CollectionControls collectionId={activeCollection.id} />
|
||||
)}
|
||||
{showButtons && openCollectionItem && openCollectionItem}
|
||||
</CollectionHeaderStyle>
|
||||
{activeCollection.description && <CollectionDescription />}
|
||||
</CollectionHeaderWrapper>
|
||||
);
|
||||
const { name, links, visibility } = activeCollection;
|
||||
return (
|
||||
<CollectionHeaderWrapper>
|
||||
<CollectionHeaderStyle>
|
||||
{showButtons && openNavigationItem && openNavigationItem}
|
||||
<CollectionName title={name}>
|
||||
<TextEllipsis>{name}</TextEllipsis>
|
||||
{links.length > 0 && <LinksCount> — {links.length}</LinksCount>}
|
||||
<VisibilityBadge
|
||||
label={t('collection.visibility')}
|
||||
visibility={visibility}
|
||||
/>
|
||||
</CollectionName>
|
||||
{showControls && (
|
||||
<CollectionControls collectionId={activeCollection.id} />
|
||||
)}
|
||||
{showButtons && openCollectionItem && openCollectionItem}
|
||||
</CollectionHeaderStyle>
|
||||
{activeCollection.description && <CollectionDescription />}
|
||||
</CollectionHeaderWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,48 +10,48 @@ import { appendCollectionId } from '~/lib/navigation';
|
||||
import { CollectionWithLinks } from '~/types/app';
|
||||
|
||||
const CollectionItemStyle = styled(Item, {
|
||||
shouldForwardProp: (propName) => propName !== 'isActive',
|
||||
shouldForwardProp: (propName) => propName !== 'isActive',
|
||||
})<{ isActive: boolean }>(({ theme, isActive }) => ({
|
||||
cursor: 'pointer',
|
||||
color: isActive ? theme.colors.primary : theme.colors.font,
|
||||
backgroundColor: theme.colors.secondary,
|
||||
cursor: 'pointer',
|
||||
color: isActive ? theme.colors.primary : theme.colors.font,
|
||||
backgroundColor: theme.colors.secondary,
|
||||
}));
|
||||
const CollectionItemLink = CollectionItemStyle.withComponent(Link);
|
||||
|
||||
const LinksCount = styled.div(({ theme }) => ({
|
||||
minWidth: 'fit-content',
|
||||
fontWeight: 300,
|
||||
fontSize: '0.9rem',
|
||||
color: theme.colors.grey,
|
||||
minWidth: 'fit-content',
|
||||
fontWeight: 300,
|
||||
fontSize: '0.9rem',
|
||||
color: theme.colors.grey,
|
||||
}));
|
||||
|
||||
export default function CollectionItem({
|
||||
collection,
|
||||
collection,
|
||||
}: {
|
||||
collection: CollectionWithLinks;
|
||||
collection: CollectionWithLinks;
|
||||
}) {
|
||||
const itemRef = useRef<HTMLDivElement>(null);
|
||||
const { activeCollection } = useActiveCollection();
|
||||
const isActiveCollection = collection.id === activeCollection?.id;
|
||||
const FolderIcon = isActiveCollection ? AiFillFolderOpen : AiOutlineFolder;
|
||||
const itemRef = useRef<HTMLDivElement>(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]);
|
||||
useEffect(() => {
|
||||
if (collection.id === activeCollection?.id) {
|
||||
itemRef.current?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||||
}
|
||||
}, [collection.id, activeCollection?.id]);
|
||||
|
||||
return (
|
||||
<CollectionItemLink
|
||||
href={appendCollectionId(route('dashboard').url, collection.id)}
|
||||
isActive={isActiveCollection}
|
||||
ref={itemRef}
|
||||
>
|
||||
<FolderIcon css={{ minWidth: '24px' }} size={24} />
|
||||
<TextEllipsis>{collection.name}</TextEllipsis>
|
||||
{collection.links.length > 0 && (
|
||||
<LinksCount>— {collection.links.length}</LinksCount>
|
||||
)}
|
||||
</CollectionItemLink>
|
||||
);
|
||||
return (
|
||||
<CollectionItemLink
|
||||
href={appendCollectionId(route('dashboard').url, collection.id)}
|
||||
isActive={isActiveCollection}
|
||||
ref={itemRef}
|
||||
>
|
||||
<FolderIcon css={{ minWidth: '24px' }} size={24} />
|
||||
<TextEllipsis>{collection.name}</TextEllipsis>
|
||||
{collection.links.length > 0 && (
|
||||
<LinksCount>— {collection.links.length}</LinksCount>
|
||||
)}
|
||||
</CollectionItemLink>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,76 +7,76 @@ import useCollections from '~/hooks/use_collections';
|
||||
import useShortcut from '~/hooks/use_shortcut';
|
||||
|
||||
const SideMenu = styled.nav(({ theme }) => ({
|
||||
height: '100%',
|
||||
width: '300px',
|
||||
backgroundColor: theme.colors.background,
|
||||
paddingLeft: '10px',
|
||||
marginLeft: '5px',
|
||||
borderLeft: `1px solid ${theme.colors.lightGrey}`,
|
||||
display: 'flex',
|
||||
gap: '.35em',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
width: '300px',
|
||||
backgroundColor: theme.colors.background,
|
||||
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,
|
||||
marginBlock: '0.35em',
|
||||
paddingInline: '15px',
|
||||
color: theme.colors.grey,
|
||||
marginBlock: '0.35em',
|
||||
paddingInline: '15px',
|
||||
}));
|
||||
|
||||
const CollectionListStyle = styled.div({
|
||||
padding: '1px',
|
||||
paddingRight: '5px',
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
gap: '.35em',
|
||||
flexDirection: 'column',
|
||||
overflow: 'auto',
|
||||
padding: '1px',
|
||||
paddingRight: '5px',
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
gap: '.35em',
|
||||
flexDirection: 'column',
|
||||
overflow: 'auto',
|
||||
});
|
||||
|
||||
export default function CollectionList() {
|
||||
const { t } = useTranslation('common');
|
||||
const { collections } = useCollections();
|
||||
const { activeCollection, setActiveCollection } = useActiveCollection();
|
||||
const { t } = useTranslation('common');
|
||||
const { collections } = useCollections();
|
||||
const { activeCollection, setActiveCollection } = useActiveCollection();
|
||||
|
||||
const goToPreviousCollection = () => {
|
||||
const currentCategoryIndex = collections.findIndex(
|
||||
({ id }) => id === activeCollection?.id
|
||||
);
|
||||
if (currentCategoryIndex === -1 || currentCategoryIndex === 0) return;
|
||||
const goToPreviousCollection = () => {
|
||||
const currentCategoryIndex = collections.findIndex(
|
||||
({ id }) => id === activeCollection?.id
|
||||
);
|
||||
if (currentCategoryIndex === -1 || currentCategoryIndex === 0) return;
|
||||
|
||||
setActiveCollection(collections[currentCategoryIndex - 1]);
|
||||
};
|
||||
setActiveCollection(collections[currentCategoryIndex - 1]);
|
||||
};
|
||||
|
||||
const goToNextCollection = () => {
|
||||
const currentCategoryIndex = collections.findIndex(
|
||||
({ id }) => id === activeCollection?.id
|
||||
);
|
||||
if (
|
||||
currentCategoryIndex === -1 ||
|
||||
currentCategoryIndex === collections.length - 1
|
||||
)
|
||||
return;
|
||||
const goToNextCollection = () => {
|
||||
const currentCategoryIndex = collections.findIndex(
|
||||
({ id }) => id === activeCollection?.id
|
||||
);
|
||||
if (
|
||||
currentCategoryIndex === -1 ||
|
||||
currentCategoryIndex === collections.length - 1
|
||||
)
|
||||
return;
|
||||
|
||||
setActiveCollection(collections[currentCategoryIndex + 1]);
|
||||
};
|
||||
setActiveCollection(collections[currentCategoryIndex + 1]);
|
||||
};
|
||||
|
||||
useShortcut('ARROW_UP', goToPreviousCollection);
|
||||
useShortcut('ARROW_DOWN', goToNextCollection);
|
||||
useShortcut('ARROW_UP', goToPreviousCollection);
|
||||
useShortcut('ARROW_DOWN', goToNextCollection);
|
||||
|
||||
return (
|
||||
<SideMenu>
|
||||
<CollectionListContainer>
|
||||
<CollectionLabel>
|
||||
{t('collection.collections', { count: collections.length })} •{' '}
|
||||
{collections.length}
|
||||
</CollectionLabel>
|
||||
<CollectionListStyle>
|
||||
{collections.map((collection) => (
|
||||
<CollectionItem collection={collection} key={collection.id} />
|
||||
))}
|
||||
</CollectionListStyle>
|
||||
</CollectionListContainer>
|
||||
</SideMenu>
|
||||
);
|
||||
return (
|
||||
<SideMenu>
|
||||
<CollectionListContainer>
|
||||
<CollectionLabel>
|
||||
{t('collection.collections', { count: collections.length })} •{' '}
|
||||
{collections.length}
|
||||
</CollectionLabel>
|
||||
<CollectionListStyle>
|
||||
{collections.map((collection) => (
|
||||
<CollectionItem collection={collection} key={collection.id} />
|
||||
))}
|
||||
</CollectionListStyle>
|
||||
</CollectionListContainer>
|
||||
</SideMenu>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
const CollectionListContainer = styled.div({
|
||||
height: '100%',
|
||||
minHeight: 0,
|
||||
paddingInline: '10px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
minHeight: 0,
|
||||
paddingInline: '10px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
});
|
||||
|
||||
export default CollectionListContainer;
|
||||
|
||||
Reference in New Issue
Block a user