omnivore/packages/web/components/patterns/CardMenu.tsx

95 lines
2.4 KiB
TypeScript
Raw Normal View History

2022-02-11 17:24:33 +00:00
import type { ReactNode } from 'react'
import { Dropdown, DropdownOption } from '../elements/DropdownElements'
import { LibraryItemNode } from '../../lib/networking/queries/useGetLibraryItemsQuery'
import { UserBasicData } from '../../lib/networking/queries/useGetViewerQuery'
export type CardMenuDropdownAction =
| 'mark-read'
| 'mark-unread'
| 'archive'
| 'unarchive'
| 'delete'
| 'set-labels'
| 'open-notebook'
| 'showOriginal'
2022-06-01 20:17:34 +00:00
| 'unsubscribe'
2022-06-07 08:40:29 +00:00
| 'editTitle'
2022-02-11 17:24:33 +00:00
type CardMenuProps = {
item: LibraryItemNode
viewer: UserBasicData
triggerElement: ReactNode
actionHandler: (action: CardMenuDropdownAction) => void
onOpenChange?: (open: boolean) => void
2022-02-11 17:24:33 +00:00
}
export function CardMenu(props: CardMenuProps): JSX.Element {
return (
<Dropdown
triggerElement={props.triggerElement}
onOpenChange={props.onOpenChange}
>
2022-02-11 17:24:33 +00:00
{!props.item.isArchived ? (
<DropdownOption
onSelect={() => props.actionHandler('archive')}
title="Archive"
/>
) : (
<DropdownOption
onSelect={() => props.actionHandler('unarchive')}
title="Unarchive"
/>
)}
<DropdownOption
onSelect={() => {
props.actionHandler('set-labels')
}}
2023-11-01 07:16:05 +00:00
title="Set labels"
/>
<DropdownOption
onSelect={() => {
props.actionHandler('open-notebook')
}}
2023-11-01 07:16:05 +00:00
title="Open notebook"
/>
<DropdownOption
onSelect={() => props.actionHandler('showOriginal')}
2023-11-01 07:16:05 +00:00
title="Open original"
/>
2022-06-07 08:40:29 +00:00
<DropdownOption
onSelect={() => props.actionHandler('editTitle')}
2024-02-29 13:43:56 +00:00
title="Edit info"
2022-06-07 08:40:29 +00:00
/>
2022-02-11 17:24:33 +00:00
{props.item.readingProgressPercent < 98 ? (
<DropdownOption
onSelect={() => {
props.actionHandler('mark-read')
}}
2023-11-01 07:16:05 +00:00
title="Mark read"
2022-02-11 17:24:33 +00:00
/>
) : (
<DropdownOption
onSelect={() => {
props.actionHandler('mark-unread')
}}
2023-11-01 07:16:05 +00:00
title="Mark unread"
2022-02-11 17:24:33 +00:00
/>
)}
<DropdownOption
onSelect={() => {
props.actionHandler('delete')
}}
title="Remove"
2022-02-11 17:24:33 +00:00
/>
{/* {!!props.item.subscription && (
2022-06-01 20:17:34 +00:00
<DropdownOption
onSelect={() => {
props.actionHandler('unsubscribe')
}}
title="Unsubscribe"
/>
)} */}
2022-02-11 17:24:33 +00:00
</Dropdown>
)
}