feat: add fav button (#4159)

Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
Peng Xiao
2023-09-05 01:14:02 +08:00
committed by GitHub
parent 6609f712e7
commit d57f995e87
4 changed files with 54 additions and 3 deletions

View File

@@ -0,0 +1,30 @@
import { PlusIcon } from '@blocksuite/icons';
import type { Workspace } from '@blocksuite/store';
import { IconButton } from '@toeverything/components/button';
import { usePageMetaHelper } from '@toeverything/hooks/use-block-suite-page-meta';
import { useCallback } from 'react';
import { usePageHelper } from '../../../blocksuite/block-suite-page-list/utils';
type AddFavouriteButtonProps = {
workspace: Workspace;
};
export const AddFavouriteButton = ({ workspace }: AddFavouriteButtonProps) => {
const { createPage } = usePageHelper(workspace);
const { setPageMeta } = usePageMetaHelper(workspace);
const handleAddFavorite = useCallback(async () => {
const id = createPage();
setPageMeta(id, { favorite: true });
}, [createPage, setPageMeta]);
return (
<IconButton
data-testid="slider-bar-add-favorite-button"
onClick={handleAddFavorite}
size="small"
>
<PlusIcon />
</IconButton>
);
};