feat(desktop): useIsInMASReview

This commit is contained in:
DIYgod
2025-04-21 17:36:33 +08:00
parent b046be71fe
commit 442f575bbb
5 changed files with 253 additions and 241 deletions
@@ -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<Nullable<ServerConfigs>>(null),
)
export const useIsInMASReview = () => {
const serverConfigs = useServerConfigs()
return isInMAS() && serverConfigs?.MAS_IN_REVIEW
}
@@ -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
? []
: [
{
@@ -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
}
@@ -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: <i className="i-mgc-power-outline" />,
// 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: <i className="i-mgc-power-outline" />,
// 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) => (
<i
className={cn(
props?.isActive ? "i-mgc-star-cute-fi text-orange-500" : "i-mgc-star-cute-re",
)}
/>
),
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) => (
<i
className={cn(
props?.isActive ? "i-mgc-star-cute-fi text-orange-500" : "i-mgc-star-cute-re",
)}
/>
),
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: <i className="i-mgc-delete-2-cute-re" />,
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: <i className="i-mgc-delete-2-cute-re" />,
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: <i className="i-mgc-link-cute-re" />,
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: <i className="i-mgc-link-cute-re" />,
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: <i className="i-mgc-pdf-cute-re" />,
run: ({ entryId }) => {
const entry = useEntryStore.getState().flatMapEntries[entryId]
{
id: COMMAND_ID.entry.exportAsPDF,
label: t("entry_actions.export_as_pdf"),
icon: <i className="i-mgc-pdf-cute-re" />,
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: <i className="i-mgc-copy-cute-re" />,
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: <i className="i-mgc-copy-cute-re" />,
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: <i className="i-mgc-world-2-cute-re" />,
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: <i className="i-mgc-web-cute-re" />,
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: <i className="i-mgc-world-2-cute-re" />,
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: <i className="i-mgc-share-forward-cute-re" />,
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: <i className="i-mgc-web-cute-re" />,
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: <i className="i-mgc-share-forward-cute-re" />,
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) => (
<i className={cn(props?.isActive ? "i-mgc-round-cute-re" : "i-mgc-round-cute-fi")} />
),
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: <i className="i-mgc-pic-cute-fi" />,
run: ({ entryId }) => {
openGalleryModal(entryId)
},
},
{
id: COMMAND_ID.entry.tts,
label: t("entry_content.header.play_tts"),
icon: <i className="i-mgc-voice-cute-re" />,
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) => (
<i className={cn(props?.isActive ? "i-mgc-round-cute-re" : "i-mgc-round-cute-fi")} />
),
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: <i className="i-mgc-pic-cute-fi" />,
run: ({ entryId }) => {
openGalleryModal(entryId)
},
},
{
id: COMMAND_ID.entry.tts,
label: t("entry_content.header.play_tts"),
icon: <i className="i-mgc-voice-cute-re" />,
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) => (
<i className={props?.isActive ? "i-mgc-docment-cute-fi" : "i-mgc-docment-cute-re"} />
),
run: async ({ entryId, entryUrl }) => {
return toggleEntryReadability({
id: entryId,
url: entryUrl,
})
},
},
],
{
id: COMMAND_ID.entry.readability,
label: t("entry_content.header.readability"),
icon: (props) => (
<i className={props?.isActive ? "i-mgc-docment-cute-fi" : "i-mgc-docment-cute-re"} />
),
run: async ({ entryId, entryUrl }) => {
return toggleEntryReadability({
id: entryId,
url: entryUrl,
})
},
deps: [isInMASReview],
},
])
)
useRegisterFollowCommand(
[
@@ -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 }) => {
)}
<span className="-mt-6 text-lg font-medium">{feed.title}</span>
{!isInMASReview() && (
{!isInMASReview && (
<div className="flex items-center gap-4">
{!isMyOwnedFeed && (
<Button