Files
commafeed/commafeed-client/src/components/content/FeedEntryFooter.tsx

110 lines
4.9 KiB
TypeScript
Raw Normal View History

import { t } from "@lingui/macro"
2022-10-27 14:32:23 +02:00
import { Checkbox, Group, Indicator, MultiSelect, Popover } from "@mantine/core"
import { useMediaQuery } from "@mantine/hooks"
2022-10-25 10:18:50 +02:00
import { Constants } from "app/constants"
import { markEntriesUpToEntry, markEntry, starEntry, tagEntry } from "app/slices/entries"
2022-08-19 12:41:33 +02:00
import { useAppDispatch, useAppSelector } from "app/store"
import { Entry } from "app/types"
import { ActionButton } from "components/ActionButtton"
2022-10-25 10:18:50 +02:00
import { useEffect, useState } from "react"
import { TbArrowBarToDown, TbExternalLink, TbShare, TbStar, TbStarOff, TbTag } from "react-icons/tb"
2022-08-19 12:41:33 +02:00
import { ShareButtons } from "./ShareButtons"
interface FeedEntryFooterProps {
entry: Entry
}
export function FeedEntryFooter(props: FeedEntryFooterProps) {
2022-10-25 10:18:50 +02:00
const [scrollPosition, setScrollPosition] = useState(0)
2022-08-19 12:41:33 +02:00
const sharingSettings = useAppSelector(state => state.user.settings?.sharingSettings)
2022-10-25 10:18:50 +02:00
const tags = useAppSelector(state => state.user.tags)
const mobile = !useMediaQuery(`(min-width: ${Constants.layout.mobileBreakpoint}px)`)
const dispatch = useAppDispatch()
2022-08-19 12:41:33 +02:00
const showSharingButtons =
sharingSettings && (Object.values(sharingSettings) as Array<typeof sharingSettings[keyof typeof sharingSettings]>).some(v => v)
const readStatusCheckboxClicked = () => dispatch(markEntry({ entry: props.entry, read: !props.entry.read }))
2022-10-25 10:18:50 +02:00
const onTagsChange = (values: string[]) =>
dispatch(
tagEntry({
entryId: +props.entry.id,
tags: values,
})
)
useEffect(() => {
const scrollArea = document.getElementById(Constants.dom.mainScrollAreaId)
const listener = () => setScrollPosition(scrollArea ? scrollArea.scrollTop : 0)
scrollArea?.addEventListener("scroll", listener)
return () => scrollArea?.removeEventListener("scroll", listener)
}, [])
return (
2022-08-24 09:08:10 +02:00
<Group position="apart">
<Group>
{props.entry.markable && (
<Checkbox
label={t`Keep unread`}
checked={!props.entry.read}
onChange={readStatusCheckboxClicked}
styles={{
label: { cursor: "pointer" },
input: { cursor: "pointer" },
}}
/>
)}
<ActionButton
icon={props.entry.starred ? <TbStarOff size={18} /> : <TbStar size={18} />}
label={props.entry.starred ? t`Unstar` : t`Star`}
onClick={() => dispatch(starEntry({ entry: props.entry, starred: !props.entry.starred }))}
/>
2022-08-24 09:08:10 +02:00
{showSharingButtons && (
<Popover withArrow withinPortal shadow="md" positionDependencies={[scrollPosition]} closeOnClickOutside={!mobile}>
2022-08-24 09:08:10 +02:00
<Popover.Target>
<ActionButton icon={<TbShare size={18} />} label={t`Share`} />
</Popover.Target>
<Popover.Dropdown>
<ShareButtons url={props.entry.url} description={props.entry.title} />
</Popover.Dropdown>
</Popover>
)}
2022-10-25 10:18:50 +02:00
{tags && (
<Popover withArrow withinPortal shadow="md" positionDependencies={[scrollPosition]} closeOnClickOutside={!mobile}>
2022-10-25 10:18:50 +02:00
<Popover.Target>
2022-10-27 14:32:23 +02:00
<Indicator label={props.entry.tags.length} showZero={false} dot={false} inline size={16}>
<ActionButton icon={<TbTag size={18} />} label={t`Tags`} />
</Indicator>
2022-10-25 10:18:50 +02:00
</Popover.Target>
<Popover.Dropdown>
<MultiSelect
data={tags}
placeholder="Tags"
searchable
creatable
2022-10-25 18:05:46 +02:00
autoFocus
2022-10-25 10:18:50 +02:00
getCreateLabel={query => t`Create tag: ${query}`}
value={props.entry.tags}
onChange={onTagsChange}
/>
</Popover.Dropdown>
</Popover>
)}
2022-08-24 09:08:10 +02:00
<a href={props.entry.url} target="_blank" rel="noreferrer">
<ActionButton icon={<TbExternalLink size={18} />} label={t`Open link`} />
</a>
</Group>
2022-08-19 10:34:04 +02:00
<ActionButton
2022-08-24 09:08:10 +02:00
icon={<TbArrowBarToDown size={18} />}
label={t`Mark as read up to here`}
onClick={() => dispatch(markEntriesUpToEntry(props.entry))}
2022-08-19 10:34:04 +02:00
/>
</Group>
)
}