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,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,