From 04e8a48df7e9f415b70490bcf07ab1f213e40144 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 8 Apr 2025 22:30:44 +0800 Subject: [PATCH] feat: remove mark as read confirmation --- .../components/mark-all-button.tsx | 236 +++++------------- .../layouts/EntryListHeader.electron.tsx | 7 +- .../layouts/EntryListHeader.mobile.tsx | 7 +- locales/app/en.json | 1 + 4 files changed, 66 insertions(+), 185 deletions(-) diff --git a/apps/desktop/src/renderer/src/modules/entry-column/components/mark-all-button.tsx b/apps/desktop/src/renderer/src/modules/entry-column/components/mark-all-button.tsx index 49a1f8e7d..23a99fdcc 100644 --- a/apps/desktop/src/renderer/src/modules/entry-column/components/mark-all-button.tsx +++ b/apps/desktop/src/renderer/src/modules/entry-column/components/mark-all-button.tsx @@ -1,17 +1,12 @@ -import { useViewport } from "@follow/components/hooks/useViewport.js" -import { ActionButton, Button, IconButton } from "@follow/components/ui/button/index.js" +import { ActionButton, Button } from "@follow/components/ui/button/index.js" import { Kbd, KbdCombined } from "@follow/components/ui/kbd/Kbd.js" -import { RootPortal } from "@follow/components/ui/portal/index.jsx" import { useCountdown } from "@follow/hooks" -import { ELECTRON_BUILD } from "@follow/shared/constants" -import { cn, getOS } from "@follow/utils/utils" -import { AnimatePresence, m } from "framer-motion" +import { cn } from "@follow/utils/utils" import type { FC, ReactNode } from "react" -import { forwardRef, Fragment, useState } from "react" +import { forwardRef, useState } from "react" import { useHotkeys } from "react-hotkeys-hook" import { Trans, useTranslation } from "react-i18next" import { toast } from "sonner" -import { useOnClickOutside } from "usehooks-ts" import { HotKeyScopeMap } from "~/constants" import { shortcuts } from "~/constants/shortcuts" @@ -26,63 +21,49 @@ interface MarkAllButtonProps { shortcut?: boolean } -export const MarkAllReadWithOverlay = forwardRef< - HTMLButtonElement, - MarkAllButtonProps & { - containerRef: React.RefObject - } ->(({ className, which = "all", shortcut, containerRef }, ref) => { - const { t } = useTranslation() - const { t: commonT } = useTranslation("common") +export const MarkAllReadButton = forwardRef( + ({ className, which = "all", shortcut }, ref) => { + const { t } = useTranslation() + const { t: commonT } = useTranslation("common") - const [show, setShow] = useState(false) + const handleMarkAllAsRead = useMarkAllByRoute() - const handleMarkAllAsRead = useMarkAllByRoute() - - const [popoverRef, setPopoverRef] = useState(null) - useOnClickOutside({ current: popoverRef }, () => { - setShow(false) - }) - - useHotkeys( - shortcuts.entries.markAllAsRead.key, - () => { - setShow(false) - - let cancel = false - const undo = () => { - toast.dismiss(id) - if (cancel) return - cancel = true - } - const id = toast("", { - description: , - duration: 3000, - onAutoClose() { + useHotkeys( + shortcuts.entries.markAllAsRead.key, + () => { + let cancel = false + const undo = () => { + toast.dismiss(id) if (cancel) return - handleMarkAllAsRead() - }, - action: { - label: ( - - {t("mark_all_read_button.undo")} - - Meta+Z - - - ), - onClick: undo, - }, - }) - }, - { - preventDefault: true, - scopes: HotKeyScopeMap.Home, - }, - ) + cancel = true + } + const id = toast("", { + description: , + duration: 3000, + onAutoClose() { + if (cancel) return + handleMarkAllAsRead() + }, + action: { + label: ( + + {t("mark_all_read_button.undo")} + + Meta+Z + + + ), + onClick: undo, + }, + }) + }, + { + preventDefault: true, + scopes: HotKeyScopeMap.Home, + }, + ) - return ( - + return ( @@ -104,88 +85,14 @@ export const MarkAllReadWithOverlay = forwardRef< className={className} ref={ref} onClick={() => { - setShow(true) + handleMarkAllAsRead() }} > - - - {show && ( - - )} - - - ) -}) - -const Popup = ({ which, containerRef, setPopoverRef, setShow, handleMarkAllAsRead }) => { - const { t } = useTranslation() - const { t: commonT } = useTranslation("common") - const $parent = containerRef.current! - const rect = $parent.getBoundingClientRect() - const paddingLeft = $parent.offsetLeft - - // change popup's width when viewport changes. - useViewport((v) => v.w) - - // electron window has pt-[calc(var(--fo-window-padding-top)_-10px)] - const isElectronWindows = ELECTRON_BUILD && getOS() === "Windows" - return ( - - -
- - - - {commonT(`words.which.${which}` as any)}, - }} - /> - - -
- } - onClick={() => { - handleMarkAllAsRead() - setShow(false) - }} - > - {t("words.confirm")} - -
-
-
-
- ) -} + ) + }, +) const ConfirmMarkAllReadInfo = ({ undo }: { undo: () => any }) => { const { t } = useTranslation() @@ -235,47 +142,26 @@ export const FlatMarkAllReadButton: FC< className, )} - onMouseLeave={() => { - if (status === "confirm") { - setStatus("initial") - } - }} onClick={() => { - if (status === "confirm") { - handleMarkAll() - .then(() => setStatus("done")) - .catch(() => setStatus("initial")) - return - } - - setStatus("confirm") + handleMarkAll() + .then(() => setStatus("done")) + .catch(() => setStatus("initial")) }} > - - {status === "confirm" ? ( - + + + {status === "done" ? ( + t("mark_all_read_button.done") ) : ( - + {typeof which === "string" ? t.common(`words.which.${which}` as any) : which} + ), + }} + /> )} - - - {typeof which === "string" ? t.common(`words.which.${which}` as any) : which} - ), - }} - /> - - - {t("mark_all_read_button.confirm")} ) diff --git a/apps/desktop/src/renderer/src/modules/entry-column/layouts/EntryListHeader.electron.tsx b/apps/desktop/src/renderer/src/modules/entry-column/layouts/EntryListHeader.electron.tsx index e95f77e9c..7ae3e236d 100644 --- a/apps/desktop/src/renderer/src/modules/entry-column/layouts/EntryListHeader.electron.tsx +++ b/apps/desktop/src/renderer/src/modules/entry-column/layouts/EntryListHeader.electron.tsx @@ -7,7 +7,6 @@ import { useIsOnline } from "@follow/hooks" import { stopPropagation } from "@follow/utils/dom" import { cn, isBizId } from "@follow/utils/utils" import type { FC } from "react" -import * as React from "react" import { useTranslation } from "react-i18next" import { setGeneralSetting, useGeneralSettingKey } from "~/atoms/settings/general" @@ -20,7 +19,7 @@ import { EntryHeader } from "~/modules/entry-content/header" import { useRefreshFeedMutation } from "~/queries/feed" import { useFeedById, useFeedHeaderTitle } from "~/store/feed" -import { MarkAllReadWithOverlay } from "../components/mark-all-button" +import { MarkAllReadButton } from "../components/mark-all-button" import { AppendTaildingDivider, DailyReportButton, @@ -58,13 +57,11 @@ export const EntryListHeader: FC<{ const feed = useFeedById(feedId) - const containerRef = React.useRef(null) const titleStyleBasedView = ["pl-6", "pl-7", "pl-7", "pl-7", "px-5", "pl-6"] const feedColumnShow = useTimelineColumnShow() return (
)} - +
diff --git a/apps/desktop/src/renderer/src/modules/entry-column/layouts/EntryListHeader.mobile.tsx b/apps/desktop/src/renderer/src/modules/entry-column/layouts/EntryListHeader.mobile.tsx index 3a1264229..6e09e42a1 100644 --- a/apps/desktop/src/renderer/src/modules/entry-column/layouts/EntryListHeader.mobile.tsx +++ b/apps/desktop/src/renderer/src/modules/entry-column/layouts/EntryListHeader.mobile.tsx @@ -8,7 +8,6 @@ import { useIsOnline } from "@follow/hooks" import { stopPropagation } from "@follow/utils/dom" import { cn, isBizId } from "@follow/utils/utils" import type { FC } from "react" -import * as React from "react" import { useTranslation } from "react-i18next" import { setGeneralSetting, useGeneralSettingKey } from "~/atoms/settings/general" @@ -22,7 +21,7 @@ import { FeedColumnMobile } from "~/modules/app-layout/feed-column/mobile" import { useRefreshFeedMutation } from "~/queries/feed" import { useFeedById, useFeedHeaderTitle } from "~/store/feed" -import { MarkAllReadWithOverlay } from "../components/mark-all-button" +import { MarkAllReadButton } from "../components/mark-all-button" import type { EntryListHeaderProps } from "./EntryListHeader.shared" import { AppendTaildingDivider, @@ -61,11 +60,9 @@ export const EntryListHeader: FC = ({ refetch, isRefreshin const isList = !!listId const showQuickTimeline = useGeneralSettingKey("showQuickTimeline") - const containerRef = React.useRef(null) return (
= ({ refetch, isRefreshin )} - + )}
diff --git a/locales/app/en.json b/locales/app/en.json index 232f191c6..bd7e130e6 100644 --- a/locales/app/en.json +++ b/locales/app/en.json @@ -220,6 +220,7 @@ "mark_all_read_button.confirm": "Confirm", "mark_all_read_button.confirm_mark_all": "Mark as read?", "mark_all_read_button.confirm_mark_all_info": "Confirm mark all as read?", + "mark_all_read_button.done": "Marked", "mark_all_read_button.mark_all_as_read": "Mark all as read", "mark_all_read_button.mark_as_read": "Mark as read", "mark_all_read_button.undo": "Undo",