Merge pull request #710 from omnivore-app/OMN-657

[OMN-657]: Archive button should change to unarchive on web if an article has already been archived
This commit is contained in:
Jackson Harper 2022-06-09 12:45:53 -07:00 committed by GitHub
commit edadb9aafa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 9 deletions

View file

@ -1,5 +1,5 @@
import { Separator } from "@radix-ui/react-separator"
import { ArchiveBox, DotsThree, HighlighterCircle, TagSimple, TextAa } from "phosphor-react"
import { ArchiveBox, DotsThree, HighlighterCircle, TagSimple, TextAa, Tray } from "phosphor-react"
import { ArticleAttributes } from "../../../lib/networking/queries/useGetArticleQuery"
import { Button } from "../../elements/Button"
import { Dropdown } from "../../elements/DropdownElements"
@ -150,14 +150,38 @@ export function ArticleActionsMenu(props: ArticleActionsMenuProps): JSX.Element
<MenuSeparator layout={props.layout} />
<Button style='articleActionIcon' onClick={() => props.articleActionHandler('archive')}>
<TooltipWrapped
tooltipContent="Archive"
tooltipSide={props.layout == 'side' ? 'right' : 'bottom'}
>
<ArchiveBox size={24} color={theme.colors.readerFont.toString()} />
</TooltipWrapped>
</Button>
{!props.article?.isArchived ? (
<Button
style="articleActionIcon"
onClick={() => props.articleActionHandler('archive')}
>
<TooltipWrapped
tooltipContent="Archive"
tooltipSide={props.layout == 'side' ? 'right' : 'bottom'}
>
<ArchiveBox
size={24}
color={theme.colors.readerFont.toString()}
/>
</TooltipWrapped>
</Button>
) : (
<Button
style="articleActionIcon"
onClick={() => props.articleActionHandler('unarchive')}
>
<TooltipWrapped
tooltipContent="Unarchive"
tooltipSide={props.layout == 'side' ? 'right' : 'bottom'}
>
<Tray
size={24}
color={theme.colors.readerFont.toString()}
/>
</TooltipWrapped>
</Button>
)}
{/* <MenuSeparator layout={props.layout} />
<Button style='articleActionIcon'>

View file

@ -40,6 +40,7 @@ export type ArticleAttributes = {
author?: string
image?: string
savedAt: string
isArchived: boolean
createdAt: string
publishedAt?: string
description?: string

View file

@ -62,6 +62,28 @@ export default function Home(): JSX.Element {
const actionHandler = useCallback(async(action: string, arg?: unknown) => {
switch (action) {
case 'unarchive':
if (article) {
removeItemFromCache(cache, mutate, article.id)
setLinkArchivedMutation({
linkId: article.id,
archived: false,
}).then((res) => {
if (res) {
showSuccessToast('Link unarchived', {
position: 'bottom-right',
})
} else {
showErrorToast('Error unarchiving link', {
position: 'bottom-right',
})
}
})
router.push(`/home`)
}
break
case 'archive':
if (article) {
removeItemFromCache(cache, mutate, article.id)