mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-27 06:33:32 +03:00
feat(core): add favorite operation to all collection (#6428)
https://github.com/toeverything/AFFiNE/assets/102217452/d90553aa-6076-4ecc-996b-a8398991982a
This commit is contained in:
parent
381be8a982
commit
4624a4923d
@ -1,7 +1,8 @@
|
|||||||
import { cssVar } from '@toeverything/theme';
|
import { cssVar } from '@toeverything/theme';
|
||||||
import { createContainer, style } from '@vanilla-extract/css';
|
import { createContainer, style } from '@vanilla-extract/css';
|
||||||
|
|
||||||
import * as itemStyles from './docs/page-list-item.css';
|
import { root as collectionItemRoot } from './collections/collection-list-item.css';
|
||||||
|
import { root as pageItemRoot } from './docs/page-list-item.css';
|
||||||
export const listRootContainer = createContainer('list-root-container');
|
export const listRootContainer = createContainer('list-root-container');
|
||||||
export const pageListScrollContainer = style({
|
export const pageListScrollContainer = style({
|
||||||
width: '100%',
|
width: '100%',
|
||||||
@ -48,9 +49,10 @@ export const favoriteCell = style({
|
|||||||
flexShrink: 0,
|
flexShrink: 0,
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
selectors: {
|
selectors: {
|
||||||
[`&[data-favorite], ${itemStyles.root}:hover &`]: {
|
[`&[data-favorite], ${pageItemRoot}:hover &, ${collectionItemRoot}:hover &`]:
|
||||||
opacity: 1,
|
{
|
||||||
},
|
opacity: 1,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
export const clearLinkStyle = style({
|
export const clearLinkStyle = style({
|
||||||
|
@ -285,6 +285,10 @@ export const CollectionOperationCell = ({
|
|||||||
info,
|
info,
|
||||||
}: CollectionOperationCellProps) => {
|
}: CollectionOperationCellProps) => {
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
const favAdapter = useService(FavoriteItemsAdapter);
|
||||||
|
const favourite = useLiveData(
|
||||||
|
favAdapter.isFavorite$(collection.id, 'collection')
|
||||||
|
);
|
||||||
|
|
||||||
const { open: openEditCollectionModal, node: editModal } =
|
const { open: openEditCollectionModal, node: editModal } =
|
||||||
useEditCollection(config);
|
useEditCollection(config);
|
||||||
@ -322,10 +326,28 @@ export const CollectionOperationCell = ({
|
|||||||
return service.deleteCollection(info, collection.id);
|
return service.deleteCollection(info, collection.id);
|
||||||
}, [service, info, collection]);
|
}, [service, info, collection]);
|
||||||
|
|
||||||
|
const onToggleFavoriteCollection = useCallback(() => {
|
||||||
|
const status = favAdapter.isFavorite(collection.id, 'collection');
|
||||||
|
favAdapter.toggle(collection.id, 'collection');
|
||||||
|
toast(
|
||||||
|
status
|
||||||
|
? t['com.affine.toastMessage.removedFavorites']()
|
||||||
|
: t['com.affine.toastMessage.addedFavorites']()
|
||||||
|
);
|
||||||
|
}, [favAdapter, collection.id, t]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{editModal}
|
{editModal}
|
||||||
{editNameModal}
|
{editNameModal}
|
||||||
|
<ColWrapper
|
||||||
|
hideInSmallContainer
|
||||||
|
data-testid="page-list-item-favorite"
|
||||||
|
data-favorite={favourite ? true : undefined}
|
||||||
|
className={styles.favoriteCell}
|
||||||
|
>
|
||||||
|
<FavoriteTag onClick={onToggleFavoriteCollection} active={favourite} />
|
||||||
|
</ColWrapper>
|
||||||
<Tooltip content={t['com.affine.collection.menu.rename']()} side="top">
|
<Tooltip content={t['com.affine.collection.menu.rename']()} side="top">
|
||||||
<IconButton onClick={handleEditName}>
|
<IconButton onClick={handleEditName}>
|
||||||
<EditIcon />
|
<EditIcon />
|
||||||
@ -336,21 +358,40 @@ export const CollectionOperationCell = ({
|
|||||||
<FilterIcon />
|
<FilterIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
<ColWrapper alignment="start">
|
<ColWrapper alignment="start">
|
||||||
<Menu
|
<Menu
|
||||||
items={
|
items={
|
||||||
<MenuItem
|
<>
|
||||||
onClick={handleDelete}
|
<MenuItem
|
||||||
preFix={
|
onClick={onToggleFavoriteCollection}
|
||||||
<MenuIcon>
|
preFix={
|
||||||
<DeleteIcon />
|
<MenuIcon>
|
||||||
</MenuIcon>
|
{favourite ? (
|
||||||
}
|
<FavoritedIcon
|
||||||
type="danger"
|
style={{ color: 'var(--affine-primary-color)' }}
|
||||||
>
|
/>
|
||||||
{t['Delete']()}
|
) : (
|
||||||
</MenuItem>
|
<FavoriteIcon />
|
||||||
|
)}
|
||||||
|
</MenuIcon>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{favourite
|
||||||
|
? t['com.affine.favoritePageOperation.remove']()
|
||||||
|
: t['com.affine.favoritePageOperation.add']()}
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem
|
||||||
|
onClick={handleDelete}
|
||||||
|
preFix={
|
||||||
|
<MenuIcon>
|
||||||
|
<DeleteIcon />
|
||||||
|
</MenuIcon>
|
||||||
|
}
|
||||||
|
type="danger"
|
||||||
|
>
|
||||||
|
{t['Delete']()}
|
||||||
|
</MenuItem>
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
contentOptions={{
|
contentOptions={{
|
||||||
align: 'end',
|
align: 'end',
|
||||||
|
Loading…
Reference in New Issue
Block a user