From 442f575bbb43e765f597794091f85ccaa5cee026 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 21 Apr 2025 17:36:33 +0800 Subject: [PATCH] feat(desktop): useIsInMASReview --- .../src/renderer/src/atoms/server-configs.ts | 6 + .../renderer/src/hooks/biz/useFeedActions.tsx | 6 +- apps/desktop/src/renderer/src/lib/utils.ts | 5 - .../src/modules/command/commands/entry.tsx | 471 +++++++++--------- .../components/SupportCreator.tsx | 6 +- 5 files changed, 253 insertions(+), 241 deletions(-) diff --git a/apps/desktop/src/renderer/src/atoms/server-configs.ts b/apps/desktop/src/renderer/src/atoms/server-configs.ts index 02eac3b64..bb1fac38b 100644 --- a/apps/desktop/src/renderer/src/atoms/server-configs.ts +++ b/apps/desktop/src/renderer/src/atoms/server-configs.ts @@ -2,7 +2,13 @@ import type { ServerConfigs } from "@follow/models/types" import { atom } from "jotai" import { createAtomHooks } from "~/lib/jotai" +import { isInMAS } from "~/lib/utils" export const [, , useServerConfigs, , getServerConfigs, setServerConfigs] = createAtomHooks( atom>(null), ) + +export const useIsInMASReview = () => { + const serverConfigs = useServerConfigs() + return isInMAS() && serverConfigs?.MAS_IN_REVIEW +} diff --git a/apps/desktop/src/renderer/src/hooks/biz/useFeedActions.tsx b/apps/desktop/src/renderer/src/hooks/biz/useFeedActions.tsx index e49c84d94..8e3182b25 100644 --- a/apps/desktop/src/renderer/src/hooks/biz/useFeedActions.tsx +++ b/apps/desktop/src/renderer/src/hooks/biz/useFeedActions.tsx @@ -9,11 +9,11 @@ import { useTranslation } from "react-i18next" import { toast } from "sonner" import type { FollowMenuItem, MenuItemInput } from "~/atoms/context-menu" +import { useIsInMASReview } from "~/atoms/server-configs" import { whoami } from "~/atoms/user" import { useModalStack } from "~/components/ui/modal/stacked/hooks" import { apiClient } from "~/lib/api-fetch" import { UrlBuilder } from "~/lib/url-builder" -import { isInMASReview } from "~/lib/utils" import { useBoostModal } from "~/modules/boost/hooks" import { useFeedClaimModal } from "~/modules/claim" import { FeedForm } from "~/modules/discover/feed-form" @@ -103,6 +103,8 @@ export const useFeedActions = ({ const isMultipleSelection = feedIds && feedIds.length > 1 && feedIds.includes(feedId) + const isInMASReview = useIsInMASReview() + const items = useMemo(() => { const related = feed || inbox if (!related) return [] @@ -148,7 +150,7 @@ export const useFeedActions = ({ }, ] : []), - ...(isInMASReview() + ...(isInMASReview ? [] : [ { diff --git a/apps/desktop/src/renderer/src/lib/utils.ts b/apps/desktop/src/renderer/src/lib/utils.ts index 531c8b9fb..9e84f0a6e 100644 --- a/apps/desktop/src/renderer/src/lib/utils.ts +++ b/apps/desktop/src/renderer/src/lib/utils.ts @@ -108,8 +108,3 @@ export const getBlockchainExplorerUrl = () => { export const isInMAS = () => { return typeof process !== "undefined" && process.mas } - -export const isInMASReview = () => { - const serverConfigs = getServerConfigs() - return isInMAS() && serverConfigs?.MAS_IN_REVIEW -} diff --git a/apps/desktop/src/renderer/src/modules/command/commands/entry.tsx b/apps/desktop/src/renderer/src/modules/command/commands/entry.tsx index 4e8dcca0c..1f0bc24ef 100644 --- a/apps/desktop/src/renderer/src/modules/command/commands/entry.tsx +++ b/apps/desktop/src/renderer/src/modules/command/commands/entry.tsx @@ -8,6 +8,7 @@ import { toast } from "sonner" import { toggleShowAISummaryOnce } from "~/atoms/ai-summary" import { toggleShowAITranslationOnce } from "~/atoms/ai-translation" import { AudioPlayer, getAudioPlayerAtomValue } from "~/atoms/player" +import { useIsInMASReview } from "~/atoms/server-configs" import { useGeneralSettingKey } from "~/atoms/settings/general" import { getShowSourceContent, @@ -20,7 +21,6 @@ import { navigateEntry } from "~/hooks/biz/useNavigateEntry" import { getRouteParams } from "~/hooks/biz/useRouteParams" import { tipcClient } from "~/lib/client" import { parseHtml } from "~/lib/parse-html" -import { isInMASReview } from "~/lib/utils" import { useActivationModal } from "~/modules/activation" import { useGalleryModal } from "~/modules/entry-content/hooks" import { useTipModal } from "~/modules/wallet/hooks" @@ -107,256 +107,263 @@ export const useRegisterEntryCommands = () => { const voice = useGeneralSettingKey("voice") - useRegisterFollowCommand([ - ...(isInMASReview() - ? ([] as any[]) - : [ - { - id: COMMAND_ID.entry.tip, - label: t("entry_actions.tip"), - icon: , - // keyBinding: shortcuts.entry.tip.key, - // when: !isInbox && feed?.ownerUserId !== whoami()?.id && !!populatedEntry, - run: ({ userId, feedId, entryId }) => { - openTipModal({ - userId, - feedId, - entryId, - }) + const isInMASReview = useIsInMASReview() + + useRegisterFollowCommand( + [ + ...(isInMASReview + ? ([] as any[]) + : [ + { + id: COMMAND_ID.entry.tip, + label: t("entry_actions.tip"), + icon: , + // keyBinding: shortcuts.entry.tip.key, + // when: !isInbox && feed?.ownerUserId !== whoami()?.id && !!populatedEntry, + run: ({ userId, feedId, entryId }) => { + openTipModal({ + userId, + feedId, + entryId, + }) + }, }, - }, - ]), - { - id: COMMAND_ID.entry.star, - label: t("entry_actions.star"), - icon: (props) => ( - - ), - run: ({ entryId, view }) => { - const entry = useEntryStore.getState().flatMapEntries[entryId] - if (!entry) { - toast.error("Failed to star: entry is not available", { duration: 3000 }) - return - } - // if (type === "toolbar") { - // const absoluteStarAnimationUri = new URL(StarAnimationUri, import.meta.url).href - // mountLottie(absoluteStarAnimationUri, { - // x: e.clientX - 90, - // y: e.clientY - 70, - // height: 126, - // width: 252, - // }) - // } - if (entry.collections) { - uncollect.mutate(entry.entries.id) - } else { - collect.mutate({ entryId, view }) - } + ]), + { + id: COMMAND_ID.entry.star, + label: t("entry_actions.star"), + icon: (props) => ( + + ), + run: ({ entryId, view }) => { + const entry = useEntryStore.getState().flatMapEntries[entryId] + if (!entry) { + toast.error("Failed to star: entry is not available", { duration: 3000 }) + return + } + // if (type === "toolbar") { + // const absoluteStarAnimationUri = new URL(StarAnimationUri, import.meta.url).href + // mountLottie(absoluteStarAnimationUri, { + // x: e.clientX - 90, + // y: e.clientY - 70, + // height: 126, + // width: 252, + // }) + // } + if (entry.collections) { + uncollect.mutate(entry.entries.id) + } else { + collect.mutate({ entryId, view }) + } + }, }, - }, - { - id: COMMAND_ID.entry.delete, - label: t("entry_actions.delete"), - icon: , - run: ({ entryId }) => { - const entry = useEntryStore.getState().flatMapEntries[entryId] - if (!entry) { - toast.error("Failed to delete: entry is not available", { duration: 3000 }) - return - } - deleteInboxEntry.mutate(entry.entries.id) + { + id: COMMAND_ID.entry.delete, + label: t("entry_actions.delete"), + icon: , + run: ({ entryId }) => { + const entry = useEntryStore.getState().flatMapEntries[entryId] + if (!entry) { + toast.error("Failed to delete: entry is not available", { duration: 3000 }) + return + } + deleteInboxEntry.mutate(entry.entries.id) + }, }, - }, - { - id: COMMAND_ID.entry.copyLink, - label: t("entry_actions.copy_link"), - icon: , - run: ({ entryId }) => { - const entry = useEntryStore.getState().flatMapEntries[entryId] - if (!entry) { - toast.error("Failed to copy link: entry is not available", { duration: 3000 }) - return - } - if (!entry.entries.url) return - navigator.clipboard.writeText(entry.entries.url) - toast(t("entry_actions.copied_notify", { which: t("words.link") }), { - duration: 1000, - }) + { + id: COMMAND_ID.entry.copyLink, + label: t("entry_actions.copy_link"), + icon: , + run: ({ entryId }) => { + const entry = useEntryStore.getState().flatMapEntries[entryId] + if (!entry) { + toast.error("Failed to copy link: entry is not available", { duration: 3000 }) + return + } + if (!entry.entries.url) return + navigator.clipboard.writeText(entry.entries.url) + toast(t("entry_actions.copied_notify", { which: t("words.link") }), { + duration: 1000, + }) + }, }, - }, - { - id: COMMAND_ID.entry.exportAsPDF, - label: t("entry_actions.export_as_pdf"), - icon: , - run: ({ entryId }) => { - const entry = useEntryStore.getState().flatMapEntries[entryId] + { + id: COMMAND_ID.entry.exportAsPDF, + label: t("entry_actions.export_as_pdf"), + icon: , + run: ({ entryId }) => { + const entry = useEntryStore.getState().flatMapEntries[entryId] - if (!entry) { - toast.error("Failed to export as pdf: entry is not available", { duration: 3000 }) - return - } + if (!entry) { + toast.error("Failed to export as pdf: entry is not available", { duration: 3000 }) + return + } - window.print() + window.print() + }, }, - }, - { - id: COMMAND_ID.entry.copyTitle, - label: t("entry_actions.copy_title"), - icon: , - run: ({ entryId }) => { - const entry = useEntryStore.getState().flatMapEntries[entryId] - if (!entry) { - toast.error("Failed to copy link: entry is not available", { duration: 3000 }) - return - } - if (!entry.entries.title) return - navigator.clipboard.writeText(entry.entries.title) - toast(t("entry_actions.copied_notify", { which: t("words.title") }), { - duration: 1000, - }) + { + id: COMMAND_ID.entry.copyTitle, + label: t("entry_actions.copy_title"), + icon: , + run: ({ entryId }) => { + const entry = useEntryStore.getState().flatMapEntries[entryId] + if (!entry) { + toast.error("Failed to copy link: entry is not available", { duration: 3000 }) + return + } + if (!entry.entries.title) return + navigator.clipboard.writeText(entry.entries.title) + toast(t("entry_actions.copied_notify", { which: t("words.title") }), { + duration: 1000, + }) + }, }, - }, - { - id: COMMAND_ID.entry.openInBrowser, - label: t("entry_actions.open_in_browser", { - which: t(IN_ELECTRON ? "words.browser" : "words.newTab"), - }), - icon: , - run: ({ entryId }) => { - const entry = useEntryStore.getState().flatMapEntries[entryId] - if (!entry || !entry.entries.url) { - toast.error("Failed to open in browser: url is not available", { duration: 3000 }) - return - } - window.open(entry.entries.url, "_blank") - }, - }, - { - id: COMMAND_ID.entry.viewSourceContent, - label: t("entry_actions.view_source_content"), - icon: , - run: ({ entryId }) => { - if (!getShowSourceContent()) { + { + id: COMMAND_ID.entry.openInBrowser, + label: t("entry_actions.open_in_browser", { + which: t(IN_ELECTRON ? "words.browser" : "words.newTab"), + }), + icon: , + run: ({ entryId }) => { const entry = useEntryStore.getState().flatMapEntries[entryId] if (!entry || !entry.entries.url) { - toast.error("Failed to view source content: url is not available", { duration: 3000 }) + toast.error("Failed to open in browser: url is not available", { duration: 3000 }) return } - const routeParams = getRouteParams() - const viewPreviewInModal = [ - FeedViewType.SocialMedia, - FeedViewType.Videos, - FeedViewType.Pictures, - ].includes(routeParams.view) - if (viewPreviewInModal) { - showSourceContentModal({ - title: entry.entries.title ?? undefined, - src: entry.entries.url, - }) - return - } - const layoutEntryId = routeParams.entryId - if (layoutEntryId !== entry.entries.id) { - navigateEntry({ entryId: entry.entries.id }) - } - } - toggleShowSourceContent() + window.open(entry.entries.url, "_blank") + }, }, - }, - { - id: COMMAND_ID.entry.share, - label: t("entry_actions.share"), - icon: , - run: ({ entryId }) => { - const entry = useEntryStore.getState().flatMapEntries[entryId] - if (!entry || !entry.entries.url) { - toast.error("Failed to share: url is not available", { duration: 3000 }) - return - } - if (!entry.entries.url) return + { + id: COMMAND_ID.entry.viewSourceContent, + label: t("entry_actions.view_source_content"), + icon: , + run: ({ entryId }) => { + if (!getShowSourceContent()) { + const entry = useEntryStore.getState().flatMapEntries[entryId] + if (!entry || !entry.entries.url) { + toast.error("Failed to view source content: url is not available", { duration: 3000 }) + return + } + const routeParams = getRouteParams() + const viewPreviewInModal = [ + FeedViewType.SocialMedia, + FeedViewType.Videos, + FeedViewType.Pictures, + ].includes(routeParams.view) + if (viewPreviewInModal) { + showSourceContentModal({ + title: entry.entries.title ?? undefined, + src: entry.entries.url, + }) + return + } + const layoutEntryId = routeParams.entryId + if (layoutEntryId !== entry.entries.id) { + navigateEntry({ entryId: entry.entries.id }) + } + } + toggleShowSourceContent() + }, + }, + { + id: COMMAND_ID.entry.share, + label: t("entry_actions.share"), + icon: , + run: ({ entryId }) => { + const entry = useEntryStore.getState().flatMapEntries[entryId] + if (!entry || !entry.entries.url) { + toast.error("Failed to share: url is not available", { duration: 3000 }) + return + } + if (!entry.entries.url) return - if (IN_ELECTRON) { - return tipcClient?.showShareMenu(entry.entries.url) - } else { - const { title, description } = entry.entries - navigator.share({ - title: title || undefined, - text: description || undefined, - url: entry.entries.url, - }) - } - return - }, - }, - { - id: COMMAND_ID.entry.read, - label: t("entry_actions.mark_as_read"), - icon: (props) => ( - - ), - run: ({ entryId }) => { - const entry = useEntryStore.getState().flatMapEntries[entryId] - if (!entry) { - toast.error("Failed to mark as unread: feed is not available", { duration: 3000 }) - return - } - if (entry.read) { - unread.mutate({ entryId, feedId: entry.feedId }) - } else { - read.mutate({ entryId, feedId: entry.feedId }) - } - }, - }, - { - id: COMMAND_ID.entry.imageGallery, - label: t("entry_actions.image_gallery"), - icon: , - run: ({ entryId }) => { - openGalleryModal(entryId) - }, - }, - { - id: COMMAND_ID.entry.tts, - label: t("entry_content.header.play_tts"), - icon: , - run: async ({ entryId, entryContent }) => { - if (getAudioPlayerAtomValue().entryId === entryId) { - AudioPlayer.togglePlayAndPause() - } else { - const filePath = await tipcClient?.tts({ - id: entryId, - text: parseHtml(entryContent).toText(), - voice, - }) - if (filePath) { - AudioPlayer.mount({ - type: "audio", - entryId, - src: `file://${filePath}`, - currentTime: 0, + if (IN_ELECTRON) { + return tipcClient?.showShareMenu(entry.entries.url) + } else { + const { title, description } = entry.entries + navigator.share({ + title: title || undefined, + text: description || undefined, + url: entry.entries.url, }) } - } + return + }, }, - }, + { + id: COMMAND_ID.entry.read, + label: t("entry_actions.mark_as_read"), + icon: (props) => ( + + ), + run: ({ entryId }) => { + const entry = useEntryStore.getState().flatMapEntries[entryId] + if (!entry) { + toast.error("Failed to mark as unread: feed is not available", { duration: 3000 }) + return + } + if (entry.read) { + unread.mutate({ entryId, feedId: entry.feedId }) + } else { + read.mutate({ entryId, feedId: entry.feedId }) + } + }, + }, + { + id: COMMAND_ID.entry.imageGallery, + label: t("entry_actions.image_gallery"), + icon: , + run: ({ entryId }) => { + openGalleryModal(entryId) + }, + }, + { + id: COMMAND_ID.entry.tts, + label: t("entry_content.header.play_tts"), + icon: , + run: async ({ entryId, entryContent }) => { + if (getAudioPlayerAtomValue().entryId === entryId) { + AudioPlayer.togglePlayAndPause() + } else { + const filePath = await tipcClient?.tts({ + id: entryId, + text: parseHtml(entryContent).toText(), + voice, + }) + if (filePath) { + AudioPlayer.mount({ + type: "audio", + entryId, + src: `file://${filePath}`, + currentTime: 0, + }) + } + } + }, + }, + { + id: COMMAND_ID.entry.readability, + label: t("entry_content.header.readability"), + icon: (props) => ( + + ), + run: async ({ entryId, entryUrl }) => { + return toggleEntryReadability({ + id: entryId, + url: entryUrl, + }) + }, + }, + ], { - id: COMMAND_ID.entry.readability, - label: t("entry_content.header.readability"), - icon: (props) => ( - - ), - run: async ({ entryId, entryUrl }) => { - return toggleEntryReadability({ - id: entryId, - url: entryUrl, - }) - }, + deps: [isInMASReview], }, - ]) + ) useRegisterFollowCommand( [ diff --git a/apps/desktop/src/renderer/src/modules/entry-content/components/SupportCreator.tsx b/apps/desktop/src/renderer/src/modules/entry-content/components/SupportCreator.tsx index 722791229..fa155e40a 100644 --- a/apps/desktop/src/renderer/src/modules/entry-content/components/SupportCreator.tsx +++ b/apps/desktop/src/renderer/src/modules/entry-content/components/SupportCreator.tsx @@ -3,8 +3,8 @@ import { Divider } from "@follow/components/ui/divider/index.js" import { useMemo } from "react" import { useTranslation } from "react-i18next" +import { useIsInMASReview } from "~/atoms/server-configs" import { useWhoami } from "~/atoms/user" -import { isInMASReview } from "~/lib/utils" import { useBoostModal } from "~/modules/boost/hooks" import { useFeedBoostersQuery } from "~/modules/boost/query" import { FeedIcon } from "~/modules/feed/feed-icon" @@ -36,6 +36,8 @@ export const SupportCreator = ({ entryId }: { entryId: string }) => { ) const supportAmount = allSupporters.length + const isInMASReview = useIsInMASReview() + if (!feed || feed.type !== "feed") return null return ( @@ -55,7 +57,7 @@ export const SupportCreator = ({ entryId }: { entryId: string }) => { )} {feed.title} - {!isInMASReview() && ( + {!isInMASReview && (
{!isMyOwnedFeed && (