fix: favorite button will not work (#1228)

This commit is contained in:
Himself65
2023-03-01 10:50:23 -06:00
committed by GitHub
parent e0481d29ad
commit f6a620e0ac
2 changed files with 25 additions and 5 deletions

View File

@@ -32,10 +32,14 @@ import {
StyledTitleLink, StyledTitleLink,
StyledTitleWrapper, StyledTitleWrapper,
} from './styles'; } from './styles';
const FavoriteTag = ({
pageMeta: { favorite, id }, export type FavoriteTagProps = {
}: {
pageMeta: PageMeta; pageMeta: PageMeta;
onClick: () => void;
};
const FavoriteTag: React.FC<FavoriteTagProps> = ({
pageMeta: { favorite },
onClick,
}) => { }) => {
const { theme } = useTheme(); const { theme } = useTheme();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -49,7 +53,7 @@ const FavoriteTag = ({
iconSize={[20, 20]} iconSize={[20, 20]}
onClick={e => { onClick={e => {
e.stopPropagation(); e.stopPropagation();
// toggleFavoritePage(id); onClick();
toast( toast(
favorite ? t('Removed from Favorites') : t('Added to Favorites') favorite ? t('Removed from Favorites') : t('Added to Favorites')
); );
@@ -142,7 +146,16 @@ export const PageList: React.FC<PageListProps> = ({
{pageMeta.title || t('Untitled')} {pageMeta.title || t('Untitled')}
</Content> </Content>
</StyledTitleLink> </StyledTitleLink>
{!isTrash && <FavoriteTag pageMeta={pageMeta} />} {!isTrash && (
<FavoriteTag
onClick={() => {
helper.setPageMeta(pageMeta.id, {
favorite: !pageMeta.favorite,
});
}}
pageMeta={pageMeta}
/>
)}
</StyledTitleWrapper> </StyledTitleWrapper>
</TableCell> </TableCell>
{matches && ( {matches && (

View File

@@ -48,5 +48,12 @@ test.describe('Local first favorite items ui', () => {
expect( expect(
page.getByRole('cell', { name: 'this is a new page to favorite' }) page.getByRole('cell', { name: 'this is a new page to favorite' })
).not.toBeUndefined(); ).not.toBeUndefined();
await page.getByRole('cell').getByRole('button').nth(0).click();
expect(
await page
.getByText('Click Add to Favorites and the page will appear here.')
.isVisible()
).toBe(true);
}); });
}); });