import { msg } from "@lingui/macro" import { useLingui } from "@lingui/react" import { Box, Center, CloseButton, Divider, Group, Indicator, Popover, TextInput } from "@mantine/core" import { useForm } from "@mantine/form" import { reloadEntries, search, selectNextEntry, selectPreviousEntry } from "app/entries/thunks" import { useAppDispatch, useAppSelector } from "app/store" import { changeReadingMode, changeReadingOrder } from "app/user/thunks" import { ActionButton } from "components/ActionButton" import { Loader } from "components/Loader" import { useActionButton } from "hooks/useActionButton" import { useBrowserExtension } from "hooks/useBrowserExtension" import { useMobile } from "hooks/useMobile" import { useEffect } from "react" import { TbArrowDown, TbArrowUp, TbExternalLink, TbEye, TbEyeOff, TbRefresh, TbSearch, TbSettings, TbSortAscending, TbSortDescending, TbUser, } from "react-icons/tb" import { MarkAllAsReadButton } from "./MarkAllAsReadButton" import { ProfileMenu } from "./ProfileMenu" function HeaderDivider() { return } function HeaderToolbar(props: { children: React.ReactNode }) { const { spacing } = useActionButton() const mobile = useMobile("480px") return mobile ? ( // on mobile use all available width {props.children} ) : ( {props.children} ) } const iconSize = 18 export function Header() { const settings = useAppSelector(state => state.user.settings) const profile = useAppSelector(state => state.user.profile) const searchFromStore = useAppSelector(state => state.entries.search) const { isBrowserExtensionPopup, openSettingsPage, openAppInNewTab } = useBrowserExtension() const dispatch = useAppDispatch() const { _ } = useLingui() const searchForm = useForm<{ search: string }>({ validate: { search: value => (value.length > 0 && value.length < 3 ? _(msg`Search requires at least 3 characters`) : null), }, }) const { setValues } = searchForm useEffect(() => { setValues({ search: searchFromStore, }) }, [setValues, searchFromStore]) if (!settings) return return (
} label={msg`Previous`} onClick={async () => await dispatch( selectPreviousEntry({ expand: true, markAsRead: true, scrollToEntry: true, }) ) } /> } label={msg`Next`} onClick={async () => await dispatch( selectNextEntry({ expand: true, markAsRead: true, scrollToEntry: true, }) ) } /> } label={msg`Refresh`} onClick={async () => await dispatch(reloadEntries())} /> : } label={settings.readingMode === "all" ? msg`All` : msg`Unread`} onClick={async () => await dispatch(changeReadingMode(settings.readingMode === "all" ? "unread" : "all"))} /> : } label={settings.readingOrder === "asc" ? msg`Asc` : msg`Desc`} onClick={async () => await dispatch(changeReadingOrder(settings.readingOrder === "asc" ? "desc" : "asc"))} /> } label={msg`Search`} />
await dispatch(search(values.search)))}> } rightSection={ await (searchFromStore && dispatch(search("")))} />} autoFocus />
} label={profile?.name} />} /> {isBrowserExtensionPopup && ( <> } label={msg`Extension options`} onClick={() => openSettingsPage()} /> } label={msg`Open CommaFeed`} onClick={() => openAppInNewTab()} /> )}
) }