mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-11 00:33:04 +00:00
refactor: use tabs instead of spaces
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
const FavoriteListContainer = styled.div({
|
||||
height: '100%',
|
||||
minHeight: 0,
|
||||
paddingInline: '10px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
minHeight: 0,
|
||||
paddingInline: '10px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
});
|
||||
|
||||
export default FavoriteListContainer;
|
||||
|
||||
@@ -9,52 +9,52 @@ import { onFavorite } from '~/lib/favorite';
|
||||
import { Link } from '~/types/app';
|
||||
|
||||
const StarItem = styled(DropdownItemButton)(({ theme }) => ({
|
||||
color: theme.colors.yellow,
|
||||
color: theme.colors.yellow,
|
||||
}));
|
||||
|
||||
export default function FavoriteDropdownItem({ link }: { link: Link }) {
|
||||
const { collections, setCollections } = useCollections();
|
||||
const { setActiveCollection } = useActiveCollection();
|
||||
const { t } = useTranslation();
|
||||
const { collections, setCollections } = useCollections();
|
||||
const { setActiveCollection } = useActiveCollection();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const toggleFavorite = useCallback(
|
||||
(linkId: Link['id']) => {
|
||||
let linkIndex = 0;
|
||||
const collectionIndex = collections.findIndex(({ links }) => {
|
||||
const lIndex = links.findIndex((l) => l.id === linkId);
|
||||
if (lIndex !== -1) {
|
||||
linkIndex = lIndex;
|
||||
}
|
||||
return lIndex !== -1;
|
||||
});
|
||||
const toggleFavorite = useCallback(
|
||||
(linkId: Link['id']) => {
|
||||
let linkIndex = 0;
|
||||
const collectionIndex = collections.findIndex(({ links }) => {
|
||||
const lIndex = links.findIndex((l) => l.id === linkId);
|
||||
if (lIndex !== -1) {
|
||||
linkIndex = lIndex;
|
||||
}
|
||||
return lIndex !== -1;
|
||||
});
|
||||
|
||||
const collectionLink = collections[collectionIndex].links[linkIndex];
|
||||
const collectionsCopy = [...collections];
|
||||
collectionsCopy[collectionIndex].links[linkIndex] = {
|
||||
...collectionLink,
|
||||
favorite: !collectionLink.favorite,
|
||||
};
|
||||
const collectionLink = collections[collectionIndex].links[linkIndex];
|
||||
const collectionsCopy = [...collections];
|
||||
collectionsCopy[collectionIndex].links[linkIndex] = {
|
||||
...collectionLink,
|
||||
favorite: !collectionLink.favorite,
|
||||
};
|
||||
|
||||
setCollections(collectionsCopy);
|
||||
setActiveCollection(collectionsCopy[collectionIndex]);
|
||||
},
|
||||
[collections, setCollections]
|
||||
);
|
||||
setCollections(collectionsCopy);
|
||||
setActiveCollection(collectionsCopy[collectionIndex]);
|
||||
},
|
||||
[collections, setCollections]
|
||||
);
|
||||
|
||||
const onFavoriteCallback = () => toggleFavorite(link.id);
|
||||
return (
|
||||
<StarItem
|
||||
onClick={() => onFavorite(link.id, !link.favorite, onFavoriteCallback)}
|
||||
>
|
||||
{!link.favorite ? (
|
||||
<>
|
||||
<AiFillStar /> {t('add-favorite')}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<AiOutlineStar /> {t('remove-favorite')}
|
||||
</>
|
||||
)}
|
||||
</StarItem>
|
||||
);
|
||||
const onFavoriteCallback = () => toggleFavorite(link.id);
|
||||
return (
|
||||
<StarItem
|
||||
onClick={() => onFavorite(link.id, !link.favorite, onFavoriteCallback)}
|
||||
>
|
||||
{!link.favorite ? (
|
||||
<>
|
||||
<AiFillStar /> {t('add-favorite')}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<AiOutlineStar /> {t('remove-favorite')}
|
||||
</>
|
||||
)}
|
||||
</StarItem>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,54 +16,54 @@ import { appendCollectionId, appendLinkId } from '~/lib/navigation';
|
||||
import { LinkWithCollection } from '~/types/app';
|
||||
|
||||
const FavoriteItemStyle = styled(ItemExternalLink)(({ theme }) => ({
|
||||
height: 'auto',
|
||||
backgroundColor: theme.colors.secondary,
|
||||
height: 'auto',
|
||||
backgroundColor: theme.colors.secondary,
|
||||
}));
|
||||
|
||||
const FavoriteDropdown = styled(Dropdown)(({ theme }) => ({
|
||||
backgroundColor: theme.colors.secondary,
|
||||
backgroundColor: theme.colors.secondary,
|
||||
}));
|
||||
|
||||
const FavoriteContainer = styled.div({
|
||||
flex: 1,
|
||||
lineHeight: '1.1rem',
|
||||
flex: 1,
|
||||
lineHeight: '1.1rem',
|
||||
});
|
||||
|
||||
export default function FavoriteItem({ link }: { link: LinkWithCollection }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<FavoriteItemStyle href={link.url}>
|
||||
<LinkFavicon url={link.url} size={24} />
|
||||
<FavoriteContainer>
|
||||
<TextEllipsis>{link.name}</TextEllipsis>
|
||||
<Legend>{link.collection.name}</Legend>
|
||||
</FavoriteContainer>
|
||||
<FavoriteDropdown
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}}
|
||||
label={<BsThreeDotsVertical />}
|
||||
svgSize={18}
|
||||
>
|
||||
<DropdownItemLink
|
||||
href={appendCollectionId(route('dashboard').url, link.collection.id)}
|
||||
>
|
||||
<FaRegEye /> {t('go-to-collection')}
|
||||
</DropdownItemLink>
|
||||
<FavoriteDropdownItem link={link} />
|
||||
<DropdownItemLink
|
||||
href={appendLinkId(route('link.edit-form').url, link.id)}
|
||||
>
|
||||
<GoPencil /> {t('link.edit')}
|
||||
</DropdownItemLink>
|
||||
<DropdownItemLink
|
||||
href={appendLinkId(route('link.delete-form').url, link.id)}
|
||||
danger
|
||||
>
|
||||
<IoTrashOutline /> {t('link.delete')}
|
||||
</DropdownItemLink>
|
||||
</FavoriteDropdown>
|
||||
</FavoriteItemStyle>
|
||||
);
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<FavoriteItemStyle href={link.url}>
|
||||
<LinkFavicon url={link.url} size={24} />
|
||||
<FavoriteContainer>
|
||||
<TextEllipsis>{link.name}</TextEllipsis>
|
||||
<Legend>{link.collection.name}</Legend>
|
||||
</FavoriteContainer>
|
||||
<FavoriteDropdown
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}}
|
||||
label={<BsThreeDotsVertical />}
|
||||
svgSize={18}
|
||||
>
|
||||
<DropdownItemLink
|
||||
href={appendCollectionId(route('dashboard').url, link.collection.id)}
|
||||
>
|
||||
<FaRegEye /> {t('go-to-collection')}
|
||||
</DropdownItemLink>
|
||||
<FavoriteDropdownItem link={link} />
|
||||
<DropdownItemLink
|
||||
href={appendLinkId(route('link.edit-form').url, link.id)}
|
||||
>
|
||||
<GoPencil /> {t('link.edit')}
|
||||
</DropdownItemLink>
|
||||
<DropdownItemLink
|
||||
href={appendLinkId(route('link.delete-form').url, link.id)}
|
||||
danger
|
||||
>
|
||||
<IoTrashOutline /> {t('link.delete')}
|
||||
</DropdownItemLink>
|
||||
</FavoriteDropdown>
|
||||
</FavoriteItemStyle>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,47 +5,47 @@ import FavoriteItem from '~/components/dashboard/side_nav/favorite/favorite_item
|
||||
import useFavorites from '~/hooks/use_favorites';
|
||||
|
||||
const FavoriteLabel = styled.p(({ theme }) => ({
|
||||
color: theme.colors.grey,
|
||||
marginBlock: '0.35em',
|
||||
paddingInline: '15px',
|
||||
color: theme.colors.grey,
|
||||
marginBlock: '0.35em',
|
||||
paddingInline: '15px',
|
||||
}));
|
||||
|
||||
const NoFavorite = () => {
|
||||
const { t } = useTranslation('common');
|
||||
return (
|
||||
<FavoriteLabel css={{ textAlign: 'center' }}>
|
||||
{t('favorites-appears-here')}
|
||||
</FavoriteLabel>
|
||||
);
|
||||
const { t } = useTranslation('common');
|
||||
return (
|
||||
<FavoriteLabel css={{ textAlign: 'center' }}>
|
||||
{t('favorites-appears-here')}
|
||||
</FavoriteLabel>
|
||||
);
|
||||
};
|
||||
|
||||
const FavoriteListStyle = 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 FavoriteList() {
|
||||
const { t } = useTranslation('common');
|
||||
const { favorites } = useFavorites();
|
||||
if (favorites.length === 0) {
|
||||
return <NoFavorite key="no-favorite" />;
|
||||
}
|
||||
const { t } = useTranslation('common');
|
||||
const { favorites } = useFavorites();
|
||||
if (favorites.length === 0) {
|
||||
return <NoFavorite key="no-favorite" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<FavoriteListContainer>
|
||||
<FavoriteLabel>
|
||||
{t('favorite')} • {favorites.length}
|
||||
</FavoriteLabel>
|
||||
<FavoriteListStyle>
|
||||
{favorites.map((link) => (
|
||||
<FavoriteItem link={link} key={link.id} />
|
||||
))}
|
||||
</FavoriteListStyle>
|
||||
</FavoriteListContainer>
|
||||
);
|
||||
return (
|
||||
<FavoriteListContainer>
|
||||
<FavoriteLabel>
|
||||
{t('favorite')} • {favorites.length}
|
||||
</FavoriteLabel>
|
||||
<FavoriteListStyle>
|
||||
{favorites.map((link) => (
|
||||
<FavoriteItem link={link} key={link.id} />
|
||||
))}
|
||||
</FavoriteListStyle>
|
||||
</FavoriteListContainer>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,27 +4,27 @@ import ExternalLink from '~/components/common/external_link';
|
||||
import { rgba } from '~/lib/color';
|
||||
|
||||
export const Item = styled.div(({ theme }) => ({
|
||||
userSelect: 'none',
|
||||
height: '40px',
|
||||
width: '100%',
|
||||
color: theme.colors.font,
|
||||
backgroundColor: theme.colors.background,
|
||||
padding: '8px 12px',
|
||||
borderRadius: theme.border.radius,
|
||||
display: 'flex',
|
||||
gap: '.75em',
|
||||
alignItems: 'center',
|
||||
userSelect: 'none',
|
||||
height: '40px',
|
||||
width: '100%',
|
||||
color: theme.colors.font,
|
||||
backgroundColor: theme.colors.background,
|
||||
padding: '8px 12px',
|
||||
borderRadius: theme.border.radius,
|
||||
display: 'flex',
|
||||
gap: '.75em',
|
||||
alignItems: 'center',
|
||||
|
||||
'& > svg': {
|
||||
height: '24px',
|
||||
width: '24px',
|
||||
},
|
||||
'& > svg': {
|
||||
height: '24px',
|
||||
width: '24px',
|
||||
},
|
||||
|
||||
// Disable hover effect for UserCard
|
||||
'&:hover:not(.disable-hover)': {
|
||||
cursor: 'pointer',
|
||||
backgroundColor: rgba(theme.colors.font, 0.1),
|
||||
},
|
||||
// Disable hover effect for UserCard
|
||||
'&:hover:not(.disable-hover)': {
|
||||
cursor: 'pointer',
|
||||
backgroundColor: rgba(theme.colors.font, 0.1),
|
||||
},
|
||||
}));
|
||||
|
||||
export const ItemLink = Item.withComponent(Link);
|
||||
|
||||
@@ -14,67 +14,67 @@ import { rgba } from '~/lib/color';
|
||||
import { appendCollectionId } from '~/lib/navigation';
|
||||
|
||||
const SideMenu = styled.nav(({ theme }) => ({
|
||||
height: '100%',
|
||||
width: '300px',
|
||||
backgroundColor: theme.colors.background,
|
||||
borderRight: `1px solid ${theme.colors.lightGrey}`,
|
||||
marginRight: '5px',
|
||||
display: 'flex',
|
||||
gap: '.35em',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
width: '300px',
|
||||
backgroundColor: theme.colors.background,
|
||||
borderRight: `1px solid ${theme.colors.lightGrey}`,
|
||||
marginRight: '5px',
|
||||
display: 'flex',
|
||||
gap: '.35em',
|
||||
flexDirection: 'column',
|
||||
}));
|
||||
|
||||
const AdminButton = styled(ItemLink)(({ theme }) => ({
|
||||
color: theme.colors.lightRed,
|
||||
'&:hover': {
|
||||
backgroundColor: `${rgba(theme.colors.lightRed, 0.1)}!important`,
|
||||
},
|
||||
color: theme.colors.lightRed,
|
||||
'&:hover': {
|
||||
backgroundColor: `${rgba(theme.colors.lightRed, 0.1)}!important`,
|
||||
},
|
||||
}));
|
||||
|
||||
const SettingsButton = styled(Item)(({ theme }) => ({
|
||||
color: theme.colors.grey,
|
||||
'&:hover': {
|
||||
backgroundColor: `${rgba(theme.colors.grey, 0.1)}!important`,
|
||||
},
|
||||
color: theme.colors.grey,
|
||||
'&:hover': {
|
||||
backgroundColor: `${rgba(theme.colors.grey, 0.1)}!important`,
|
||||
},
|
||||
}));
|
||||
|
||||
const AddButton = styled(ItemLink)(({ theme }) => ({
|
||||
color: theme.colors.primary,
|
||||
'&:hover': {
|
||||
backgroundColor: `${rgba(theme.colors.primary, 0.1)}!important`,
|
||||
},
|
||||
color: theme.colors.primary,
|
||||
'&:hover': {
|
||||
backgroundColor: `${rgba(theme.colors.primary, 0.1)}!important`,
|
||||
},
|
||||
}));
|
||||
|
||||
const SearchButton = AddButton.withComponent(Item);
|
||||
|
||||
export default function SideNavigation() {
|
||||
const { user } = useUser();
|
||||
const { t } = useTranslation('common');
|
||||
const { activeCollection } = useActiveCollection();
|
||||
return (
|
||||
<SideMenu>
|
||||
<div css={{ paddingInline: '10px' }}>
|
||||
<UserCard />
|
||||
{user!.isAdmin && (
|
||||
<AdminButton href={route('admin.dashboard').url}>
|
||||
<IoShieldHalfSharp /> {t('admin')}
|
||||
</AdminButton>
|
||||
)}
|
||||
<ModalSettings openItem={SettingsButton} />
|
||||
<SearchModal openItem={SearchButton} />
|
||||
<AddButton
|
||||
href={appendCollectionId(
|
||||
route('link.create-form').url,
|
||||
activeCollection?.id
|
||||
)}
|
||||
>
|
||||
<IoAdd /> {t('link.create')}
|
||||
</AddButton>
|
||||
<AddButton href={route('collection.create-form').url}>
|
||||
<AiOutlineFolderAdd /> {t('collection.create')}
|
||||
</AddButton>
|
||||
</div>
|
||||
<FavoriteList />
|
||||
</SideMenu>
|
||||
);
|
||||
const { user } = useUser();
|
||||
const { t } = useTranslation('common');
|
||||
const { activeCollection } = useActiveCollection();
|
||||
return (
|
||||
<SideMenu>
|
||||
<div css={{ paddingInline: '10px' }}>
|
||||
<UserCard />
|
||||
{user!.isAdmin && (
|
||||
<AdminButton href={route('admin.dashboard').url}>
|
||||
<IoShieldHalfSharp /> {t('admin')}
|
||||
</AdminButton>
|
||||
)}
|
||||
<ModalSettings openItem={SettingsButton} />
|
||||
<SearchModal openItem={SearchButton} />
|
||||
<AddButton
|
||||
href={appendCollectionId(
|
||||
route('link.create-form').url,
|
||||
activeCollection?.id
|
||||
)}
|
||||
>
|
||||
<IoAdd /> {t('link.create')}
|
||||
</AddButton>
|
||||
<AddButton href={route('collection.create-form').url}>
|
||||
<AiOutlineFolderAdd /> {t('collection.create')}
|
||||
</AddButton>
|
||||
</div>
|
||||
<FavoriteList />
|
||||
</SideMenu>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,19 +3,19 @@ import { Item } from '~/components/dashboard/side_nav/nav_item';
|
||||
import useUser from '~/hooks/use_user';
|
||||
|
||||
export default function UserCard() {
|
||||
const { user, isAuthenticated } = useUser();
|
||||
const altImage = `${user?.fullname}'s avatar`;
|
||||
return (
|
||||
isAuthenticated && (
|
||||
<Item className="disable-hover">
|
||||
<RoundedImage
|
||||
src={user.avatarUrl}
|
||||
width={24}
|
||||
alt={altImage}
|
||||
referrerPolicy="no-referrer"
|
||||
/>
|
||||
{user.fullname}
|
||||
</Item>
|
||||
)
|
||||
);
|
||||
const { user, isAuthenticated } = useUser();
|
||||
const altImage = `${user?.fullname}'s avatar`;
|
||||
return (
|
||||
isAuthenticated && (
|
||||
<Item className="disable-hover">
|
||||
<RoundedImage
|
||||
src={user.avatarUrl}
|
||||
width={24}
|
||||
alt={altImage}
|
||||
referrerPolicy="no-referrer"
|
||||
/>
|
||||
{user.fullname}
|
||||
</Item>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user