fix(translation): update user role checks for translation prefetching

Refactored translation prefetching logic across multiple components to utilize the new isFreeRole function. This change ensures that users with Free roles do not trigger translation prefetching, optimizing performance and enhancing user experience. Updated relevant imports and conditions in EntryItemImpl, useEntryContent, and various EntryList components.

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-11-05 21:41:56 +08:00
parent f7b648f25e
commit f6a8691e3a
8 changed files with 20 additions and 14 deletions
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
+6
View File
@@ -30,3 +30,9 @@ export const UserRoleName: Record<UserRole, string> = {
[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
}