diff --git a/apps/desktop/layer/renderer/src/modules/entry-column/item.tsx b/apps/desktop/layer/renderer/src/modules/entry-column/item.tsx index 41b1005fc..1b19738eb 100644 --- a/apps/desktop/layer/renderer/src/modules/entry-column/item.tsx +++ b/apps/desktop/layer/renderer/src/modules/entry-column/item.tsx @@ -1,4 +1,4 @@ -import { FeedViewType, UserRole } from "@follow/constants" +import { FeedViewType, isFreeRole } from "@follow/constants" import { useHasEntry } from "@follow/store/entry/hooks" import { useEntryTranslation, usePrefetchEntryTranslation } from "@follow/store/translation/hooks" import { useUserRole } from "@follow/store/user/hooks" @@ -26,7 +26,7 @@ const EntryItemImpl = memo(function EntryItemImpl({ const enableTranslation = useGeneralSettingKey("translation") const actionLanguage = useActionLanguage() const userRole = useUserRole() - const shouldPrefetchTranslation = enableTranslation && userRole !== UserRole.Free + const shouldPrefetchTranslation = enableTranslation && !isFreeRole(userRole) const translation = useEntryTranslation({ entryId, language: actionLanguage, diff --git a/apps/desktop/layer/renderer/src/modules/entry-content/hooks.tsx b/apps/desktop/layer/renderer/src/modules/entry-content/hooks.tsx index 689d6ef07..862e21696 100644 --- a/apps/desktop/layer/renderer/src/modules/entry-content/hooks.tsx +++ b/apps/desktop/layer/renderer/src/modules/entry-content/hooks.tsx @@ -1,4 +1,4 @@ -import { UserRole } from "@follow/constants" +import { isFreeRole } from "@follow/constants" import { useEntry, usePrefetchEntryDetail } from "@follow/store/entry/hooks" import { useEntryTranslation, usePrefetchEntryTranslation } from "@follow/store/translation/hooks" import { useUserRole } from "@follow/store/user/hooks" @@ -50,7 +50,7 @@ export const useEntryContent = (entryId: string) => { const enableTranslation = useShowAITranslation() const userRole = useUserRole() - const shouldPrefetchTranslation = enableTranslation && userRole !== UserRole.Free + const shouldPrefetchTranslation = enableTranslation && !isFreeRole(userRole) const actionLanguage = useActionLanguage() const contentTranslated = useEntryTranslation({ entryId, diff --git a/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx b/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx index 99a6844f4..96a97d6ed 100644 --- a/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx @@ -1,5 +1,5 @@ import type { FeedViewType } from "@follow/constants" -import { UserRole } from "@follow/constants" +import { isFreeRole } from "@follow/constants" import { usePrefetchEntryTranslation } from "@follow/store/translation/hooks" import { useUserRole } from "@follow/store/user/hooks" import type { FlashListRef, ListRenderItemInfo } from "@shopify/flash-list" @@ -55,7 +55,7 @@ export const EntryListContentArticle = ({ const translation = useGeneralSettingKey("translation") const actionLanguage = useActionLanguage() const userRole = useUserRole() - const translationPrefetchEnabled = translation && userRole !== UserRole.Free + const translationPrefetchEnabled = translation && !isFreeRole(userRole) usePrefetchEntryTranslation({ entryIds: active ? viewableItems.map((item) => item.key) : [], language: actionLanguage, diff --git a/apps/mobile/src/modules/entry-list/EntryListContentPicture.tsx b/apps/mobile/src/modules/entry-list/EntryListContentPicture.tsx index 44d203dd4..9bc44bd06 100644 --- a/apps/mobile/src/modules/entry-list/EntryListContentPicture.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListContentPicture.tsx @@ -1,4 +1,4 @@ -import { UserRole } from "@follow/constants" +import { isFreeRole } from "@follow/constants" import { useTypeScriptHappyCallback } from "@follow/hooks" import { usePrefetchEntryTranslation } from "@follow/store/translation/hooks" import { useUserRole } from "@follow/store/user/hooks" @@ -38,7 +38,7 @@ export const EntryListContentPicture = ({ const translation = useGeneralSettingKey("translation") const actionLanguage = useActionLanguage() const userRole = useUserRole() - const translationPrefetchEnabled = translation && userRole !== UserRole.Free + const translationPrefetchEnabled = translation && !isFreeRole(userRole) usePrefetchEntryTranslation({ entryIds: active ? viewableItems.map((item) => item.key) : [], language: actionLanguage, diff --git a/apps/mobile/src/modules/entry-list/EntryListContentSocial.tsx b/apps/mobile/src/modules/entry-list/EntryListContentSocial.tsx index 4892f0efc..c6d0893c8 100644 --- a/apps/mobile/src/modules/entry-list/EntryListContentSocial.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListContentSocial.tsx @@ -1,4 +1,4 @@ -import { UserRole } from "@follow/constants" +import { isFreeRole } from "@follow/constants" import { usePrefetchEntryTranslation } from "@follow/store/translation/hooks" import { useUserRole } from "@follow/store/user/hooks" import type { FlashListRef, ListRenderItemInfo } from "@shopify/flash-list" @@ -48,7 +48,7 @@ export const EntryListContentSocial = ({ const translation = useGeneralSettingKey("translation") const actionLanguage = useActionLanguage() const userRole = useUserRole() - const translationPrefetchEnabled = translation && userRole !== UserRole.Free + const translationPrefetchEnabled = translation && !isFreeRole(userRole) usePrefetchEntryTranslation({ entryIds: active ? viewableItems.map((item) => item.key) : [], language: actionLanguage, diff --git a/apps/mobile/src/modules/entry-list/EntryListContentVideo.tsx b/apps/mobile/src/modules/entry-list/EntryListContentVideo.tsx index b38f027d4..9d6608661 100644 --- a/apps/mobile/src/modules/entry-list/EntryListContentVideo.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListContentVideo.tsx @@ -1,4 +1,4 @@ -import { UserRole } from "@follow/constants" +import { isFreeRole } from "@follow/constants" import { useTypeScriptHappyCallback } from "@follow/hooks" import { usePrefetchEntryTranslation } from "@follow/store/translation/hooks" import { useUserRole } from "@follow/store/user/hooks" @@ -36,7 +36,7 @@ export const EntryListContentVideo = ({ const translation = useGeneralSettingKey("translation") const actionLanguage = useActionLanguage() const userRole = useUserRole() - const translationPrefetchEnabled = translation && userRole !== UserRole.Free + const translationPrefetchEnabled = translation && !isFreeRole(userRole) usePrefetchEntryTranslation({ entryIds: active ? viewableItems.map((item) => item.key) : [], language: actionLanguage, diff --git a/apps/mobile/src/screens/(stack)/entries/[entryId]/EntryDetailScreen.tsx b/apps/mobile/src/screens/(stack)/entries/[entryId]/EntryDetailScreen.tsx index 73f1fcab8..7ed1b0740 100644 --- a/apps/mobile/src/screens/(stack)/entries/[entryId]/EntryDetailScreen.tsx +++ b/apps/mobile/src/screens/(stack)/entries/[entryId]/EntryDetailScreen.tsx @@ -1,4 +1,4 @@ -import { FeedViewType, UserRole } from "@follow/constants" +import { FeedViewType, isFreeRole } from "@follow/constants" import { useEntry, useEntryReadHistory, usePrefetchEntryDetail } from "@follow/store/entry/hooks" import { entrySyncServices } from "@follow/store/entry/store" import { useFeedById } from "@follow/store/feed/hooks" @@ -145,7 +145,7 @@ const EntryContentWebViewWithContext = ({ entryId }: { entryId: string }) => { const showTranslationOnce = useAtomValue(showAITranslationAtom) const actionLanguage = useActionLanguage() const userRole = useUserRole() - const translationPrefetchEnabled = translationSetting && userRole !== UserRole.Free + const translationPrefetchEnabled = translationSetting && !isFreeRole(userRole) const entry = useEntry(entryId, (state) => ({ content: state.content, readabilityContent: state.readabilityContent, diff --git a/packages/internal/constants/src/enums.ts b/packages/internal/constants/src/enums.ts index e1b51392e..ee9602609 100644 --- a/packages/internal/constants/src/enums.ts +++ b/packages/internal/constants/src/enums.ts @@ -30,3 +30,9 @@ export const UserRoleName: Record = { [UserRole.Pro]: "Pro", [UserRole.Plus]: "Plus", } as const + +export const isFreeRole = (role?: UserRole | null) => { + return role + ? role === UserRole.Free || role === UserRole.Trial || role === UserRole.PreProTrial + : true +}