From 0a2a099d7bb894f08c6ac96d008b84904e8dd30e Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Mon, 26 May 2025 22:54:15 +0800 Subject: [PATCH] refactor(mobile): sperate store package (#3819) --- apps/mobile/package.json | 1 + apps/mobile/src/App.tsx | 9 +- apps/mobile/src/atoms/settings/general.ts | 21 +++++ .../native/webview/EntryContentWebView.tsx | 2 +- .../components/ui/image/ImageContextMenu.tsx | 8 +- apps/mobile/src/constants/views.tsx | 9 -- .../hooks.ts => hooks/useMessaging.ts} | 5 +- apps/mobile/src/hooks/useOnboarding.ts | 21 +++++ apps/mobile/src/hooks/useUnreadCountBadge.ts | 17 ++++ apps/mobile/src/initialize/analytics.ts | 2 +- apps/mobile/src/initialize/background.ts | 10 +- apps/mobile/src/initialize/crashlytics.tsx | 3 +- apps/mobile/src/initialize/hydrate.ts | 1 - apps/mobile/src/initialize/index.ts | 12 ++- apps/mobile/src/lib/api-fetch.ts | 2 +- apps/mobile/src/lib/auth.ts | 6 +- apps/mobile/src/main.tsx | 7 ++ .../mobile/src/modules/context-menu/entry.tsx | 14 +-- .../mobile/src/modules/context-menu/feeds.tsx | 16 ++-- .../mobile/src/modules/context-menu/inbox.tsx | 2 +- .../mobile/src/modules/context-menu/lists.tsx | 4 +- .../mobile/src/modules/context-menu/video.tsx | 8 +- .../modules/dialogs/MarkAllAsReadDialog.tsx | 12 ++- .../discover/search-tabs/SearchFeedCard.tsx | 2 +- .../discover/search-tabs/SearchList.tsx | 2 +- .../modules/entry-content/EntryAISummary.tsx | 22 ++--- .../EntryContentHeaderRightActions.tsx | 25 ++--- .../modules/entry-content/EntryGridFooter.tsx | 11 ++- .../entry-content/EntryNavigationHeader.tsx | 2 +- .../entry-content/EntryReadHistory.tsx | 6 +- .../src/modules/entry-content/EntryTitle.tsx | 10 +- .../entry-list/EntryListContentArticle.tsx | 13 ++- .../entry-list/EntryListContentPicture.tsx | 14 ++- .../entry-list/EntryListContentSocial.tsx | 13 ++- .../entry-list/EntryListContentVideo.tsx | 13 ++- .../modules/entry-list/EntryListFooter.tsx | 18 +++- .../modules/entry-list/EntryListSelector.tsx | 2 +- apps/mobile/src/modules/entry-list/hooks.ts | 11 ++- apps/mobile/src/modules/entry-list/index.tsx | 12 +-- .../entry-list/templates/EntryNormalItem.tsx | 14 +-- .../entry-list/templates/EntryPictureItem.tsx | 6 +- .../entry-list/templates/EntrySocialItem.tsx | 13 +-- .../entry-list/templates/EntryVideoItem.tsx | 4 +- apps/mobile/src/modules/feed/FollowFeed.tsx | 8 +- apps/mobile/src/modules/list/FollowList.tsx | 8 +- .../src/modules/player/PlayerTabBar.tsx | 2 +- apps/mobile/src/modules/player/hooks.ts | 3 +- .../src/modules/screen/PagerList.ios.tsx | 12 +-- apps/mobile/src/modules/screen/PagerList.tsx | 12 +-- .../modules/screen/TimelineSelectorList.tsx | 4 +- .../modules/screen/TimelineViewSelector.tsx | 25 +++-- .../TimelineViewSelectorContextMenu.tsx | 8 +- apps/mobile/src/modules/screen/action.tsx | 4 +- apps/mobile/src/modules/screen/atoms.ts | 61 ++++++++++-- .../src/modules/settings/SettingsList.tsx | 2 +- .../src/modules/settings/UserHeaderBanner.tsx | 4 +- .../src/modules/settings/actions/constant.ts | 2 +- .../settings/hooks/useTOTPModalWrapper.tsx | 2 +- .../modules/settings/routes/2FASetting.tsx | 2 +- .../src/modules/settings/routes/Account.tsx | 4 +- .../src/modules/settings/routes/Actions.tsx | 26 +++-- .../modules/settings/routes/Appearance.tsx | 2 +- .../modules/settings/routes/EditCondition.tsx | 4 +- .../modules/settings/routes/EditProfile.tsx | 8 +- .../settings/routes/EditRewriteRules.tsx | 4 +- .../src/modules/settings/routes/EditRule.tsx | 4 +- .../modules/settings/routes/EditWebhooks.tsx | 4 +- .../src/modules/settings/routes/Lists.tsx | 6 +- .../modules/settings/routes/ManageList.tsx | 16 ++-- apps/mobile/src/modules/settings/utils.ts | 2 +- .../modules/subscription/CategoryGrouped.tsx | 2 +- .../subscription/SubscriptionLists.tsx | 49 +++++++--- .../modules/subscription/UnGroupedList.tsx | 11 ++- .../modules/subscription/items/InboxItem.tsx | 6 +- .../items/ListSubscriptionItem.tsx | 6 +- .../subscription/items/SubscriptionItem.tsx | 6 +- .../src/screens/(modal)/EditEmailScreen.tsx | 8 +- .../src/screens/(modal)/InvitationScreen.tsx | 2 +- .../mobile/src/screens/(modal)/ListScreen.tsx | 10 +- .../src/screens/(modal)/LoginScreen.tsx | 2 +- .../src/screens/(modal)/ProfileScreen.tsx | 12 +-- .../src/screens/(modal)/RsshubFormScreen.tsx | 2 +- .../screens/(modal)/TwoFactorAuthScreen.tsx | 2 +- .../src/screens/(stack)/(tabs)/settings.tsx | 2 +- .../screens/(stack)/(tabs)/subscriptions.tsx | 2 +- .../entries/[entryId]/EntryDetailScreen.tsx | 26 +++-- .../(stack)/feeds/[feedId]/FeedScreen.tsx | 18 ++-- apps/mobile/src/screens/OnboardingScreen.tsx | 2 +- apps/mobile/src/screens/PlayerScreen.tsx | 2 +- apps/mobile/src/store/entry/getter.ts | 58 ------------ apps/mobile/src/store/internal/base.ts | 3 - packages/internal/constants/src/tabs.tsx | 12 +++ packages/internal/store/package.json | 39 ++++++++ .../internal/store/src}/action/hooks.ts | 14 +-- .../internal/store/src}/action/store.ts | 2 - .../internal/store/src}/collection/hooks.ts | 0 .../internal/store/src}/collection/store.ts | 2 - .../internal/store/src}/collection/types.ts | 0 packages/internal/store/src/entry/getter.ts | 8 ++ .../internal/store/src}/entry/hooks.ts | 40 ++++---- .../internal/store/src}/entry/store.ts | 47 +++++----- .../internal/store/src}/entry/types.ts | 5 + .../internal/store/src}/entry/utils.ts | 0 .../internal/store/src}/feed/getter.ts | 0 .../internal/store/src}/feed/hooks.ts | 0 .../internal/store/src}/feed/store.ts | 2 - .../internal/store/src}/feed/types.ts | 0 .../internal/store/src}/image/getters.ts | 0 .../internal/store/src}/image/hooks.ts | 0 .../internal/store/src}/image/store.ts | 0 .../internal/store/src}/inbox/hooks.ts | 0 .../internal/store/src}/inbox/store.ts | 0 .../internal/store/src}/index.ts | 6 +- packages/internal/store/src/internal/base.ts | 7 ++ .../internal/store/src}/internal/helper.ts | 0 .../internal/store/src}/list/getters.ts | 0 .../internal/store/src}/list/hooks.ts | 0 .../internal/store/src}/list/store.ts | 6 +- .../internal/store/src}/list/types.ts | 0 .../internal/store}/src/morph/db-store.ts | 4 +- .../internal/store}/src/morph/hono.ts | 12 +-- .../internal/store}/src/morph/store-db.ts | 6 +- .../internal/store}/src/morph/types.ts | 4 +- .../store/src}/subscription/getter.ts | 0 .../internal/store/src}/subscription/hooks.ts | 94 ++++++++++++------- .../internal/store/src}/subscription/store.ts | 10 +- .../internal/store/src}/subscription/types.ts | 0 .../internal/store/src}/subscription/utils.ts | 2 +- .../internal/store/src}/summary/enum.ts | 0 .../internal/store/src}/summary/hooks.ts | 19 ++-- .../internal/store/src}/summary/store.ts | 15 ++- .../internal/store/src}/translation/hooks.ts | 21 +++-- .../internal/store/src}/translation/store.ts | 8 +- .../internal/store/src}/translation/types.ts | 0 packages/internal/store/src/types.ts | 58 ++++++++++++ .../internal/store/src}/unread/getter.ts | 0 .../internal/store/src}/unread/hooks.ts | 14 --- .../internal/store/src}/unread/store.ts | 17 +--- .../internal/store/src}/unread/types.ts | 0 .../internal/store/src}/user/constants.ts | 0 .../internal/store/src}/user/getters.ts | 0 .../internal/store/src}/user/hooks.ts | 28 +----- .../internal/store/src}/user/store.ts | 19 ++-- .../internal/store/src}/user/types.ts | 0 packages/internal/store/tsconfig.json | 7 ++ packages/internal/utils/package.json | 5 + packages/internal/utils/src/utils.ts | 2 + pnpm-lock.yaml | 64 ++++++++++++- 148 files changed, 911 insertions(+), 563 deletions(-) rename apps/mobile/src/{store/messaging/hooks.ts => hooks/useMessaging.ts} (94%) create mode 100644 apps/mobile/src/hooks/useOnboarding.ts create mode 100644 apps/mobile/src/hooks/useUnreadCountBadge.ts delete mode 100644 apps/mobile/src/store/entry/getter.ts delete mode 100644 apps/mobile/src/store/internal/base.ts create mode 100644 packages/internal/store/package.json rename {apps/mobile/src/store => packages/internal/store/src}/action/hooks.ts (82%) rename {apps/mobile/src/store => packages/internal/store/src}/action/store.ts (99%) rename {apps/mobile/src/store => packages/internal/store/src}/collection/hooks.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/collection/store.ts (98%) rename {apps/mobile/src/store => packages/internal/store/src}/collection/types.ts (100%) create mode 100644 packages/internal/store/src/entry/getter.ts rename {apps/mobile/src/store => packages/internal/store/src}/entry/hooks.ts (78%) rename {apps/mobile/src/store => packages/internal/store/src}/entry/store.ts (93%) rename {apps/mobile/src/store => packages/internal/store/src}/entry/types.ts (81%) rename {apps/mobile/src/store => packages/internal/store/src}/entry/utils.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/feed/getter.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/feed/hooks.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/feed/store.ts (98%) rename {apps/mobile/src/store => packages/internal/store/src}/feed/types.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/image/getters.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/image/hooks.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/image/store.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/inbox/hooks.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/inbox/store.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/index.ts (77%) create mode 100644 packages/internal/store/src/internal/base.ts rename {apps/mobile/src/store => packages/internal/store/src}/internal/helper.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/list/getters.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/list/hooks.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/list/store.ts (96%) rename {apps/mobile/src/store => packages/internal/store/src}/list/types.ts (100%) rename {apps/mobile => packages/internal/store}/src/morph/db-store.ts (73%) rename {apps/mobile => packages/internal/store}/src/morph/hono.ts (94%) rename {apps/mobile => packages/internal/store}/src/morph/store-db.ts (83%) rename {apps/mobile => packages/internal/store}/src/morph/types.ts (91%) rename {apps/mobile/src/store => packages/internal/store/src}/subscription/getter.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/subscription/hooks.ts (85%) rename {apps/mobile/src/store => packages/internal/store/src}/subscription/store.ts (97%) rename {apps/mobile/src/store => packages/internal/store/src}/subscription/types.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/subscription/utils.ts (91%) rename {apps/mobile/src/store => packages/internal/store/src}/summary/enum.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/summary/hooks.ts (57%) rename {apps/mobile/src/store => packages/internal/store/src}/summary/store.ts (94%) rename {apps/mobile/src/store => packages/internal/store/src}/translation/hooks.ts (64%) rename {apps/mobile/src/store => packages/internal/store/src}/translation/store.ts (93%) rename {apps/mobile/src/store => packages/internal/store/src}/translation/types.ts (100%) create mode 100644 packages/internal/store/src/types.ts rename {apps/mobile/src/store => packages/internal/store/src}/unread/getter.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/unread/hooks.ts (80%) rename {apps/mobile/src/store => packages/internal/store/src}/unread/store.ts (91%) rename {apps/mobile/src/store => packages/internal/store/src}/unread/types.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/user/constants.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/user/getters.ts (100%) rename {apps/mobile/src/store => packages/internal/store/src}/user/hooks.ts (56%) rename {apps/mobile/src/store => packages/internal/store/src}/user/store.ts (90%) rename {apps/mobile/src/store => packages/internal/store/src}/user/types.ts (100%) create mode 100644 packages/internal/store/tsconfig.json diff --git a/apps/mobile/package.json b/apps/mobile/package.json index 9e02af1e7..8c0cc09ce 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -28,6 +28,7 @@ "@follow/legal": "workspace:*", "@follow/models": "workspace:*", "@follow/shared": "workspace:*", + "@follow/store": "workspace:*", "@follow/tracker": "workspace:*", "@follow/types": "workspace:*", "@follow/utils": "workspace:*", diff --git a/apps/mobile/src/App.tsx b/apps/mobile/src/App.tsx index 38fa0bec3..bea64f237 100644 --- a/apps/mobile/src/App.tsx +++ b/apps/mobile/src/App.tsx @@ -1,3 +1,5 @@ +import { usePrefetchActions } from "@follow/store/src/action/hooks" +import { usePrefetchSessionUser } from "@follow/store/src/user/hooks" import { StatusBar } from "expo-status-bar" import { View } from "react-native" import Animated, { interpolate, useAnimatedStyle } from "react-native-reanimated" @@ -6,11 +8,10 @@ import { useSheet } from "react-native-sheet-transitions" import { useBackHandler } from "./hooks/useBackHandler" import { useIntentHandler } from "./hooks/useIntentHandler" +import { useMessaging, useUpdateMessagingToken } from "./hooks/useMessaging" +import { useOnboarding } from "./hooks/useOnboarding" +import { useUnreadCountBadge } from "./hooks/useUnreadCountBadge" import { DebugButton, EnvProfileIndicator } from "./modules/debug" -import { usePrefetchActions } from "./store/action/hooks" -import { useMessaging, useUpdateMessagingToken } from "./store/messaging/hooks" -import { useUnreadCountBadge } from "./store/unread/hooks" -import { useOnboarding, usePrefetchSessionUser } from "./store/user/hooks" export function App({ children }: { children: React.ReactNode }) { useIntentHandler() diff --git a/apps/mobile/src/atoms/settings/general.ts b/apps/mobile/src/atoms/settings/general.ts index 522de8c41..9138f420f 100644 --- a/apps/mobile/src/atoms/settings/general.ts +++ b/apps/mobile/src/atoms/settings/general.ts @@ -1,5 +1,7 @@ import { defaultGeneralSettings } from "@follow/shared/src/settings/defaults" import type { GeneralSettings } from "@follow/shared/src/settings/interface" +import type { FetchEntriesPropsSettings } from "@follow/store/src/entry/types" +import { useMemo } from "react" import { getDeviceLanguage } from "@/src/lib/i18n" import type { SupportedLanguages } from "@/src/lib/language" @@ -51,3 +53,22 @@ export function useHideAllReadSubscriptions() { const unreadOnly = useGeneralSettingKey("unreadOnly") return hideAllReadSubscriptions && unreadOnly } + +export function getHideAllReadSubscriptions() { + const { hideAllReadSubscriptions, unreadOnly } = getGeneralSettings() + return hideAllReadSubscriptions && unreadOnly +} + +export function useFetchEntriesSettings(): FetchEntriesPropsSettings { + const hidePrivateSubscriptionsInTimeline = useGeneralSettingKey( + "hidePrivateSubscriptionsInTimeline", + ) + const unreadOnly = useGeneralSettingKey("unreadOnly") + return useMemo( + () => ({ + hidePrivateSubscriptionsInTimeline, + unreadOnly, + }), + [hidePrivateSubscriptionsInTimeline, unreadOnly], + ) +} diff --git a/apps/mobile/src/components/native/webview/EntryContentWebView.tsx b/apps/mobile/src/components/native/webview/EntryContentWebView.tsx index 55c5c7ad9..ad33031a0 100644 --- a/apps/mobile/src/components/native/webview/EntryContentWebView.tsx +++ b/apps/mobile/src/components/native/webview/EntryContentWebView.tsx @@ -1,3 +1,4 @@ +import type { EntryModel, EntryWithTranslation } from "@follow/store/src/entry/types" import { clsx } from "@follow/utils" import { Portal } from "@gorhom/portal" import { useAtom } from "jotai" @@ -7,7 +8,6 @@ import { TouchableOpacity, View } from "react-native" import { useUISettingKey } from "@/src/atoms/settings/ui" import { BugCuteReIcon } from "@/src/icons/bug_cute_re" -import type { EntryModel, EntryWithTranslation } from "@/src/store/entry/types" import { PlatformActivityIndicator } from "../../ui/loading/PlatformActivityIndicator" import { sharedWebViewHeightAtom } from "./atom" diff --git a/apps/mobile/src/components/ui/image/ImageContextMenu.tsx b/apps/mobile/src/components/ui/image/ImageContextMenu.tsx index 8325cad3e..217cdbd51 100644 --- a/apps/mobile/src/components/ui/image/ImageContextMenu.tsx +++ b/apps/mobile/src/components/ui/image/ImageContextMenu.tsx @@ -1,4 +1,8 @@ import type { FeedViewType } from "@follow/constants" +import { useIsEntryStarred } from "@follow/store/src/collection/hooks" +import { collectionSyncService } from "@follow/store/src/collection/store" +import { useEntry } from "@follow/store/src/entry/hooks" +import { unreadSyncService } from "@follow/store/src/unread/store" import ImageEditor from "@react-native-community/image-editor" import { requireNativeModule } from "expo" import * as FileSystem from "expo-file-system" @@ -12,10 +16,6 @@ import { findNodeHandle, Image, Pressable } from "react-native" import { isIOS } from "@/src/lib/platform" import { toast } from "@/src/lib/toast" -import { useIsEntryStarred } from "@/src/store/collection/hooks" -import { collectionSyncService } from "@/src/store/collection/store" -import { useEntry } from "@/src/store/entry/hooks" -import { unreadSyncService } from "@/src/store/unread/store" import { ContextMenu } from "../context-menu" diff --git a/apps/mobile/src/constants/views.tsx b/apps/mobile/src/constants/views.tsx index c0dc5f08f..412eb8cb6 100644 --- a/apps/mobile/src/constants/views.tsx +++ b/apps/mobile/src/constants/views.tsx @@ -1,6 +1,5 @@ import type { ViewDefinition as ViewDefinitionBase } from "@follow/constants" import { FeedViewType, views as viewsBase } from "@follow/constants" -import colors from "tailwindcss/colors" import { AnnouncementCuteFiIcon } from "../icons/announcement_cute_fi" import { MicCuteFiIcon } from "../icons/mic_cute_fi" @@ -8,36 +7,28 @@ import { PaperCuteFiIcon } from "../icons/paper_cute_fi" import { PicCuteFiIcon } from "../icons/pic_cute_fi" import { TwitterCuteFiIcon } from "../icons/twitter_cute_fi" import { VideoCuteFiIcon } from "../icons/video_cute_fi" -import { accentColor } from "../theme/colors" interface ViewDefinitionExtended { icon: React.FC<{ color?: string; height?: number; width?: number }> - activeColor: string } const extendMap: Record = { [FeedViewType.Articles]: { icon: PaperCuteFiIcon, - activeColor: accentColor, }, [FeedViewType.SocialMedia]: { icon: TwitterCuteFiIcon, - activeColor: colors.sky[500], }, [FeedViewType.Pictures]: { icon: PicCuteFiIcon, - activeColor: colors.green[500], }, [FeedViewType.Videos]: { icon: VideoCuteFiIcon, - activeColor: colors.red[500], }, [FeedViewType.Audios]: { icon: MicCuteFiIcon, - activeColor: colors.purple[500], }, [FeedViewType.Notifications]: { icon: AnnouncementCuteFiIcon, - activeColor: colors.yellow[500], }, } diff --git a/apps/mobile/src/store/messaging/hooks.ts b/apps/mobile/src/hooks/useMessaging.ts similarity index 94% rename from apps/mobile/src/store/messaging/hooks.ts rename to apps/mobile/src/hooks/useMessaging.ts index 7d4f92b4b..548250db1 100644 --- a/apps/mobile/src/store/messaging/hooks.ts +++ b/apps/mobile/src/hooks/useMessaging.ts @@ -1,3 +1,5 @@ +import { useHasNotificationActions } from "@follow/store/src/action/hooks" +import { useWhoami } from "@follow/store/src/user/hooks" import { getApp } from "@react-native-firebase/app" import type { FirebaseMessagingTypes } from "@react-native-firebase/messaging" import { getMessaging } from "@react-native-firebase/messaging" @@ -11,9 +13,6 @@ import { useNavigation } from "@/src/lib/navigation/hooks" import { requestNotificationPermission } from "@/src/lib/permission" import { EntryDetailScreen } from "@/src/screens/(stack)/entries/[entryId]/EntryDetailScreen" -import { useHasNotificationActions } from "../action/hooks" -import { useWhoami } from "../user/hooks" - const FIREBASE_MESSAGING_TOKEN_STORAGE_KEY = "firebase_messaging_token" async function saveMessagingToken() { diff --git a/apps/mobile/src/hooks/useOnboarding.ts b/apps/mobile/src/hooks/useOnboarding.ts new file mode 100644 index 000000000..0281120a1 --- /dev/null +++ b/apps/mobile/src/hooks/useOnboarding.ts @@ -0,0 +1,21 @@ +import { isOnboardingFinishedStorageKey } from "@follow/store/src/user/constants" +import { useIsNewUser, useWhoami } from "@follow/store/src/user/hooks" +import { useEffect } from "react" + +import { kv } from "../lib/kv" +import { useNavigation } from "../lib/navigation/hooks" +import { OnboardingScreen } from "../screens/OnboardingScreen" + +export function useOnboarding() { + const whoami = useWhoami() + const isNewUser = useIsNewUser({ enabled: !!whoami }) + const navigation = useNavigation() + useEffect(() => { + async function checkOnboarding() { + if (isNewUser && !(await kv.get(isOnboardingFinishedStorageKey))) { + navigation.presentControllerView(OnboardingScreen, undefined, "fullScreenModal") + } + } + checkOnboarding() + }, [isNewUser, navigation]) +} diff --git a/apps/mobile/src/hooks/useUnreadCountBadge.ts b/apps/mobile/src/hooks/useUnreadCountBadge.ts new file mode 100644 index 000000000..37bb54c11 --- /dev/null +++ b/apps/mobile/src/hooks/useUnreadCountBadge.ts @@ -0,0 +1,17 @@ +import { useUnreadCounts } from "@follow/store/src/unread/hooks" +import { useMutation } from "@tanstack/react-query" +import { useEffect } from "react" + +import { setBadgeCountAsyncWithPermission } from "../lib/permission" + +export function useUnreadCountBadge() { + const unreadCount = useUnreadCounts() + const { mutate, isPending } = useMutation({ + mutationFn: (unread: number) => setBadgeCountAsyncWithPermission(unread), + }) + useEffect(() => { + if (!isPending) { + mutate(unreadCount) + } + }, [unreadCount, mutate, isPending]) +} diff --git a/apps/mobile/src/initialize/analytics.ts b/apps/mobile/src/initialize/analytics.ts index d26921d2c..5cd6ba50a 100644 --- a/apps/mobile/src/initialize/analytics.ts +++ b/apps/mobile/src/initialize/analytics.ts @@ -1,10 +1,10 @@ +import { whoami } from "@follow/store/src/user/getters" import { setFirebaseTracker, setOpenPanelTracker, tracker } from "@follow/tracker" import { getAnalytics } from "@react-native-firebase/analytics" import { nativeApplicationVersion, nativeBuildVersion } from "expo-application" import { getUserAgent } from "../lib/native/user-agent" import { op } from "../lib/op" -import { whoami } from "../store/user/getters" export const initAnalytics = async () => { setOpenPanelTracker(op) diff --git a/apps/mobile/src/initialize/background.ts b/apps/mobile/src/initialize/background.ts index 8683a56ec..5d5f38c53 100644 --- a/apps/mobile/src/initialize/background.ts +++ b/apps/mobile/src/initialize/background.ts @@ -1,9 +1,11 @@ +import { getAllUnreadCount } from "@follow/store/src/unread/getter" +import { unreadSyncService } from "@follow/store/src/unread/store" +import { whoami } from "@follow/store/src/user/getters" import * as BackgroundTask from "expo-background-task" import * as TaskManager from "expo-task-manager" import { getUISettings } from "../atoms/settings/ui" -import { unreadSyncService } from "../store/unread/store" -import { whoami } from "../store/user/getters" +import { setBadgeCountAsyncWithPermission } from "../lib/permission" const BACKGROUND_FETCH_TASK = "background-fetch" @@ -18,7 +20,9 @@ export async function initBackgroundTask() { } try { - await unreadSyncService.updateBadgeAtBackground() + await unreadSyncService.resetFromRemote() + const allUnreadCount = getAllUnreadCount() + await setBadgeCountAsyncWithPermission(allUnreadCount) return BackgroundTask.BackgroundTaskResult.Success } catch (err) { console.error(err) diff --git a/apps/mobile/src/initialize/crashlytics.tsx b/apps/mobile/src/initialize/crashlytics.tsx index 5dd896f91..3ab5baed5 100644 --- a/apps/mobile/src/initialize/crashlytics.tsx +++ b/apps/mobile/src/initialize/crashlytics.tsx @@ -1,7 +1,6 @@ +import { whoami } from "@follow/store/src/user/getters" import { getCrashlytics, setAttributes, setUserId } from "@react-native-firebase/crashlytics" -import { whoami } from "../store/user/getters" - export const initCrashlytics = async () => { const crashlytics = getCrashlytics() const user = whoami() diff --git a/apps/mobile/src/initialize/hydrate.ts b/apps/mobile/src/initialize/hydrate.ts index a0d86f2ac..d51102ac4 100644 --- a/apps/mobile/src/initialize/hydrate.ts +++ b/apps/mobile/src/initialize/hydrate.ts @@ -2,7 +2,6 @@ import { persistQueryClient } from "@tanstack/react-query-persist-client" import { kvStoragePersister, queryClient } from "../lib/query-client" -export { hydrateDatabaseToStore } from "../store" export const hydrateSettings = () => {} export const hydrateQueryClient = () => { persistQueryClient({ diff --git a/apps/mobile/src/initialize/index.ts b/apps/mobile/src/initialize/index.ts index e025e2d9c..f4f582c89 100644 --- a/apps/mobile/src/initialize/index.ts +++ b/apps/mobile/src/initialize/index.ts @@ -1,7 +1,9 @@ import { initializeDb } from "@follow/database/src/db" +import { hydrateDatabaseToStore } from "@follow/store/src" import { tracker } from "@follow/tracker" import { nativeApplicationVersion } from "expo-application" +import { getGeneralSettings } from "../atoms/settings/general" import { settingSyncQueue } from "../modules/settings/sync-queue" import { initAnalytics } from "./analytics" import { initializeAppCheck } from "./app-check" @@ -9,7 +11,7 @@ import { initBackgroundTask } from "./background" import { initCrashlytics } from "./crashlytics" import { initializeDayjs } from "./dayjs" import { initDeviceType } from "./device" -import { hydrateDatabaseToStore, hydrateQueryClient, hydrateSettings } from "./hydrate" +import { hydrateQueryClient, hydrateSettings } from "./hydrate" import { migrateDatabase } from "./migration" import { initializePlayer } from "./player" @@ -27,7 +29,13 @@ export const initializeApp = async () => { await apm("hydrateSettings", hydrateSettings) let dataHydratedTime = Date.now() - await apm("hydrateDatabaseToStore", hydrateDatabaseToStore) + await apm("hydrateDatabaseToStore", () => { + const { hidePrivateSubscriptionsInTimeline, unreadOnly } = getGeneralSettings() + return hydrateDatabaseToStore({ + hidePrivateSubscriptionsInTimeline, + unreadOnly, + }) + }) dataHydratedTime = Date.now() - dataHydratedTime await apm("hydrateQueryClient", hydrateQueryClient) diff --git a/apps/mobile/src/lib/api-fetch.ts b/apps/mobile/src/lib/api-fetch.ts index f74eeaf1b..f8faad8ae 100644 --- a/apps/mobile/src/lib/api-fetch.ts +++ b/apps/mobile/src/lib/api-fetch.ts @@ -1,9 +1,9 @@ /* eslint-disable no-console */ import type { AppType } from "@follow/shared" +import { userActions } from "@follow/store/src/user/store" import { FetchError, ofetch } from "ofetch" import { InvitationScreen } from "../screens/(modal)/InvitationScreen" -import { userActions } from "../store/user/store" import { getCookie } from "./auth" import { getUserAgent } from "./native/user-agent" import { Navigation } from "./navigation/Navigation" diff --git a/apps/mobile/src/lib/auth.ts b/apps/mobile/src/lib/auth.ts index 12db90136..77089df3f 100644 --- a/apps/mobile/src/lib/auth.ts +++ b/apps/mobile/src/lib/auth.ts @@ -1,5 +1,7 @@ import { expoClient } from "@better-auth/expo/client" import type { authPlugins } from "@follow/shared/src/hono" +import { isNewUserQueryKey } from "@follow/store/src/user/constants" +import { whoamiQueryKey } from "@follow/store/src/user/hooks" import { useQuery } from "@tanstack/react-query" import { inferAdditionalFields, twoFactorClient } from "better-auth/client/plugins" import { createAuthClient } from "better-auth/react" @@ -7,8 +9,6 @@ import type { BetterAuthClientPlugin } from "better-auth/types" import * as SecureStore from "expo-secure-store" import { Platform } from "react-native" -import { isNewUserQueryKey } from "../store/user/constants" -import { whoamiQueryKey } from "../store/user/hooks" import { proxyEnv } from "./proxy-env" import { queryClient } from "./query-client" @@ -41,7 +41,7 @@ const serverPlugins = [ }), ] satisfies BetterAuthClientPlugin[] -const authClient = createAuthClient({ +export const authClient = createAuthClient({ baseURL: `${proxyEnv.API_URL}/better-auth`, plugins: [ twoFactorClient(), diff --git a/apps/mobile/src/main.tsx b/apps/mobile/src/main.tsx index dc80b60d3..ee7ab9ad2 100644 --- a/apps/mobile/src/main.tsx +++ b/apps/mobile/src/main.tsx @@ -11,6 +11,8 @@ import { App } from "./App" import { BottomTabProvider } from "./components/layouts/tabbar/BottomTabProvider" import { BottomTabs } from "./components/layouts/tabbar/BottomTabs" import { initializeApp } from "./initialize" +import { apiClient } from "./lib/api-fetch" +import { authClient } from "./lib/auth" import { initializeI18n } from "./lib/i18n" import { TabBarPortal } from "./lib/navigation/bottom-tab/TabBarPortal" import { TabRoot } from "./lib/navigation/bottom-tab/TabRoot" @@ -23,6 +25,11 @@ import { SettingsTabScreen } from "./screens/(stack)/(tabs)/settings" import { SubscriptionsTabScreen } from "./screens/(stack)/(tabs)/subscriptions" import { registerSitemap } from "./sitemap" +// @ts-expect-error +globalThis.apiClient = apiClient +// @ts-expect-error +globalThis.authClient = authClient + enableFreeze(true) ;[Image, LinearGradient].forEach((Component) => { cssInterop(Component, { className: "style" }) diff --git a/apps/mobile/src/modules/context-menu/entry.tsx b/apps/mobile/src/modules/context-menu/entry.tsx index 05b214b00..29dc58160 100644 --- a/apps/mobile/src/modules/context-menu/entry.tsx +++ b/apps/mobile/src/modules/context-menu/entry.tsx @@ -1,10 +1,15 @@ import type { FeedViewType } from "@follow/constants" +import { useIsEntryStarred } from "@follow/store/src/collection/hooks" +import { collectionSyncService } from "@follow/store/src/collection/store" +import { useEntry } from "@follow/store/src/entry/hooks" +import { unreadSyncService } from "@follow/store/src/unread/store" import { PortalProvider } from "@gorhom/portal" import type { PropsWithChildren } from "react" import { useCallback } from "react" import { useTranslation } from "react-i18next" import { Share, Text, View } from "react-native" +import { getHideAllReadSubscriptions } from "@/src/atoms/settings/general" import { EntryContentWebView, preloadWebViewEntry, @@ -13,13 +18,8 @@ import { ContextMenu } from "@/src/components/ui/context-menu" import { useNavigation } from "@/src/lib/navigation/hooks" import { toast } from "@/src/lib/toast" import { EntryDetailScreen } from "@/src/screens/(stack)/entries/[entryId]/EntryDetailScreen" -import { useIsEntryStarred } from "@/src/store/collection/hooks" -import { collectionSyncService } from "@/src/store/collection/store" -import { getFetchEntryPayload } from "@/src/store/entry/getter" -import { useEntry } from "@/src/store/entry/hooks" -import { unreadSyncService } from "@/src/store/unread/store" -import { useSelectedFeed, useSelectedView } from "../screen/atoms" +import { getFetchEntryPayload, useSelectedFeed, useSelectedView } from "../screen/atoms" export const EntryItemContextMenu = ({ id, @@ -76,6 +76,7 @@ export const EntryItemContextMenu = ({ startTime: new Date(publishedAt).getTime() + 1, endTime: Date.now(), }, + excludePrivate: getHideAllReadSubscriptions(), }) }} > @@ -121,6 +122,7 @@ export const EntryItemContextMenu = ({ startTime: 1, endTime: new Date(publishedAt).getTime() - 1, }, + excludePrivate: getHideAllReadSubscriptions(), }) }} > diff --git a/apps/mobile/src/modules/context-menu/feeds.tsx b/apps/mobile/src/modules/context-menu/feeds.tsx index dc79a9cc7..c4220a1bb 100644 --- a/apps/mobile/src/modules/context-menu/feeds.tsx +++ b/apps/mobile/src/modules/context-menu/feeds.tsx @@ -1,4 +1,10 @@ import { FeedViewType } from "@follow/constants" +import { useEntryIdsByFeedId, usePrefetchEntries } from "@follow/store/src/entry/hooks" +import { getFeed } from "@follow/store/src/feed/getter" +import { getSubscription } from "@follow/store/src/subscription/getter" +import { getSubscriptionCategory } from "@follow/store/src/subscription/hooks" +import { subscriptionSyncService } from "@follow/store/src/subscription/store" +import { unreadSyncService } from "@follow/store/src/unread/store" import dayjs from "dayjs" import { setStringAsync } from "expo-clipboard" import { t } from "i18next" @@ -8,6 +14,7 @@ import { useTranslation } from "react-i18next" import type { ListRenderItemInfo } from "react-native" import { Alert, FlatList, View } from "react-native" +import { useFetchEntriesSettings } from "@/src/atoms/settings/general" import { ContextMenu } from "@/src/components/ui/context-menu" import { PlatformActivityIndicator } from "@/src/components/ui/loading/PlatformActivityIndicator" import { views } from "@/src/constants/views" @@ -16,12 +23,6 @@ import type { Navigation } from "@/src/lib/navigation/Navigation" import { toast } from "@/src/lib/toast" import { FollowScreen } from "@/src/screens/(modal)/FollowScreen" import { FeedScreen } from "@/src/screens/(stack)/feeds/[feedId]/FeedScreen" -import { useEntryIdsByFeedId, usePrefetchEntries } from "@/src/store/entry/hooks" -import { getFeed } from "@/src/store/feed/getter" -import { getSubscription } from "@/src/store/subscription/getter" -import { getSubscriptionCategory } from "@/src/store/subscription/hooks" -import { subscriptionSyncService } from "@/src/store/subscription/store" -import { unreadSyncService } from "@/src/store/unread/store" import { ItemSeparator } from "../entry-list/ItemSeparator" import { EntryNormalItem } from "../entry-list/templates/EntryNormalItem" @@ -339,7 +340,8 @@ export const SubscriptionFeedCategoryContextMenu = ({ const PreviewFeeds = (props: { id: string; view: FeedViewType }) => { const { id: feedId } = props const entryIds = useEntryIdsByFeedId(feedId) - const { isLoading } = usePrefetchEntries({ feedId, limit: 5 }) + const options = useFetchEntriesSettings() + const { isLoading } = usePrefetchEntries({ feedId, limit: 5, ...options }) const renderItem = useCallback( ({ item: id }: ListRenderItemInfo) => ( diff --git a/apps/mobile/src/modules/context-menu/inbox.tsx b/apps/mobile/src/modules/context-menu/inbox.tsx index 0787003fa..65ebd517d 100644 --- a/apps/mobile/src/modules/context-menu/inbox.tsx +++ b/apps/mobile/src/modules/context-menu/inbox.tsx @@ -1,10 +1,10 @@ +import { useInbox } from "@follow/store/src/inbox/hooks" import { setStringAsync } from "expo-clipboard" import type { PropsWithChildren } from "react" import { useTranslation } from "react-i18next" import { ContextMenu } from "@/src/components/ui/context-menu" import { toast } from "@/src/lib/toast" -import { useInbox } from "@/src/store/inbox/hooks" type InboxContextMenuProps = PropsWithChildren<{ inboxId: string diff --git a/apps/mobile/src/modules/context-menu/lists.tsx b/apps/mobile/src/modules/context-menu/lists.tsx index 95a176a99..4272720b7 100644 --- a/apps/mobile/src/modules/context-menu/lists.tsx +++ b/apps/mobile/src/modules/context-menu/lists.tsx @@ -1,4 +1,6 @@ import { env } from "@follow/shared/src/env.rn" +import { getList } from "@follow/store/src/list/getters" +import { subscriptionSyncService } from "@follow/store/src/subscription/store" import type { FC, PropsWithChildren } from "react" import { useMemo } from "react" import { useTranslation } from "react-i18next" @@ -8,8 +10,6 @@ import { ContextMenu } from "@/src/components/ui/context-menu" import { useNavigation } from "@/src/lib/navigation/hooks" import { toast } from "@/src/lib/toast" import { FollowScreen } from "@/src/screens/(modal)/FollowScreen" -import { getList } from "@/src/store/list/getters" -import { subscriptionSyncService } from "@/src/store/subscription/store" export const SubscriptionListItemContextMenu: FC< PropsWithChildren & { diff --git a/apps/mobile/src/modules/context-menu/video.tsx b/apps/mobile/src/modules/context-menu/video.tsx index 1f083450d..9534eef70 100644 --- a/apps/mobile/src/modules/context-menu/video.tsx +++ b/apps/mobile/src/modules/context-menu/video.tsx @@ -1,14 +1,14 @@ import { FeedViewType } from "@follow/constants" +import { useIsEntryStarred } from "@follow/store/src/collection/hooks" +import { collectionSyncService } from "@follow/store/src/collection/store" +import { useEntry } from "@follow/store/src/entry/hooks" +import { unreadSyncService } from "@follow/store/src/unread/store" import type { PropsWithChildren } from "react" import { useTranslation } from "react-i18next" import { Share } from "react-native" import { ContextMenu } from "@/src/components/ui/context-menu" import { toast } from "@/src/lib/toast" -import { useIsEntryStarred } from "@/src/store/collection/hooks" -import { collectionSyncService } from "@/src/store/collection/store" -import { useEntry } from "@/src/store/entry/hooks" -import { unreadSyncService } from "@/src/store/unread/store" type VideoContextMenuProps = PropsWithChildren<{ entryId: string diff --git a/apps/mobile/src/modules/dialogs/MarkAllAsReadDialog.tsx b/apps/mobile/src/modules/dialogs/MarkAllAsReadDialog.tsx index e72d85820..eb73fbc4d 100644 --- a/apps/mobile/src/modules/dialogs/MarkAllAsReadDialog.tsx +++ b/apps/mobile/src/modules/dialogs/MarkAllAsReadDialog.tsx @@ -1,14 +1,14 @@ +import { unreadSyncService } from "@follow/store/src/unread/store" import { t } from "i18next" import { useTranslation } from "react-i18next" import { Text, View } from "react-native" +import { getHideAllReadSubscriptions } from "@/src/atoms/settings/general" import { CheckCircleCuteReIcon } from "@/src/icons/check_circle_cute_re" import type { DialogComponent } from "@/src/lib/dialog" import { Dialog } from "@/src/lib/dialog" -import { getFetchEntryPayload } from "@/src/store/entry/getter" -import { unreadSyncService } from "@/src/store/unread/store" -import { useSelectedFeed, useSelectedView } from "../screen/atoms" +import { getFetchEntryPayload, useSelectedFeed, useSelectedView } from "../screen/atoms" export const MarkAllAsReadDialog: DialogComponent = () => { const { t } = useTranslation() @@ -25,7 +25,11 @@ export const MarkAllAsReadDialog: DialogComponent = () => { if (typeof selectedView === "number") { const payload = getFetchEntryPayload(selectedFeed, selectedView) - unreadSyncService.markViewAsRead({ view: selectedView, filter: payload }) + unreadSyncService.markViewAsRead({ + view: selectedView, + filter: payload, + excludePrivate: getHideAllReadSubscriptions(), + }) } }} /> diff --git a/apps/mobile/src/modules/discover/search-tabs/SearchFeedCard.tsx b/apps/mobile/src/modules/discover/search-tabs/SearchFeedCard.tsx index acb7f0509..347c03af6 100644 --- a/apps/mobile/src/modules/discover/search-tabs/SearchFeedCard.tsx +++ b/apps/mobile/src/modules/discover/search-tabs/SearchFeedCard.tsx @@ -1,3 +1,4 @@ +import { useSubscriptionByFeedId } from "@follow/store/src/subscription/hooks" import { Text, View } from "react-native" import { RelativeDateTime } from "@/src/components/ui/datetime/RelativeDateTime" @@ -5,7 +6,6 @@ import { SafeAlertCuteReIcon } from "@/src/icons/safe_alert_cute_re" import { SafetyCertificateCuteReIcon } from "@/src/icons/safety_certificate_cute_re" import { User3CuteReIcon } from "@/src/icons/user_3_cute_re" import type { apiClient } from "@/src/lib/api-fetch" -import { useSubscriptionByFeedId } from "@/src/store/subscription/hooks" import { useColor } from "@/src/theme/colors" import { FeedSummary } from "../FeedSummary" diff --git a/apps/mobile/src/modules/discover/search-tabs/SearchList.tsx b/apps/mobile/src/modules/discover/search-tabs/SearchList.tsx index 15174345d..e8939160b 100644 --- a/apps/mobile/src/modules/discover/search-tabs/SearchList.tsx +++ b/apps/mobile/src/modules/discover/search-tabs/SearchList.tsx @@ -1,3 +1,4 @@ +import { useSubscriptionByListId } from "@follow/store/src/subscription/hooks" import { useQuery } from "@tanstack/react-query" import { useAtomValue } from "jotai" import { memo } from "react" @@ -13,7 +14,6 @@ import { apiClient } from "@/src/lib/api-fetch" import { useNavigation } from "@/src/lib/navigation/hooks" import { UrlBuilder } from "@/src/lib/url-builder" import { FollowScreen } from "@/src/screens/(modal)/FollowScreen" -import { useSubscriptionByListId } from "@/src/store/subscription/hooks" import { useColor } from "@/src/theme/colors" import { useSearchPageContext } from "../ctx" diff --git a/apps/mobile/src/modules/entry-content/EntryAISummary.tsx b/apps/mobile/src/modules/entry-content/EntryAISummary.tsx index 023948d40..4cca1c2db 100644 --- a/apps/mobile/src/modules/entry-content/EntryAISummary.tsx +++ b/apps/mobile/src/modules/entry-content/EntryAISummary.tsx @@ -1,11 +1,11 @@ +import { useEntry } from "@follow/store/src/entry/hooks" +import { SummaryGeneratingStatus } from "@follow/store/src/summary/enum" +import { usePrefetchSummary, useSummary } from "@follow/store/src/summary/hooks" +import { useSummaryStore } from "@follow/store/src/summary/store" import { useAtomValue } from "jotai" import type { FC } from "react" -import { useGeneralSettingKey } from "@/src/atoms/settings/general" -import { useEntry } from "@/src/store/entry/hooks" -import { SummaryGeneratingStatus } from "@/src/store/summary/enum" -import { usePrefetchSummary, useSummary } from "@/src/store/summary/hooks" -import { useSummaryStore } from "@/src/store/summary/store" +import { useActionLanguage, useGeneralSettingKey } from "@/src/atoms/settings/general" import { AISummary } from "../ai/summary" import { useEntryContentContext } from "./ctx" @@ -19,13 +19,13 @@ export const EntryAISummary: FC<{ const showAISummary = useGeneralSettingKey("summary") || showAISummaryOnce const entryReadabilityContent = useEntry(entryId, (state) => state.readabilityContent) const summary = useSummary(entryId) - usePrefetchSummary( + const actionLanguage = useActionLanguage() + usePrefetchSummary({ entryId, - showReadability && entryReadabilityContent ? "readabilityContent" : "content", - { - enabled: showAISummary, - }, - ) + target: showReadability && entryReadabilityContent ? "readabilityContent" : "content", + actionLanguage, + enabled: showAISummary, + }) const summaryToShow = showReadability ? summary?.readabilitySummary || summary?.summary : summary?.summary diff --git a/apps/mobile/src/modules/entry-content/EntryContentHeaderRightActions.tsx b/apps/mobile/src/modules/entry-content/EntryContentHeaderRightActions.tsx index d61934680..67d9419a1 100644 --- a/apps/mobile/src/modules/entry-content/EntryContentHeaderRightActions.tsx +++ b/apps/mobile/src/modules/entry-content/EntryContentHeaderRightActions.tsx @@ -1,3 +1,11 @@ +import { useIsEntryStarred } from "@follow/store/src/collection/hooks" +import { collectionSyncService } from "@follow/store/src/collection/store" +import { useEntry } from "@follow/store/src/entry/hooks" +import { entrySyncServices } from "@follow/store/src/entry/store" +import { useFeed } from "@follow/store/src/feed/hooks" +import { useSubscription } from "@follow/store/src/subscription/hooks" +import { summaryActions, summarySyncService } from "@follow/store/src/summary/store" +import { translationSyncService } from "@follow/store/src/translation/store" import { setStringAsync } from "expo-clipboard" import { useAtom } from "jotai" import { useCallback, useEffect, useState } from "react" @@ -20,14 +28,7 @@ import { StarCuteReIcon } from "@/src/icons/star_cute_re" import { Translate2CuteReIcon } from "@/src/icons/translate_2_cute_re" import { hideIntelligenceGlowEffect, openLink, showIntelligenceGlowEffect } from "@/src/lib/native" import { toast } from "@/src/lib/toast" -import { useIsEntryStarred } from "@/src/store/collection/hooks" -import { collectionSyncService } from "@/src/store/collection/store" -import { useEntry } from "@/src/store/entry/hooks" -import { entrySyncServices } from "@/src/store/entry/store" -import { useFeed } from "@/src/store/feed/hooks" -import { useSubscription } from "@/src/store/subscription/hooks" -import { summaryActions, summarySyncService } from "@/src/store/summary/store" -import { translationSyncService } from "@/src/store/translation/store" +import { checkLanguage } from "@/src/lib/translation" import { useEntryContentContext } from "./ctx" @@ -115,10 +116,11 @@ const HeaderRightActionsImpl = ({ if (hasSummary) return const hideGlowEffect = showIntelligenceGlowEffect() - await summarySyncService.generateSummary( + await summarySyncService.generateSummary({ entryId, - showReadability ? "readabilityContent" : "content", - ) + target: showReadability ? "readabilityContent" : "content", + actionLanguage: getActionLanguage(), + }) hideGlowEffect() } @@ -135,6 +137,7 @@ const HeaderRightActionsImpl = ({ language: getActionLanguage(), withContent: true, target: showReadability ? "readabilityContent" : "content", + checkLanguage, }) setShowTranslation((prev) => !prev) } diff --git a/apps/mobile/src/modules/entry-content/EntryGridFooter.tsx b/apps/mobile/src/modules/entry-content/EntryGridFooter.tsx index 6b04992d2..d6cb469b5 100644 --- a/apps/mobile/src/modules/entry-content/EntryGridFooter.tsx +++ b/apps/mobile/src/modules/entry-content/EntryGridFooter.tsx @@ -1,12 +1,13 @@ import { FeedViewType } from "@follow/constants" +import { useEntry } from "@follow/store/src/entry/hooks" +import { useFeed } from "@follow/store/src/feed/hooks" +import { useEntryTranslation } from "@follow/store/src/translation/hooks" import { cn } from "@follow/utils" import { Text, View } from "react-native" +import { useActionLanguage } from "@/src/atoms/settings/general" import { RelativeDateTime } from "@/src/components/ui/datetime/RelativeDateTime" import { FeedIcon } from "@/src/components/ui/icon/feed-icon" -import { useEntry } from "@/src/store/entry/hooks" -import { useFeed } from "@/src/store/feed/hooks" -import { useEntryTranslation } from "@/src/store/translation/hooks" import { EntryTranslation } from "../entry-list/templates/EntryTranslation" @@ -20,8 +21,8 @@ export const EntryGridFooter = ({ view: FeedViewType }) => { const entry = useEntry(entryId) - - const translation = useEntryTranslation(entryId) + const actionLanguage = useActionLanguage() + const translation = useEntryTranslation(entryId, actionLanguage) const feed = useFeed(entry?.feedId || "") if (!entry) return null diff --git a/apps/mobile/src/modules/entry-content/EntryNavigationHeader.tsx b/apps/mobile/src/modules/entry-content/EntryNavigationHeader.tsx index d5613d1c7..d5d633592 100644 --- a/apps/mobile/src/modules/entry-content/EntryNavigationHeader.tsx +++ b/apps/mobile/src/modules/entry-content/EntryNavigationHeader.tsx @@ -1,4 +1,5 @@ import { useTypeScriptHappyCallback } from "@follow/hooks" +import { useEntry } from "@follow/store/src/entry/hooks" import { useAtomValue } from "jotai" import type { FC } from "react" import { use, useState } from "react" @@ -17,7 +18,6 @@ import { useUISettingKey } from "@/src/atoms/settings/ui" import { DefaultHeaderBackButton } from "@/src/components/layouts/header/NavigationHeader" import { NavigationBlurEffectHeaderView } from "@/src/components/layouts/views/SafeNavigationScrollView" import { ScreenItemContext } from "@/src/lib/navigation/ScreenItemContext" -import { useEntry } from "@/src/store/entry/hooks" import { useHeaderHeight } from "../screen/hooks/useHeaderHeight" import { EntryContentContext } from "./ctx" diff --git a/apps/mobile/src/modules/entry-content/EntryReadHistory.tsx b/apps/mobile/src/modules/entry-content/EntryReadHistory.tsx index c6a39e970..ad9e613a9 100644 --- a/apps/mobile/src/modules/entry-content/EntryReadHistory.tsx +++ b/apps/mobile/src/modules/entry-content/EntryReadHistory.tsx @@ -1,3 +1,6 @@ +import { useEntry } from "@follow/store/src/entry/hooks" +import { isInboxEntry } from "@follow/store/src/entry/utils" +import { userActions } from "@follow/store/src/user/store" import { useQuery } from "@tanstack/react-query" import { Pressable, View } from "react-native" @@ -5,9 +8,6 @@ import { UserAvatar } from "@/src/components/ui/avatar/UserAvatar" import { apiClient } from "@/src/lib/api-fetch" import { useNavigation } from "@/src/lib/navigation/hooks" import { ProfileScreen } from "@/src/screens/(modal)/ProfileScreen" -import { useEntry } from "@/src/store/entry/hooks" -import { isInboxEntry } from "@/src/store/entry/utils" -import { userActions } from "@/src/store/user/store" export const EntryReadHistory = ({ entryId }: { entryId: string }) => { const entry = useEntry(entryId) diff --git a/apps/mobile/src/modules/entry-content/EntryTitle.tsx b/apps/mobile/src/modules/entry-content/EntryTitle.tsx index 23f8ab07e..3e4633da8 100644 --- a/apps/mobile/src/modules/entry-content/EntryTitle.tsx +++ b/apps/mobile/src/modules/entry-content/EntryTitle.tsx @@ -1,18 +1,20 @@ +import { useEntry } from "@follow/store/src/entry/hooks" +import { useFeed } from "@follow/store/src/feed/hooks" +import { useEntryTranslation } from "@follow/store/src/translation/hooks" import { useSetAtom } from "jotai" import { use } from "react" import { Text, View } from "react-native" +import { useActionLanguage } from "@/src/atoms/settings/general" import { UserAvatar } from "@/src/components/ui/avatar/UserAvatar" import { FeedIcon } from "@/src/components/ui/icon/feed-icon" import { EntryContentContext } from "@/src/modules/entry-content/ctx" -import { useEntry } from "@/src/store/entry/hooks" -import { useFeed } from "@/src/store/feed/hooks" -import { useEntryTranslation } from "@/src/store/translation/hooks" import { EntryTranslation } from "../entry-list/templates/EntryTranslation" export const EntryTitle = ({ title, entryId }: { title: string; entryId: string }) => { - const translation = useEntryTranslation(entryId) + const actionLanguage = useActionLanguage() + const translation = useEntryTranslation(entryId, actionLanguage) const { titleHeightAtom } = use(EntryContentContext) const setTitleHeight = useSetAtom(titleHeightAtom) diff --git a/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx b/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx index 051a301fa..53b29371b 100644 --- a/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx @@ -1,11 +1,13 @@ import type { FeedViewType } from "@follow/constants" +import { usePrefetchEntryTranslation } from "@follow/store/src/translation/hooks" import type { ListRenderItemInfo } from "@shopify/flash-list" import type { ElementRef } from "react" import { useCallback, useImperativeHandle, useMemo } from "react" import { View } from "react-native" +import { useActionLanguage, useGeneralSettingKey } from "@/src/atoms/settings/general" import { usePlayingUrl } from "@/src/lib/player" -import { usePrefetchEntryTranslation } from "@/src/store/translation/hooks" +import { checkLanguage } from "@/src/lib/translation" import { useFetchEntriesControls } from "../screen/atoms" import { TimelineSelectorList } from "../screen/TimelineSelectorList" @@ -53,7 +55,14 @@ export const EntryListContentArticle = ({ useImperativeHandle(forwardRef, () => ref.current!) - usePrefetchEntryTranslation({ entryIds: active ? viewableItems.map((item) => item.key) : [] }) + const translation = useGeneralSettingKey("translation") + const actionLanguage = useActionLanguage() + usePrefetchEntryTranslation({ + entryIds: active ? viewableItems.map((item) => item.key) : [], + language: actionLanguage, + translation, + checkLanguage, + }) return ( item.key) : [] }) + const translation = useGeneralSettingKey("translation") + const actionLanguage = useActionLanguage() + usePrefetchEntryTranslation({ + entryIds: active ? viewableItems.map((item) => item.key) : [], + language: actionLanguage, + checkLanguage, + translation, + }) return ( item.key) : [] }) + const translation = useGeneralSettingKey("translation") + const actionLanguage = useActionLanguage() + usePrefetchEntryTranslation({ + entryIds: active ? viewableItems.map((item) => item.key) : [], + language: actionLanguage, + translation, + checkLanguage, + }) return ( item.key) : [] }) + const translation = useGeneralSettingKey("translation") + const actionLanguage = useActionLanguage() + usePrefetchEntryTranslation({ + entryIds: active ? viewableItems.map((item) => item.key) : [], + language: actionLanguage, + translation, + checkLanguage, + }) const ListFooterComponent = useMemo( () => diff --git a/apps/mobile/src/modules/entry-list/EntryListFooter.tsx b/apps/mobile/src/modules/entry-list/EntryListFooter.tsx index d42da893a..710bcc39f 100644 --- a/apps/mobile/src/modules/entry-list/EntryListFooter.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListFooter.tsx @@ -1,12 +1,12 @@ +import { unreadSyncService } from "@follow/store/src/unread/store" import { useTranslation } from "react-i18next" import { Text, TouchableOpacity } from "react-native" +import { getHideAllReadSubscriptions } from "@/src/atoms/settings/general" import { CheckCircleCuteReIcon } from "@/src/icons/check_circle_cute_re" -import { getFetchEntryPayload } from "@/src/store/entry/getter" -import { unreadSyncService } from "@/src/store/unread/store" import { useColor } from "@/src/theme/colors" -import { useSelectedFeed, useSelectedView } from "../screen/atoms" +import { getFetchEntryPayload, useSelectedFeed, useSelectedView } from "../screen/atoms" import { ItemSeparator } from "./ItemSeparator" export const EntryListFooter = () => { @@ -23,7 +23,11 @@ export const EntryListFooter = () => { onPress={() => { if (typeof selectedView === "number") { const payload = getFetchEntryPayload(selectedFeed, selectedView) - unreadSyncService.markViewAsRead({ view: selectedView, filter: payload }) + unreadSyncService.markViewAsRead({ + view: selectedView, + filter: payload, + excludePrivate: getHideAllReadSubscriptions(), + }) } }} > @@ -49,7 +53,11 @@ export const GridEntryListFooter = () => { onPress={() => { if (typeof selectedView === "number") { const payload = getFetchEntryPayload(selectedFeed, selectedView) - unreadSyncService.markViewAsRead({ view: selectedView, filter: payload }) + unreadSyncService.markViewAsRead({ + view: selectedView, + filter: payload, + excludePrivate: getHideAllReadSubscriptions(), + }) } }} > diff --git a/apps/mobile/src/modules/entry-list/EntryListSelector.tsx b/apps/mobile/src/modules/entry-list/EntryListSelector.tsx index 81268b7cc..2b5f4a55e 100644 --- a/apps/mobile/src/modules/entry-list/EntryListSelector.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListSelector.tsx @@ -1,4 +1,5 @@ import { FeedViewType } from "@follow/constants" +import { useWhoami } from "@follow/store/src/user/hooks" import type { FlashList } from "@shopify/flash-list" import { useEffect } from "react" @@ -8,7 +9,6 @@ import { NoLoginInfo } from "@/src/components/common/NoLoginInfo" import { ListErrorView } from "@/src/components/errors/ListErrorView" import { useRegisterNavigationScrollView } from "@/src/components/layouts/tabbar/hooks" import { EntryListContentPicture } from "@/src/modules/entry-list/EntryListContentPicture" -import { useWhoami } from "@/src/store/user/hooks" import { useFetchEntriesControls } from "../screen/atoms" import { EntryListContentArticle } from "./EntryListContentArticle" diff --git a/apps/mobile/src/modules/entry-list/hooks.ts b/apps/mobile/src/modules/entry-list/hooks.ts index aae5e653f..f44645d54 100644 --- a/apps/mobile/src/modules/entry-list/hooks.ts +++ b/apps/mobile/src/modules/entry-list/hooks.ts @@ -1,13 +1,15 @@ +import { debouncedFetchEntryContentByStream } from "@follow/store/src/entry/store" +import { unreadSyncService } from "@follow/store/src/unread/store" import type { FlashList } from "@shopify/flash-list" import type ViewToken from "@shopify/flash-list/dist/viewability/ViewToken" +import { fetch as expoFetch } from "expo/fetch" import type { RefObject } from "react" import { use, useCallback, useEffect, useInsertionEffect, useMemo, useRef, useState } from "react" import type { NativeScrollEvent, NativeSyntheticEvent, ViewStyle } from "react-native" import { useEventCallback } from "usehooks-ts" import { useGeneralSettingKey } from "@/src/atoms/settings/general" -import { debouncedFetchEntryContentByStream } from "@/src/store/entry/store" -import { unreadSyncService } from "@/src/store/unread/store" +import { getCookie } from "@/src/lib/auth" import { PagerListVisibleContext, PagerListWillVisibleContext } from "../screen/PagerListContext" @@ -38,7 +40,10 @@ export function useOnViewableItemsChanged({ }) => void = useNonReactiveCallback(({ viewableItems, changed }) => { setViewableItems(viewableItems) - debouncedFetchEntryContentByStream(viewableItems.map((item) => stableIdExtractor(item))) + debouncedFetchEntryContentByStream( + viewableItems.map((item) => stableIdExtractor(item)), + { cookie: getCookie(), fetch: expoFetch as any }, + ) const removed = changed.filter((item) => !item.isViewable) if (orientation.current === "down") { diff --git a/apps/mobile/src/modules/entry-list/index.tsx b/apps/mobile/src/modules/entry-list/index.tsx index a3cb47ece..b11431747 100644 --- a/apps/mobile/src/modules/entry-list/index.tsx +++ b/apps/mobile/src/modules/entry-list/index.tsx @@ -1,16 +1,16 @@ import { FeedViewType } from "@follow/constants" -import { memo, useMemo } from "react" - -import { useSelectedFeed, useSelectedView } from "@/src/modules/screen/atoms" -import { PagerList } from "@/src/modules/screen/PagerList" -import { TimelineHeader } from "@/src/modules/screen/TimelineSelectorProvider" import { useEntryIdsByCategory, useEntryIdsByFeedId, useEntryIdsByInboxId, useEntryIdsByListId, useEntryIdsByView, -} from "@/src/store/entry/hooks" +} from "@follow/store/src/entry/hooks" +import { memo, useMemo } from "react" + +import { useSelectedFeed, useSelectedView } from "@/src/modules/screen/atoms" +import { PagerList } from "@/src/modules/screen/PagerList" +import { TimelineHeader } from "@/src/modules/screen/TimelineSelectorProvider" import { EntryListSelector } from "./EntryListSelector" diff --git a/apps/mobile/src/modules/entry-list/templates/EntryNormalItem.tsx b/apps/mobile/src/modules/entry-list/templates/EntryNormalItem.tsx index 455470f4c..733e80574 100644 --- a/apps/mobile/src/modules/entry-list/templates/EntryNormalItem.tsx +++ b/apps/mobile/src/modules/entry-list/templates/EntryNormalItem.tsx @@ -1,10 +1,16 @@ import { FeedViewType } from "@follow/constants" +import { useEntry } from "@follow/store/src/entry/hooks" +import type { EntryModel } from "@follow/store/src/entry/types" +import { getInboxFrom } from "@follow/store/src/entry/utils" +import { useFeed } from "@follow/store/src/feed/hooks" +import { useEntryTranslation } from "@follow/store/src/translation/hooks" import { tracker } from "@follow/tracker" import { cn, formatEstimatedMins, formatTimeToSeconds } from "@follow/utils" import { useVideoPlayer, VideoView } from "expo-video" import { memo, useCallback, useMemo, useRef, useState } from "react" import { StyleSheet, Text, View } from "react-native" +import { useActionLanguage } from "@/src/atoms/settings/general" import { useUISettingKey } from "@/src/atoms/settings/ui" import { ThemedBlurView } from "@/src/components/common/ThemedBlurView" import { preloadWebViewEntry } from "@/src/components/native/webview/EntryContentWebView" @@ -21,11 +27,6 @@ import { useNavigation } from "@/src/lib/navigation/hooks" import { isIOS } from "@/src/lib/platform" import { getAttachmentState, player } from "@/src/lib/player" import { EntryDetailScreen } from "@/src/screens/(stack)/entries/[entryId]/EntryDetailScreen" -import { useEntry } from "@/src/store/entry/hooks" -import type { EntryModel } from "@/src/store/entry/types" -import { getInboxFrom } from "@/src/store/entry/utils" -import { useFeed } from "@/src/store/feed/hooks" -import { useEntryTranslation } from "@/src/store/translation/hooks" import { EntryItemContextMenu } from "../../context-menu/entry" import { EntryItemSkeleton } from "../EntryListContentArticle" @@ -43,7 +44,8 @@ export const EntryNormalItem = memo( view: FeedViewType }) => { const entry = useEntry(entryId) - const translation = useEntryTranslation(entryId) + const actionLanguage = useActionLanguage() + const translation = useEntryTranslation(entryId, actionLanguage) const from = getInboxFrom(entry) const feed = useFeed(entry?.feedId as string) const navigation = useNavigation() diff --git a/apps/mobile/src/modules/entry-list/templates/EntryPictureItem.tsx b/apps/mobile/src/modules/entry-list/templates/EntryPictureItem.tsx index c309b07d9..94d596e9d 100644 --- a/apps/mobile/src/modules/entry-list/templates/EntryPictureItem.tsx +++ b/apps/mobile/src/modules/entry-list/templates/EntryPictureItem.tsx @@ -1,5 +1,8 @@ import { FeedViewType } from "@follow/constants" import type { MediaModel } from "@follow/database/src/schemas/types" +import { useEntry } from "@follow/store/src/entry/hooks" +import { getFeed } from "@follow/store/src/feed/getter" +import { unreadSyncService } from "@follow/store/src/unread/store" import { tracker } from "@follow/tracker" import { uniqBy } from "es-toolkit/compat" import { useMemo } from "react" @@ -9,9 +12,6 @@ import { showEntryGaleriaAccessory } from "@/src/components/native/GaleriaAccess import { preloadWebViewEntry } from "@/src/components/native/webview/EntryContentWebView" import { MediaCarousel } from "@/src/components/ui/carousel/MediaCarousel" import { getFeedIconSource } from "@/src/lib/image" -import { useEntry } from "@/src/store/entry/hooks" -import { getFeed } from "@/src/store/feed/getter" -import { unreadSyncService } from "@/src/store/unread/store" export function EntryPictureItem({ id }: { id: string }) { const item = useEntry(id) diff --git a/apps/mobile/src/modules/entry-list/templates/EntrySocialItem.tsx b/apps/mobile/src/modules/entry-list/templates/EntrySocialItem.tsx index 20d71484a..55065f37e 100644 --- a/apps/mobile/src/modules/entry-list/templates/EntrySocialItem.tsx +++ b/apps/mobile/src/modules/entry-list/templates/EntrySocialItem.tsx @@ -1,9 +1,13 @@ import { FeedViewType } from "@follow/constants" +import { useEntry } from "@follow/store/src/entry/hooks" +import { useFeed } from "@follow/store/src/feed/hooks" +import { useEntryTranslation } from "@follow/store/src/translation/hooks" +import { unreadSyncService } from "@follow/store/src/unread/store" import { tracker } from "@follow/tracker" import { memo, useCallback, useMemo } from "react" import { Pressable, Text, View } from "react-native" -import { useGeneralSettingKey } from "@/src/atoms/settings/general" +import { useActionLanguage, useGeneralSettingKey } from "@/src/atoms/settings/general" import { UserAvatar } from "@/src/components/ui/avatar/UserAvatar" import { RelativeDateTime } from "@/src/components/ui/datetime/RelativeDateTime" import { FeedIcon } from "@/src/components/ui/icon/feed-icon" @@ -16,10 +20,6 @@ import { VideoPlayer } from "@/src/components/ui/video/VideoPlayer" import { useNavigation } from "@/src/lib/navigation/hooks" import { EntryDetailScreen } from "@/src/screens/(stack)/entries/[entryId]/EntryDetailScreen" import { FeedScreen } from "@/src/screens/(stack)/feeds/[feedId]/FeedScreen" -import { useEntry } from "@/src/store/entry/hooks" -import { useFeed } from "@/src/store/feed/hooks" -import { useEntryTranslation } from "@/src/store/translation/hooks" -import { unreadSyncService } from "@/src/store/unread/store" import { EntryItemContextMenu } from "../../context-menu/entry" import { EntryItemSkeleton } from "../EntryListContentSocial" @@ -29,7 +29,8 @@ import { EntryTranslation } from "./EntryTranslation" export const EntrySocialItem = memo( ({ entryId, extraData }: { entryId: string; extraData: EntryExtraData }) => { const entry = useEntry(entryId) - const translation = useEntryTranslation(entryId) + const actionLanguage = useActionLanguage() + const translation = useEntryTranslation(entryId, actionLanguage) const feed = useFeed(entry?.feedId || "") diff --git a/apps/mobile/src/modules/entry-list/templates/EntryVideoItem.tsx b/apps/mobile/src/modules/entry-list/templates/EntryVideoItem.tsx index 51541a60e..0997713d4 100644 --- a/apps/mobile/src/modules/entry-list/templates/EntryVideoItem.tsx +++ b/apps/mobile/src/modules/entry-list/templates/EntryVideoItem.tsx @@ -1,4 +1,6 @@ import { FeedViewType } from "@follow/constants" +import { useEntry } from "@follow/store/src/entry/hooks" +import { unreadSyncService } from "@follow/store/src/unread/store" import { tracker } from "@follow/tracker" import { formatDuration, transformVideoUrl } from "@follow/utils" import { memo, useMemo } from "react" @@ -10,8 +12,6 @@ import { ItemPressableStyle } from "@/src/components/ui/pressable/enum" import { ItemPressable } from "@/src/components/ui/pressable/ItemPressable" import { openLink } from "@/src/lib/native" import { toast } from "@/src/lib/toast" -import { useEntry } from "@/src/store/entry/hooks" -import { unreadSyncService } from "@/src/store/unread/store" import { VideoContextMenu } from "../../context-menu/video" import { EntryGridFooter } from "../../entry-content/EntryGridFooter" diff --git a/apps/mobile/src/modules/feed/FollowFeed.tsx b/apps/mobile/src/modules/feed/FollowFeed.tsx index 601ed301b..ed92adcee 100644 --- a/apps/mobile/src/modules/feed/FollowFeed.tsx +++ b/apps/mobile/src/modules/feed/FollowFeed.tsx @@ -1,4 +1,8 @@ import { FeedViewType } from "@follow/constants" +import { useFeed, usePrefetchFeed, usePrefetchFeedByUrl } from "@follow/store/src/feed/hooks" +import { useSubscriptionByFeedId } from "@follow/store/src/subscription/hooks" +import { subscriptionSyncService } from "@follow/store/src/subscription/store" +import type { SubscriptionForm } from "@follow/store/src/subscription/types" import { zodResolver } from "@hookform/resolvers/zod" import { useEffect, useState } from "react" import { Controller, useForm } from "react-hook-form" @@ -22,10 +26,6 @@ import { useCanDismiss, useNavigation } from "@/src/lib/navigation/hooks" import { useSetModalScreenOptions } from "@/src/lib/navigation/ScreenOptionsContext" import { FeedSummary } from "@/src/modules/discover/FeedSummary" import { FeedViewSelector } from "@/src/modules/feed/view-selector" -import { useFeed, usePrefetchFeed, usePrefetchFeedByUrl } from "@/src/store/feed/hooks" -import { useSubscriptionByFeedId } from "@/src/store/subscription/hooks" -import { subscriptionSyncService } from "@/src/store/subscription/store" -import type { SubscriptionForm } from "@/src/store/subscription/types" const formSchema = z.object({ view: z.coerce.number(), diff --git a/apps/mobile/src/modules/list/FollowList.tsx b/apps/mobile/src/modules/list/FollowList.tsx index 14374f43a..59e8937e7 100644 --- a/apps/mobile/src/modules/list/FollowList.tsx +++ b/apps/mobile/src/modules/list/FollowList.tsx @@ -1,4 +1,8 @@ import { FeedViewType } from "@follow/constants" +import { useList } from "@follow/store/src/list/hooks" +import { listSyncServices } from "@follow/store/src/list/store" +import { useSubscriptionByListId } from "@follow/store/src/subscription/hooks" +import { subscriptionSyncService } from "@follow/store/src/subscription/store" import { zodResolver } from "@hookform/resolvers/zod" import { useQuery } from "@tanstack/react-query" import { useEffect } from "react" @@ -23,10 +27,6 @@ import { PowerIcon } from "@/src/icons/power" import { useNavigation, useScreenIsInSheetModal } from "@/src/lib/navigation/hooks" import { useSetModalScreenOptions } from "@/src/lib/navigation/ScreenOptionsContext" import { toast } from "@/src/lib/toast" -import { useList } from "@/src/store/list/hooks" -import { listSyncServices } from "@/src/store/list/store" -import { useSubscriptionByListId } from "@/src/store/subscription/hooks" -import { subscriptionSyncService } from "@/src/store/subscription/store" import { accentColor } from "@/src/theme/colors" import { FeedViewSelector } from "../feed/view-selector" diff --git a/apps/mobile/src/modules/player/PlayerTabBar.tsx b/apps/mobile/src/modules/player/PlayerTabBar.tsx index aa2ca5670..4332d1d7b 100644 --- a/apps/mobile/src/modules/player/PlayerTabBar.tsx +++ b/apps/mobile/src/modules/player/PlayerTabBar.tsx @@ -1,3 +1,4 @@ +import { usePrefetchImageColors } from "@follow/store/src/image/hooks" import { cn } from "@follow/utils" import { useAtomValue } from "jotai" import { use, useEffect } from "react" @@ -14,7 +15,6 @@ import { BottomTabContext } from "@/src/lib/navigation/bottom-tab/BottomTabConte import { useNavigation } from "@/src/lib/navigation/hooks" import { useActiveTrack } from "@/src/lib/player" import { PlayerScreen } from "@/src/screens/PlayerScreen" -import { usePrefetchImageColors } from "@/src/store/image/hooks" import { PlayPauseButton, SeekButton } from "./control" diff --git a/apps/mobile/src/modules/player/hooks.ts b/apps/mobile/src/modules/player/hooks.ts index 1c271a810..b56779726 100644 --- a/apps/mobile/src/modules/player/hooks.ts +++ b/apps/mobile/src/modules/player/hooks.ts @@ -1,8 +1,7 @@ +import { useImageColors } from "@follow/store/src/image/hooks" import { getLuminance, shadeColor } from "@follow/utils" import { useMemo } from "react" -import { useImageColors } from "@/src/store/image/hooks" - const defaultBackgroundColor = "#000000" export function useCoverGradient(url?: string) { diff --git a/apps/mobile/src/modules/screen/PagerList.ios.tsx b/apps/mobile/src/modules/screen/PagerList.ios.tsx index b3bc00cb6..52654443e 100644 --- a/apps/mobile/src/modules/screen/PagerList.ios.tsx +++ b/apps/mobile/src/modules/screen/PagerList.ios.tsx @@ -1,5 +1,6 @@ import type { FeedViewType } from "@follow/constants" import { useTypeScriptHappyCallback } from "@follow/hooks" +import { useViewWithSubscription } from "@follow/store/src/subscription/hooks" import { EventBus } from "@follow/utils/src/event-bus" import * as Haptics from "expo-haptics" import { useEffect, useId, useMemo, useRef, useState } from "react" @@ -7,7 +8,6 @@ import type { StyleProp, ViewStyle } from "react-native" import { PagerView } from "@/src/components/native/PagerView" import type { PagerRef } from "@/src/components/native/PagerView/specs" -import { useViewWithSubscription } from "@/src/store/subscription/hooks" import { selectTimeline, useSelectedFeed } from "./atoms" import { PagerListVisibleContext, PagerListWillVisibleContext } from "./PagerListContext" @@ -24,7 +24,7 @@ export function PagerList({ const activeViews = useViewWithSubscription() const activeViewIndex = useMemo( - () => activeViews.findIndex((view) => view.view === viewId), + () => activeViews.indexOf(viewId as FeedViewType), [activeViews, viewId], ) const pagerRef = useRef(null) @@ -32,7 +32,7 @@ export function PagerList({ useEffect(() => { return EventBus.subscribe("SELECT_TIMELINE", (data) => { if (data.target !== rid) { - pagerRef.current?.setPage(activeViews.findIndex((view) => view.view === data.view.viewId)) + pagerRef.current?.setPage(activeViews.indexOf(data.view.viewId)) } }) }, [activeViews, pagerRef, rid]) @@ -48,16 +48,16 @@ export function PagerList({ containerClassName="flex-1 absolute inset-0" containerStyle={style} onPageChange={(targetIndex) => { - selectTimeline({ type: "view", viewId: activeViews[targetIndex]!.view }, rid) + selectTimeline({ type: "view", viewId: activeViews[targetIndex]! }, rid) Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light) }} renderPage={useTypeScriptHappyCallback( (index) => ( - + - {renderItem(activeViews[index]!.view, index === activeViewIndex)} + {renderItem(activeViews[index]!, index === activeViewIndex)} ), diff --git a/apps/mobile/src/modules/screen/PagerList.tsx b/apps/mobile/src/modules/screen/PagerList.tsx index db7d40715..788500d10 100644 --- a/apps/mobile/src/modules/screen/PagerList.tsx +++ b/apps/mobile/src/modules/screen/PagerList.tsx @@ -1,4 +1,5 @@ import type { FeedViewType } from "@follow/constants" +import { useViewWithSubscription } from "@follow/store/src/subscription/hooks" import { EventBus } from "@follow/utils/src/event-bus" import * as Haptics from "expo-haptics" import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react" @@ -8,7 +9,6 @@ import PagerView from "react-native-pager-view" import { useSharedValue } from "react-native-reanimated" import { selectTimeline, useSelectedFeed } from "@/src/modules/screen/atoms" -import { useViewWithSubscription } from "@/src/store/subscription/hooks" import { PagerListVisibleContext, PagerListWillVisibleContext } from "./PagerListContext" @@ -27,7 +27,7 @@ export function PagerList({ const activeViews = useViewWithSubscription() const activeViewIndex = useMemo( - () => activeViews.findIndex((view) => view.view === viewId), + () => activeViews.indexOf(viewId as FeedViewType), [activeViews, viewId], ) @@ -37,7 +37,7 @@ export function PagerList({ useEffect(() => { return EventBus.subscribe("SELECT_TIMELINE", (data) => { if (data.target !== rid) { - pagerRef.current?.setPage(activeViews.findIndex((view) => view.view === data.view.viewId)) + pagerRef.current?.setPage(activeViews.indexOf(data.view.viewId)) } }) }, [activeViews, pagerRef, rid]) @@ -70,7 +70,7 @@ export function PagerList({ } if (targetIndex !== activeViewIndex) { - selectTimeline({ type: "view", viewId: activeViews[targetIndex]!.view }, rid) + selectTimeline({ type: "view", viewId: activeViews[targetIndex]! }, rid) userInitiatedDragRef.value = false } }, @@ -105,11 +105,11 @@ export function PagerList({ {useMemo( () => activeViews.map((view, index) => ( - + - {renderItem(view.view, index === activeViewIndex)} + {renderItem(view, index === activeViewIndex)} )), diff --git a/apps/mobile/src/modules/screen/TimelineSelectorList.tsx b/apps/mobile/src/modules/screen/TimelineSelectorList.tsx index d8e406844..ace46cabf 100644 --- a/apps/mobile/src/modules/screen/TimelineSelectorList.tsx +++ b/apps/mobile/src/modules/screen/TimelineSelectorList.tsx @@ -1,4 +1,6 @@ import { useTypeScriptHappyCallback } from "@follow/hooks" +import { usePrefetchSubscription } from "@follow/store/src/subscription/hooks" +import { usePrefetchUnread } from "@follow/store/src/unread/hooks" import { nextFrame } from "@follow/utils" import type { FlashListProps, @@ -17,8 +19,6 @@ import { useColor } from "react-native-uikit-colors" import { useBottomTabBarHeight } from "@/src/components/layouts/tabbar/hooks" import { ScreenItemContext } from "@/src/lib/navigation/ScreenItemContext" import { useHeaderHeight } from "@/src/modules/screen/hooks/useHeaderHeight" -import { usePrefetchSubscription } from "@/src/store/subscription/hooks" -import { usePrefetchUnread } from "@/src/store/unread/hooks" import { EntryListEmpty } from "../entry-list/EntryListEmpty" diff --git a/apps/mobile/src/modules/screen/TimelineViewSelector.tsx b/apps/mobile/src/modules/screen/TimelineViewSelector.tsx index e8e97b2bf..b3469ec78 100644 --- a/apps/mobile/src/modules/screen/TimelineViewSelector.tsx +++ b/apps/mobile/src/modules/screen/TimelineViewSelector.tsx @@ -1,3 +1,5 @@ +import { useViewWithSubscription } from "@follow/store/src/subscription/hooks" +import { useUnreadCountByView } from "@follow/store/src/unread/hooks" import * as React from "react" import { useEffect } from "react" import { useTranslation } from "react-i18next" @@ -9,9 +11,8 @@ import { ReAnimatedPressable } from "@/src/components/common/AnimatedComponents" import { gentleSpringPreset } from "@/src/constants/spring" import { TIMELINE_VIEW_SELECTOR_HEIGHT } from "@/src/constants/ui" import type { ViewDefinition } from "@/src/constants/views" +import { views } from "@/src/constants/views" import { selectTimeline, useSelectedFeed } from "@/src/modules/screen/atoms" -import { useViewWithSubscription } from "@/src/store/subscription/hooks" -import { useUnreadCountByView } from "@/src/store/unread/hooks" import { useColor } from "@/src/theme/colors" import { UnreadCount } from "../subscription/items/UnreadCount" @@ -37,14 +38,18 @@ export function TimelineViewSelector() { contentContainerClassName="flex-row gap-3 items-center px-3" showsHorizontalScrollIndicator={false} > - {activeViews.map((view) => ( - - ))} + {activeViews.map((v) => { + const view = views.find((view) => view.view === v) + if (!view) return null + return ( + + ) + })} ) diff --git a/apps/mobile/src/modules/screen/TimelineViewSelectorContextMenu.tsx b/apps/mobile/src/modules/screen/TimelineViewSelectorContextMenu.tsx index bf6418667..efbe5d712 100644 --- a/apps/mobile/src/modules/screen/TimelineViewSelectorContextMenu.tsx +++ b/apps/mobile/src/modules/screen/TimelineViewSelectorContextMenu.tsx @@ -1,9 +1,10 @@ import type { FeedViewType } from "@follow/constants" +import { unreadSyncService } from "@follow/store/src/unread/store" import type { FC, PropsWithChildren } from "react" import { useTranslation } from "react-i18next" +import { getHideAllReadSubscriptions } from "@/src/atoms/settings/general" import { ContextMenu } from "@/src/components/ui/context-menu" -import { unreadSyncService } from "@/src/store/unread/store" export const TimelineViewSelectorContextMenu: FC< PropsWithChildren<{ type: string | undefined; viewId: FeedViewType | undefined }> @@ -18,7 +19,10 @@ export const TimelineViewSelectorContextMenu: FC< { - unreadSyncService.markViewAsRead({ view: viewId }) + unreadSyncService.markViewAsRead({ + view: viewId, + excludePrivate: getHideAllReadSubscriptions(), + }) }} > {t("operation.mark_as_read")} diff --git a/apps/mobile/src/modules/screen/action.tsx b/apps/mobile/src/modules/screen/action.tsx index 79a683c51..38aefea2c 100644 --- a/apps/mobile/src/modules/screen/action.tsx +++ b/apps/mobile/src/modules/screen/action.tsx @@ -1,3 +1,5 @@ +import { getFeed } from "@follow/store/src/feed/getter" +import { useWhoami } from "@follow/store/src/user/hooks" import { cn } from "@follow/utils" import * as Haptics from "expo-haptics" import type { PropsWithChildren } from "react" @@ -18,8 +20,6 @@ import { proxyEnv } from "@/src/lib/proxy-env" import { toast } from "@/src/lib/toast" import { LoginScreen } from "@/src/screens/(modal)/LoginScreen" import { ProfileScreen } from "@/src/screens/(modal)/ProfileScreen" -import { getFeed } from "@/src/store/feed/getter" -import { useWhoami } from "@/src/store/user/hooks" import { accentColor, useColor } from "@/src/theme/colors" import { MarkAllAsReadDialog } from "../dialogs/MarkAllAsReadDialog" diff --git a/apps/mobile/src/modules/screen/atoms.ts b/apps/mobile/src/modules/screen/atoms.ts index abfb2b401..1e15657e9 100644 --- a/apps/mobile/src/modules/screen/atoms.ts +++ b/apps/mobile/src/modules/screen/atoms.ts @@ -1,4 +1,11 @@ import { FeedViewType } from "@follow/constants" +import { usePrefetchEntries } from "@follow/store/src/entry/hooks" +import type { FetchEntriesProps } from "@follow/store/src/entry/types" +import { FEED_COLLECTION_LIST } from "@follow/store/src/entry/utils" +import { useFeed } from "@follow/store/src/feed/hooks" +import { useInbox } from "@follow/store/src/inbox/hooks" +import { useList } from "@follow/store/src/list/hooks" +import { getSubscriptionByCategory } from "@follow/store/src/subscription/getter" import { jotaiStore } from "@follow/utils" import { EventBus } from "@follow/utils/src/event-bus" import { atom, useAtomValue } from "jotai" @@ -6,13 +13,8 @@ import { selectAtom } from "jotai/utils" import { createContext, use, useMemo, useState } from "react" import { useTranslation } from "react-i18next" +import { useFetchEntriesSettings } from "@/src/atoms/settings/general" import { views } from "@/src/constants/views" -import { getFetchEntryPayload } from "@/src/store/entry/getter" -import { usePrefetchEntries } from "@/src/store/entry/hooks" -import { FEED_COLLECTION_LIST } from "@/src/store/entry/utils" -import { useFeed } from "@/src/store/feed/hooks" -import { useInbox } from "@/src/store/inbox/hooks" -import { useList } from "@/src/store/list/hooks" export type SelectedTimeline = { type: "view" @@ -87,12 +89,57 @@ export function useSelectedFeed( ) } +export const getFetchEntryPayload = ( + selectedFeed: SelectedTimeline | SelectedFeed, + view: FeedViewType = FeedViewType.Articles, +): FetchEntriesProps | null => { + if (!selectedFeed) { + return null + } + + let payload: FetchEntriesProps = {} + switch (selectedFeed.type) { + case "view": { + payload = { view: selectedFeed.viewId } + break + } + case "feed": { + payload = { feedId: selectedFeed.feedId } + break + } + case "category": { + payload = { + feedIdList: getSubscriptionByCategory({ category: selectedFeed.categoryName, view }), + } + break + } + case "list": { + payload = { listId: selectedFeed.listId } + break + } + case "inbox": { + payload = { inboxId: selectedFeed.inboxId } + break + } + // No default + } + const isCollection = + selectedFeed && selectedFeed.type === "feed" && selectedFeed?.feedId === FEED_COLLECTION_LIST + if (isCollection) { + payload.view = view + payload.isCollection = true + } + + return payload +} + export function useFetchEntriesControls() { const selectedFeed = useSelectedFeed() const view = useSelectedView() const payload = getFetchEntryPayload(selectedFeed, view) - return usePrefetchEntries(payload) + const options = useFetchEntriesSettings() + return usePrefetchEntries({ ...payload, ...options }) } export const useSelectedFeedTitle = () => { diff --git a/apps/mobile/src/modules/settings/SettingsList.tsx b/apps/mobile/src/modules/settings/SettingsList.tsx index 740f29c6c..27b6322ac 100644 --- a/apps/mobile/src/modules/settings/SettingsList.tsx +++ b/apps/mobile/src/modules/settings/SettingsList.tsx @@ -1,5 +1,6 @@ import { UserRole } from "@follow/constants" import type { ServerConfigs } from "@follow/models/src/types" +import { useRole, useWhoami } from "@follow/store/src/user/hooks" import * as FileSystem from "expo-file-system" import type { ParseKeys } from "i18next" import type { FC } from "react" @@ -30,7 +31,6 @@ import { signOut } from "@/src/lib/auth" import { useNavigation } from "@/src/lib/navigation/hooks" import type { Navigation } from "@/src/lib/navigation/Navigation" import { InvitationScreen } from "@/src/screens/(modal)/InvitationScreen" -import { useRole, useWhoami } from "@/src/store/user/hooks" import { AboutScreen } from "./routes/About" import { AccountScreen } from "./routes/Account" diff --git a/apps/mobile/src/modules/settings/UserHeaderBanner.tsx b/apps/mobile/src/modules/settings/UserHeaderBanner.tsx index 14b528c1e..5bb4c409a 100644 --- a/apps/mobile/src/modules/settings/UserHeaderBanner.tsx +++ b/apps/mobile/src/modules/settings/UserHeaderBanner.tsx @@ -1,3 +1,5 @@ +import { useImageColors, usePrefetchImageColors } from "@follow/store/src/image/hooks" +import { useUser } from "@follow/store/src/user/hooks" import { cn, getLuminance } from "@follow/utils" import { LinearGradient } from "expo-linear-gradient" import { useMemo } from "react" @@ -10,8 +12,6 @@ import { useColor } from "react-native-uikit-colors" import { UserAvatar } from "@/src/components/ui/avatar/UserAvatar" import { useNavigation } from "@/src/lib/navigation/hooks" import { LoginScreen } from "@/src/screens/(modal)/LoginScreen" -import { useImageColors, usePrefetchImageColors } from "@/src/store/image/hooks" -import { useUser } from "@/src/store/user/hooks" const defaultGradientColors = ["#000", "#100", "#200"] diff --git a/apps/mobile/src/modules/settings/actions/constant.ts b/apps/mobile/src/modules/settings/actions/constant.ts index 3f6ca71a9..78d7e5d95 100644 --- a/apps/mobile/src/modules/settings/actions/constant.ts +++ b/apps/mobile/src/modules/settings/actions/constant.ts @@ -1,10 +1,10 @@ import type { ActionId } from "@follow/models/src/types" +import { actionActions } from "@follow/store/src/action/store" import type { ParseKeys } from "i18next" import type { SFSymbol } from "sf-symbols-typescript" import type { SupportedLanguages } from "@/src/lib/language" import type { Navigation } from "@/src/lib/navigation/Navigation" -import { actionActions } from "@/src/store/action/store" import { EditRewriteRulesScreen } from "../routes/EditRewriteRules" import { EditWebhooksScreen } from "../routes/EditWebhooks" diff --git a/apps/mobile/src/modules/settings/hooks/useTOTPModalWrapper.tsx b/apps/mobile/src/modules/settings/hooks/useTOTPModalWrapper.tsx index 963fa0985..f3c49c4d1 100644 --- a/apps/mobile/src/modules/settings/hooks/useTOTPModalWrapper.tsx +++ b/apps/mobile/src/modules/settings/hooks/useTOTPModalWrapper.tsx @@ -1,3 +1,4 @@ +import { useWhoami } from "@follow/store/src/user/hooks" import { useCallback } from "react" import Siblings from "react-native-root-siblings" @@ -5,7 +6,6 @@ import { getFetchErrorInfo } from "@/src/lib/error-parser" import { useNavigation } from "@/src/lib/navigation/hooks" import { toast } from "@/src/lib/toast" import { TwoFactorAuthScreen } from "@/src/screens/(modal)/TwoFactorAuthScreen" -import { useWhoami } from "@/src/store/user/hooks" import { OTPWindow } from "../components/OTPWindow" diff --git a/apps/mobile/src/modules/settings/routes/2FASetting.tsx b/apps/mobile/src/modules/settings/routes/2FASetting.tsx index c8aac4c19..869fa4f1a 100644 --- a/apps/mobile/src/modules/settings/routes/2FASetting.tsx +++ b/apps/mobile/src/modules/settings/routes/2FASetting.tsx @@ -1,3 +1,4 @@ +import { whoamiQueryKey } from "@follow/store/src/user/hooks" import { useMutation } from "@tanstack/react-query" import { useRef } from "react" import { KeyboardAvoidingView, Text, View } from "react-native" @@ -14,7 +15,6 @@ import { useNavigation } from "@/src/lib/navigation/hooks" import type { NavigationControllerView } from "@/src/lib/navigation/types" import { queryClient } from "@/src/lib/query-client" import { toast } from "@/src/lib/toast" -import { whoamiQueryKey } from "@/src/store/user/hooks" import { accentColor, useColor } from "@/src/theme/colors" const isAuthCodeValid = (code: string) => { diff --git a/apps/mobile/src/modules/settings/routes/Account.tsx b/apps/mobile/src/modules/settings/routes/Account.tsx index 7ddb4de9c..fbafc16dc 100644 --- a/apps/mobile/src/modules/settings/routes/Account.tsx +++ b/apps/mobile/src/modules/settings/routes/Account.tsx @@ -1,3 +1,5 @@ +import { useWhoami } from "@follow/store/src/user/hooks" +import { userSyncService } from "@follow/store/src/user/store" import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query" import * as FileSystem from "expo-file-system" import type { FC } from "react" @@ -36,8 +38,6 @@ import { loading } from "@/src/lib/loading" import { openLink } from "@/src/lib/native" import { useNavigation } from "@/src/lib/navigation/hooks" import { toast } from "@/src/lib/toast" -import { useWhoami } from "@/src/store/user/hooks" -import { userSyncService } from "@/src/store/user/store" import { ConfirmPasswordDialog } from "../../dialogs/ConfirmPasswordDialog" import { TwoFASetting } from "./2FASetting" diff --git a/apps/mobile/src/modules/settings/routes/Actions.tsx b/apps/mobile/src/modules/settings/routes/Actions.tsx index b541ac9f6..b8c5a3165 100644 --- a/apps/mobile/src/modules/settings/routes/Actions.tsx +++ b/apps/mobile/src/modules/settings/routes/Actions.tsx @@ -1,4 +1,11 @@ import type { ActionModel } from "@follow/models/src/types" +import { + useActionRules, + useIsActionDataDirty, + usePrefetchActions, + useUpdateActionsMutation, +} from "@follow/store/src/action/hooks" +import { actionActions } from "@follow/store/src/action/store" import { useCallback } from "react" import { useTranslation } from "react-i18next" import type { ListRenderItem } from "react-native" @@ -24,13 +31,7 @@ import { Switch } from "@/src/components/ui/switch/Switch" import { Book6CuteReIcon } from "@/src/icons/book_6_cute_re" import { Magic2CuteFiIcon } from "@/src/icons/magic_2_cute_fi" import { useNavigation } from "@/src/lib/navigation/hooks" -import { - useActionRules, - useIsActionDataDirty, - usePrefetchActions, - useUpdateActionsMutation, -} from "@/src/store/action/hooks" -import { actionActions } from "@/src/store/action/store" +import { toast } from "@/src/lib/toast" import { accentColor } from "@/src/theme/colors" import { EditRuleScreen } from "./EditRule" @@ -120,7 +121,16 @@ const NewRuleButton = () => { } const SaveRuleButton = ({ disabled }: { disabled?: boolean }) => { - const { mutate, isPending } = useUpdateActionsMutation() + const navigation = useNavigation() + const { mutate, isPending } = useUpdateActionsMutation({ + onSuccess() { + navigation.back() + toast.success("Actions saved") + }, + onError(errorMessage) { + toast.error(errorMessage) + }, + }) return ( { const { t } = useTranslation("settings") diff --git a/apps/mobile/src/modules/settings/routes/EditCondition.tsx b/apps/mobile/src/modules/settings/routes/EditCondition.tsx index de1e34e14..51559fb36 100644 --- a/apps/mobile/src/modules/settings/routes/EditCondition.tsx +++ b/apps/mobile/src/modules/settings/routes/EditCondition.tsx @@ -1,4 +1,6 @@ import type { ActionConditionIndex } from "@follow/models/src/types" +import { useActionRuleCondition } from "@follow/store/src/action/hooks" +import { actionActions } from "@follow/store/src/action/store" import { useMemo } from "react" import { useTranslation } from "react-i18next" import { Text, View } from "react-native" @@ -16,8 +18,6 @@ import { } from "@/src/components/ui/grouped/GroupedList" import { views } from "@/src/constants/views" import type { NavigationControllerView } from "@/src/lib/navigation/types" -import { useActionRuleCondition } from "@/src/store/action/hooks" -import { actionActions } from "@/src/store/action/store" import { accentColor } from "@/src/theme/colors" import { filterFieldOptions, filterOperatorOptions } from "../actions/constant" diff --git a/apps/mobile/src/modules/settings/routes/EditProfile.tsx b/apps/mobile/src/modules/settings/routes/EditProfile.tsx index 1d9822cc5..fd53d8b95 100644 --- a/apps/mobile/src/modules/settings/routes/EditProfile.tsx +++ b/apps/mobile/src/modules/settings/routes/EditProfile.tsx @@ -1,3 +1,7 @@ +import { useWhoami } from "@follow/store/src/user/hooks" +import type { MeModel } from "@follow/store/src/user/store" +import { userSyncService } from "@follow/store/src/user/store" +import type { UserProfileEditable } from "@follow/store/src/user/types" import { useMutation } from "@tanstack/react-query" import type { FC } from "react" import { useState } from "react" @@ -24,10 +28,6 @@ import { CloseCircleFillIcon } from "@/src/icons/close_circle_fill" import { useNavigation } from "@/src/lib/navigation/hooks" import { toast } from "@/src/lib/toast" import { EditEmailScreen } from "@/src/screens/(modal)/EditEmailScreen" -import { useWhoami } from "@/src/store/user/hooks" -import type { MeModel } from "@/src/store/user/store" -import { userSyncService } from "@/src/store/user/store" -import type { UserProfileEditable } from "@/src/store/user/types" import { accentColor } from "@/src/theme/colors" import { setAvatar } from "../utils" diff --git a/apps/mobile/src/modules/settings/routes/EditRewriteRules.tsx b/apps/mobile/src/modules/settings/routes/EditRewriteRules.tsx index 291f326b9..c76e24971 100644 --- a/apps/mobile/src/modules/settings/routes/EditRewriteRules.tsx +++ b/apps/mobile/src/modules/settings/routes/EditRewriteRules.tsx @@ -1,3 +1,5 @@ +import { useActionRule } from "@follow/store/src/action/hooks" +import { actionActions } from "@follow/store/src/action/store" import { useTranslation } from "react-i18next" import { Text } from "react-native" @@ -13,8 +15,6 @@ import { GroupedPlainButtonCell, } from "@/src/components/ui/grouped/GroupedList" import type { NavigationControllerView } from "@/src/lib/navigation/types" -import { useActionRule } from "@/src/store/action/hooks" -import { actionActions } from "@/src/store/action/store" export const EditRewriteRulesScreen: NavigationControllerView<{ index: number }> = ({ index }) => { const { t } = useTranslation("settings") diff --git a/apps/mobile/src/modules/settings/routes/EditRule.tsx b/apps/mobile/src/modules/settings/routes/EditRule.tsx index 38fcac306..dd3d0a462 100644 --- a/apps/mobile/src/modules/settings/routes/EditRule.tsx +++ b/apps/mobile/src/modules/settings/routes/EditRule.tsx @@ -1,4 +1,6 @@ import type { ActionFilter, ActionModel } from "@follow/models/src/types" +import { useActionRule } from "@follow/store/src/action/hooks" +import { actionActions } from "@follow/store/src/action/store" import { useTranslation } from "react-i18next" import { Text, View } from "react-native" import * as DropdownMenu from "zeego/dropdown-menu" @@ -20,8 +22,6 @@ import { import { views } from "@/src/constants/views" import { useNavigation } from "@/src/lib/navigation/hooks" import type { NavigationControllerView } from "@/src/lib/navigation/types" -import { useActionRule } from "@/src/store/action/hooks" -import { actionActions } from "@/src/store/action/store" import { accentColor, useColors } from "@/src/theme/colors" import { availableActionList, filterFieldOptions, filterOperatorOptions } from "../actions/constant" diff --git a/apps/mobile/src/modules/settings/routes/EditWebhooks.tsx b/apps/mobile/src/modules/settings/routes/EditWebhooks.tsx index d5ee3f7ab..15eede4ab 100644 --- a/apps/mobile/src/modules/settings/routes/EditWebhooks.tsx +++ b/apps/mobile/src/modules/settings/routes/EditWebhooks.tsx @@ -1,3 +1,5 @@ +import { useActionRule } from "@follow/store/src/action/hooks" +import { actionActions } from "@follow/store/src/action/store" import { useTranslation } from "react-i18next" import { Text } from "react-native" @@ -13,8 +15,6 @@ import { GroupedInsetListSectionHeader, } from "@/src/components/ui/grouped/GroupedList" import type { NavigationControllerView } from "@/src/lib/navigation/types" -import { useActionRule } from "@/src/store/action/hooks" -import { actionActions } from "@/src/store/action/store" export const EditWebhooksScreen: NavigationControllerView<{ index: number }> = ({ index }) => { const { t } = useTranslation("settings") diff --git a/apps/mobile/src/modules/settings/routes/Lists.tsx b/apps/mobile/src/modules/settings/routes/Lists.tsx index f2716523b..12a733751 100644 --- a/apps/mobile/src/modules/settings/routes/Lists.tsx +++ b/apps/mobile/src/modules/settings/routes/Lists.tsx @@ -1,3 +1,6 @@ +import { useOwnedLists, usePrefetchOwnedLists } from "@follow/store/src/list/hooks" +import type { ListModel } from "@follow/store/src/list/store" +import type { HonoApiClient } from "@follow/store/src/morph/types" import { createContext, createElement, use, useCallback, useMemo } from "react" import { useTranslation } from "react-i18next" import type { ListRenderItem } from "react-native" @@ -25,10 +28,7 @@ import { RadaCuteFiIcon } from "@/src/icons/rada_cute_fi" import { UserAdd2CuteFiIcon } from "@/src/icons/user_add_2_cute_fi" import { Wallet2CuteFiIcon } from "@/src/icons/wallet_2_cute_fi" import { useNavigation } from "@/src/lib/navigation/hooks" -import type { HonoApiClient } from "@/src/morph/types" import { ListScreen } from "@/src/screens/(modal)/ListScreen" -import { useOwnedLists, usePrefetchOwnedLists } from "@/src/store/list/hooks" -import type { ListModel } from "@/src/store/list/store" import { accentColor } from "@/src/theme/colors" import { SwipeableGroupProvider, SwipeableItem } from "../../../components/common/SwipeableItem" diff --git a/apps/mobile/src/modules/settings/routes/ManageList.tsx b/apps/mobile/src/modules/settings/routes/ManageList.tsx index 7b10e5328..32d5e0eee 100644 --- a/apps/mobile/src/modules/settings/routes/ManageList.tsx +++ b/apps/mobile/src/modules/settings/routes/ManageList.tsx @@ -1,3 +1,11 @@ +import { useFeed } from "@follow/store/src/feed/hooks" +import { useList, usePrefetchOwnedLists } from "@follow/store/src/list/hooks" +import { listSyncServices } from "@follow/store/src/list/store" +import { + useFeedSubscriptionByView, + usePrefetchSubscription, + useSortedFeedSubscriptionByAlphabet, +} from "@follow/store/src/subscription/hooks" import { useMutation } from "@tanstack/react-query" import type { MutableRefObject } from "react" import { createContext, use, useEffect, useMemo, useRef, useState } from "react" @@ -21,14 +29,6 @@ import { getBizFetchErrorMessage } from "@/src/lib/api-fetch" import { useNavigation } from "@/src/lib/navigation/hooks" import type { NavigationControllerView } from "@/src/lib/navigation/types" import { toast } from "@/src/lib/toast" -import { useFeed } from "@/src/store/feed/hooks" -import { useList, usePrefetchOwnedLists } from "@/src/store/list/hooks" -import { listSyncServices } from "@/src/store/list/store" -import { - useFeedSubscriptionByView, - usePrefetchSubscription, - useSortedFeedSubscriptionByAlphabet, -} from "@/src/store/subscription/hooks" import { accentColor } from "@/src/theme/colors" const ManageListContext = createContext<{ diff --git a/apps/mobile/src/modules/settings/utils.ts b/apps/mobile/src/modules/settings/utils.ts index 8378fef8a..515fca14e 100644 --- a/apps/mobile/src/modules/settings/utils.ts +++ b/apps/mobile/src/modules/settings/utils.ts @@ -1,3 +1,4 @@ +import { userSyncService } from "@follow/store/src/user/store" import * as DocumentPicker from "expo-document-picker" import * as FileSystem from "expo-file-system" import * as Sharing from "expo-sharing" @@ -6,7 +7,6 @@ import { getDbPath } from "@/src/database" import { apiClient, apiFetch, getBizFetchErrorMessage } from "@/src/lib/api-fetch" import { pickImage } from "@/src/lib/native/picker" import { toast } from "@/src/lib/toast" -import { userSyncService } from "@/src/store/user/store" export const setAvatar = async () => { const result = await pickImage({ diff --git a/apps/mobile/src/modules/subscription/CategoryGrouped.tsx b/apps/mobile/src/modules/subscription/CategoryGrouped.tsx index 83baf1684..965198803 100644 --- a/apps/mobile/src/modules/subscription/CategoryGrouped.tsx +++ b/apps/mobile/src/modules/subscription/CategoryGrouped.tsx @@ -1,3 +1,4 @@ +import { useUnreadCounts } from "@follow/store/src/unread/hooks" import { cn } from "@follow/utils" import { memo, useState } from "react" import { Text, View } from "react-native" @@ -11,7 +12,6 @@ import { RightCuteFiIcon } from "@/src/icons/right_cute_fi" import { useNavigation } from "@/src/lib/navigation/hooks" import { selectFeed } from "@/src/modules/screen/atoms" import { FeedScreen } from "@/src/screens/(stack)/feeds/[feedId]/FeedScreen" -import { useUnreadCounts } from "@/src/store/unread/hooks" import { useColor } from "@/src/theme/colors" import { SubscriptionFeedCategoryContextMenu } from "../context-menu/feeds" diff --git a/apps/mobile/src/modules/subscription/SubscriptionLists.tsx b/apps/mobile/src/modules/subscription/SubscriptionLists.tsx index c6011472a..686c4757e 100644 --- a/apps/mobile/src/modules/subscription/SubscriptionLists.tsx +++ b/apps/mobile/src/modules/subscription/SubscriptionLists.tsx @@ -1,4 +1,14 @@ import type { FeedViewType } from "@follow/constants" +import { FEED_COLLECTION_LIST } from "@follow/store/src/entry/utils" +import { + useGroupedSubscription, + useInboxSubscription, + useListSubscription, + useSortedGroupedSubscription, + useSortedListSubscription, + useSortedUngroupedSubscription, +} from "@follow/store/src/subscription/hooks" +import { subscriptionSyncService } from "@follow/store/src/subscription/store" import type { FlashList } from "@shopify/flash-list" import type { ParseKeys } from "i18next" import { memo, useMemo, useState } from "react" @@ -6,6 +16,7 @@ import { useTranslation } from "react-i18next" import { Text, View } from "react-native" import { useEventCallback } from "usehooks-ts" +import { useGeneralSettingKey, useHideAllReadSubscriptions } from "@/src/atoms/settings/general" import { useRegisterNavigationScrollView } from "@/src/components/layouts/tabbar/hooks" import { GROUPED_ICON_TEXT_GAP, @@ -22,16 +33,6 @@ import { useNavigation } from "@/src/lib/navigation/hooks" import { selectFeed } from "@/src/modules/screen/atoms" import { TimelineSelectorList } from "@/src/modules/screen/TimelineSelectorList" import { FeedScreen } from "@/src/screens/(stack)/feeds/[feedId]/FeedScreen" -import { FEED_COLLECTION_LIST } from "@/src/store/entry/utils" -import { - useGroupedSubscription, - useInboxSubscription, - useListSubscription, - useSortedGroupedSubscription, - useSortedListSubscription, - useSortedUngroupedSubscription, -} from "@/src/store/subscription/hooks" -import { subscriptionSyncService } from "@/src/store/subscription/store" import { usePagerListPerformanceHack } from "../entry-list/hooks" import { useFeedListSortMethod, useFeedListSortOrder } from "./atoms" @@ -54,17 +55,37 @@ const SubscriptionListImpl = ({ view: FeedViewType active?: boolean }) => { + const hideAllReadSubscriptions = useHideAllReadSubscriptions() + const autoGroup = useGeneralSettingKey("autoGroup") const listIds = useListSubscription(view) - const sortedListIds = useSortedListSubscription(listIds, "alphabet") + const sortedListIds = useSortedListSubscription({ + ids: listIds, + sortBy: "alphabet", + hideAllReadSubscriptions, + }) const inboxes = useInboxSubscription(view) - const { grouped, unGrouped } = useGroupedSubscription(view) + const { grouped, unGrouped } = useGroupedSubscription({ + view, + autoGroup, + }) const sortBy = useFeedListSortMethod() const sortOrder = useFeedListSortOrder() - const sortedGrouped = useSortedGroupedSubscription(view, grouped, sortBy, sortOrder) - const sortedUnGrouped = useSortedUngroupedSubscription(unGrouped, sortBy, sortOrder) + const sortedGrouped = useSortedGroupedSubscription({ + view, + grouped, + sortBy, + sortOrder, + hideAllReadSubscriptions, + }) + const sortedUnGrouped = useSortedUngroupedSubscription({ + ids: unGrouped, + sortBy, + sortOrder, + hideAllReadSubscriptions, + }) const data = useMemo( () => [ diff --git a/apps/mobile/src/modules/subscription/UnGroupedList.tsx b/apps/mobile/src/modules/subscription/UnGroupedList.tsx index 0e70aabdd..210a459d2 100644 --- a/apps/mobile/src/modules/subscription/UnGroupedList.tsx +++ b/apps/mobile/src/modules/subscription/UnGroupedList.tsx @@ -1,6 +1,7 @@ +import { useSortedUngroupedSubscription } from "@follow/store/src/subscription/hooks" import type { FC } from "react" -import { useSortedUngroupedSubscription } from "@/src/store/subscription/hooks" +import { useHideAllReadSubscriptions } from "@/src/atoms/settings/general" import { useFeedListSortMethod, useFeedListSortOrder } from "./atoms" import { SubscriptionItem } from "./items/SubscriptionItem" @@ -11,7 +12,13 @@ export const UnGroupedList: FC<{ }> = ({ subscriptionIds, isLastGroup }) => { const sortBy = useFeedListSortMethod() const sortOrder = useFeedListSortOrder() - const sortedSubscriptionIds = useSortedUngroupedSubscription(subscriptionIds, sortBy, sortOrder) + const hideAllReadSubscriptions = useHideAllReadSubscriptions() + const sortedSubscriptionIds = useSortedUngroupedSubscription({ + ids: subscriptionIds, + sortBy, + sortOrder, + hideAllReadSubscriptions, + }) return sortedSubscriptionIds.map((id, index) => ( { const { t } = useTranslation("settings") @@ -102,7 +102,9 @@ export const EditEmailScreen: NavigationControllerView = () => { } onPress={() => { setIsSendingVerificationEmail(true) - userSyncService.sendVerificationEmail() + userSyncService.sendVerificationEmail().then(() => { + toast.success("Verification email sent") + }) }} /> diff --git a/apps/mobile/src/screens/(modal)/InvitationScreen.tsx b/apps/mobile/src/screens/(modal)/InvitationScreen.tsx index 3b60a7d69..5f53691f6 100644 --- a/apps/mobile/src/screens/(modal)/InvitationScreen.tsx +++ b/apps/mobile/src/screens/(modal)/InvitationScreen.tsx @@ -1,3 +1,4 @@ +import { userSyncService } from "@follow/store/src/user/store" import { useMutation } from "@tanstack/react-query" import { useState } from "react" import { View } from "react-native" @@ -17,7 +18,6 @@ import { getBizFetchErrorMessage } from "@/src/lib/api-fetch" import { useNavigation } from "@/src/lib/navigation/hooks" import type { NavigationControllerView } from "@/src/lib/navigation/types" import { toast } from "@/src/lib/toast" -import { userSyncService } from "@/src/store/user/store" export const InvitationScreen: NavigationControllerView = () => { const [code, setCode] = useState("") diff --git a/apps/mobile/src/screens/(modal)/ListScreen.tsx b/apps/mobile/src/screens/(modal)/ListScreen.tsx index d0781914d..c15909410 100644 --- a/apps/mobile/src/screens/(modal)/ListScreen.tsx +++ b/apps/mobile/src/screens/(modal)/ListScreen.tsx @@ -1,5 +1,10 @@ import { useActionSheet } from "@expo/react-native-action-sheet" import { FeedViewType } from "@follow/constants" +import { getList } from "@follow/store/src/list/getters" +import { useList } from "@follow/store/src/list/hooks" +import type { ListModel } from "@follow/store/src/list/store" +import { listSyncServices } from "@follow/store/src/list/store" +import type { CreateListModel } from "@follow/store/src/list/types" import { zodResolver } from "@hookform/resolvers/zod" import { memo, useEffect, useState } from "react" import { Controller, useForm } from "react-hook-form" @@ -26,11 +31,6 @@ import { useSetModalScreenOptions } from "@/src/lib/navigation/ScreenOptionsCont import type { NavigationControllerView } from "@/src/lib/navigation/types" import { toast } from "@/src/lib/toast" import { FeedViewSelector } from "@/src/modules/feed/view-selector" -import { getList } from "@/src/store/list/getters" -import { useList } from "@/src/store/list/hooks" -import type { ListModel } from "@/src/store/list/store" -import { listSyncServices } from "@/src/store/list/store" -import type { CreateListModel } from "@/src/store/list/types" import { accentColor } from "@/src/theme/colors" const listSchema = z.object({ diff --git a/apps/mobile/src/screens/(modal)/LoginScreen.tsx b/apps/mobile/src/screens/(modal)/LoginScreen.tsx index 5409a4d28..1a60ef874 100644 --- a/apps/mobile/src/screens/(modal)/LoginScreen.tsx +++ b/apps/mobile/src/screens/(modal)/LoginScreen.tsx @@ -1,3 +1,4 @@ +import { useWhoami } from "@follow/store/src/user/hooks" import { Fragment, useEffect } from "react" import { ScrollView, Text, TouchableOpacity } from "react-native" @@ -6,7 +7,6 @@ import { Navigation } from "@/src/lib/navigation/Navigation" import type { NavigationControllerView } from "@/src/lib/navigation/types" import { useIsiPad } from "@/src/lib/platform" import { Login } from "@/src/modules/login" -import { useWhoami } from "@/src/store/user/hooks" function exit() { const router = Navigation.rootNavigation diff --git a/apps/mobile/src/screens/(modal)/ProfileScreen.tsx b/apps/mobile/src/screens/(modal)/ProfileScreen.tsx index 76c065bd6..81b937b4a 100644 --- a/apps/mobile/src/screens/(modal)/ProfileScreen.tsx +++ b/apps/mobile/src/screens/(modal)/ProfileScreen.tsx @@ -1,4 +1,10 @@ import type { FeedViewType } from "@follow/constants" +import type { FeedModel } from "@follow/store/src/feed/types" +import type { ListModel } from "@follow/store/src/list/store" +import { getSubscription } from "@follow/store/src/subscription/getter" +import { subscriptionSyncService } from "@follow/store/src/subscription/store" +import { useUser, useWhoami } from "@follow/store/src/user/hooks" +import { userSyncService } from "@follow/store/src/user/store" import { useQuery } from "@tanstack/react-query" import { createContext, Fragment, use, useCallback, useEffect, useMemo } from "react" import { useTranslation } from "react-i18next" @@ -41,12 +47,6 @@ import { toast } from "@/src/lib/toast" import { useShareSubscription } from "@/src/modules/settings/hooks/useShareSubscription" import { UserHeaderBanner } from "@/src/modules/settings/UserHeaderBanner" import { ItemSeparator } from "@/src/modules/subscription/ItemSeparator" -import type { FeedModel } from "@/src/store/feed/types" -import type { ListModel } from "@/src/store/list/store" -import { getSubscription } from "@/src/store/subscription/getter" -import { subscriptionSyncService } from "@/src/store/subscription/store" -import { useUser, useWhoami } from "@/src/store/user/hooks" -import { userSyncService } from "@/src/store/user/store" import { useColor } from "@/src/theme/colors" import { FeedScreen } from "../(stack)/feeds/[feedId]/FeedScreen" diff --git a/apps/mobile/src/screens/(modal)/RsshubFormScreen.tsx b/apps/mobile/src/screens/(modal)/RsshubFormScreen.tsx index 51435455c..458117545 100644 --- a/apps/mobile/src/screens/(modal)/RsshubFormScreen.tsx +++ b/apps/mobile/src/screens/(modal)/RsshubFormScreen.tsx @@ -1,4 +1,5 @@ import type { RSSHubParameter, RSSHubParameterObject, RSSHubRoute } from "@follow/models/src/rsshub" +import { feedSyncServices } from "@follow/store/src/feed/store" import { MissingOptionalParamError, parseFullPathParams, @@ -26,7 +27,6 @@ import { useNavigation } from "@/src/lib/navigation/hooks" import { useSetModalScreenOptions } from "@/src/lib/navigation/ScreenOptionsContext" import type { NavigationControllerView } from "@/src/lib/navigation/types" import { toast } from "@/src/lib/toast" -import { feedSyncServices } from "@/src/store/feed/store" import { FollowScreen } from "./FollowScreen" diff --git a/apps/mobile/src/screens/(modal)/TwoFactorAuthScreen.tsx b/apps/mobile/src/screens/(modal)/TwoFactorAuthScreen.tsx index 416cdf3fb..b72a0c362 100644 --- a/apps/mobile/src/screens/(modal)/TwoFactorAuthScreen.tsx +++ b/apps/mobile/src/screens/(modal)/TwoFactorAuthScreen.tsx @@ -1,3 +1,4 @@ +import { whoamiQueryKey } from "@follow/store/src/user/hooks" import { useMutation } from "@tanstack/react-query" import { useRef } from "react" import { Text, TouchableWithoutFeedback, View } from "react-native" @@ -13,7 +14,6 @@ import { useNavigation } from "@/src/lib/navigation/hooks" import type { NavigationControllerView } from "@/src/lib/navigation/types" import { queryClient } from "@/src/lib/query-client" import { toast } from "@/src/lib/toast" -import { whoamiQueryKey } from "@/src/store/user/hooks" import { accentColor } from "@/src/theme/colors" export const TwoFactorAuthScreen: NavigationControllerView = () => { diff --git a/apps/mobile/src/screens/(stack)/(tabs)/settings.tsx b/apps/mobile/src/screens/(stack)/(tabs)/settings.tsx index 87bc75a16..32b2ee201 100644 --- a/apps/mobile/src/screens/(stack)/(tabs)/settings.tsx +++ b/apps/mobile/src/screens/(stack)/(tabs)/settings.tsx @@ -1,3 +1,4 @@ +import { useWhoami } from "@follow/store/src/user/hooks" import { use } from "react" import { useTranslation } from "react-i18next" import type { ScrollView } from "react-native" @@ -18,7 +19,6 @@ import { ScreenItemContext } from "@/src/lib/navigation/ScreenItemContext" import { EditProfileScreen } from "@/src/modules/settings/routes/EditProfile" import { SettingsList } from "@/src/modules/settings/SettingsList" import { UserHeaderBanner } from "@/src/modules/settings/UserHeaderBanner" -import { useWhoami } from "@/src/store/user/hooks" export function Settings() { const insets = useSafeAreaInsets() diff --git a/apps/mobile/src/screens/(stack)/(tabs)/subscriptions.tsx b/apps/mobile/src/screens/(stack)/(tabs)/subscriptions.tsx index 4620206c5..500e553eb 100644 --- a/apps/mobile/src/screens/(stack)/(tabs)/subscriptions.tsx +++ b/apps/mobile/src/screens/(stack)/(tabs)/subscriptions.tsx @@ -1,4 +1,5 @@ import type { FeedViewType } from "@follow/constants" +import { useWhoami } from "@follow/store/src/user/hooks" import { useMemo } from "react" import { useColor } from "react-native-uikit-colors" @@ -13,7 +14,6 @@ import { EntryListContext } from "@/src/modules/screen/atoms" import { PagerList } from "@/src/modules/screen/PagerList" import { TimelineHeader } from "@/src/modules/screen/TimelineSelectorProvider" import { SubscriptionList } from "@/src/modules/subscription/SubscriptionLists" -import { useWhoami } from "@/src/store/user/hooks" export default function Subscriptions() { const whoami = useWhoami() diff --git a/apps/mobile/src/screens/(stack)/entries/[entryId]/EntryDetailScreen.tsx b/apps/mobile/src/screens/(stack)/entries/[entryId]/EntryDetailScreen.tsx index f568a871a..9a6561c0b 100644 --- a/apps/mobile/src/screens/(stack)/entries/[entryId]/EntryDetailScreen.tsx +++ b/apps/mobile/src/screens/(stack)/entries/[entryId]/EntryDetailScreen.tsx @@ -1,4 +1,13 @@ import { FeedViewType } from "@follow/constants" +import { useEntry, usePrefetchEntryDetail } from "@follow/store/src/entry/hooks" +import { entrySyncServices } from "@follow/store/src/entry/store" +import type { EntryWithTranslation } from "@follow/store/src/entry/types" +import { useFeed } from "@follow/store/src/feed/hooks" +import { + useEntryTranslation, + usePrefetchEntryTranslation, +} from "@follow/store/src/translation/hooks" +import { useAutoMarkAsRead } from "@follow/store/src/unread/hooks" import { PortalProvider } from "@gorhom/portal" import { atom, useAtomValue, useSetAtom } from "jotai" import { useCallback, useEffect, useMemo } from "react" @@ -6,7 +15,7 @@ import { Text, View } from "react-native" import { useSafeAreaInsets } from "react-native-safe-area-context" import { useColor } from "react-native-uikit-colors" -import { useGeneralSettingKey } from "@/src/atoms/settings/general" +import { useActionLanguage, useGeneralSettingKey } from "@/src/atoms/settings/general" import { BottomTabBarHeightContext } from "@/src/components/layouts/tabbar/contexts/BottomTabBarHeightContext" import { SafeNavigationScrollView } from "@/src/components/layouts/views/SafeNavigationScrollView" import { EntryContentWebView } from "@/src/components/native/webview/EntryContentWebView" @@ -18,16 +27,11 @@ import { CalendarTimeAddCuteReIcon } from "@/src/icons/calendar_time_add_cute_re import { openLink } from "@/src/lib/native" import { useNavigation } from "@/src/lib/navigation/hooks" import type { NavigationControllerView } from "@/src/lib/navigation/types" +import { checkLanguage } from "@/src/lib/translation" import { EntryContentContext, useEntryContentContext } from "@/src/modules/entry-content/ctx" import { EntryAISummary } from "@/src/modules/entry-content/EntryAISummary" import { EntryNavigationHeader } from "@/src/modules/entry-content/EntryNavigationHeader" import { usePullUpToNext } from "@/src/modules/entry-content/use-pull-up-to-next" -import { useEntry, usePrefetchEntryDetail } from "@/src/store/entry/hooks" -import { entrySyncServices } from "@/src/store/entry/store" -import type { EntryWithTranslation } from "@/src/store/entry/types" -import { useFeed } from "@/src/store/feed/hooks" -import { useEntryTranslation, usePrefetchEntryTranslation } from "@/src/store/translation/hooks" -import { useAutoMarkAsRead } from "@/src/store/unread/hooks" import { EntrySocialTitle, EntryTitle } from "../../../../modules/entry-content/EntryTitle" @@ -38,7 +42,8 @@ export const EntryDetailScreen: NavigationControllerView<{ }> = ({ entryId, entryIds, view: viewType }) => { useAutoMarkAsRead(entryId) const entry = useEntry(entryId) - const translation = useEntryTranslation(entryId) + const actionLanguage = useActionLanguage() + const translation = useEntryTranslation(entryId, actionLanguage) const entryWithTranslation = useMemo(() => { if (!entry) return entry return { @@ -128,10 +133,15 @@ const EntryContentWebViewWithContext = ({ entry }: { entry: EntryWithTranslation const translationSetting = useGeneralSettingKey("translation") const showTranslation = useAtomValue(showAITranslationAtom) const entryId = entry.id + const actionLanguage = useActionLanguage() + const translation = useGeneralSettingKey("translation") usePrefetchEntryTranslation({ entryIds: [entryId], withContent: true, target: showReadability && entry.readabilityContent ? "readabilityContent" : "content", + language: actionLanguage, + checkLanguage, + translation, }) // Auto toggle readability when content is empty diff --git a/apps/mobile/src/screens/(stack)/feeds/[feedId]/FeedScreen.tsx b/apps/mobile/src/screens/(stack)/feeds/[feedId]/FeedScreen.tsx index f7ccd74b5..076904893 100644 --- a/apps/mobile/src/screens/(stack)/feeds/[feedId]/FeedScreen.tsx +++ b/apps/mobile/src/screens/(stack)/feeds/[feedId]/FeedScreen.tsx @@ -1,4 +1,13 @@ import { FeedViewType } from "@follow/constants" +import { useCollectionEntryList } from "@follow/store/src/collection/hooks" +import { + useEntryIdsByCategory, + useEntryIdsByFeedId, + useEntryIdsByInboxId, + useEntryIdsByListId, +} from "@follow/store/src/entry/hooks" +import { FEED_COLLECTION_LIST } from "@follow/store/src/entry/utils" +import { useFeed } from "@follow/store/src/feed/hooks" import { useMemo } from "react" import { RootSiblingParent } from "react-native-root-siblings" import { useSafeAreaInsets } from "react-native-safe-area-context" @@ -8,15 +17,6 @@ import type { NavigationControllerView } from "@/src/lib/navigation/types" import { EntryListSelector } from "@/src/modules/entry-list/EntryListSelector" import { EntryListContext, useSelectedView } from "@/src/modules/screen/atoms" import { TimelineHeader } from "@/src/modules/screen/TimelineSelectorProvider" -import { useCollectionEntryList } from "@/src/store/collection/hooks" -import { - useEntryIdsByCategory, - useEntryIdsByFeedId, - useEntryIdsByInboxId, - useEntryIdsByListId, -} from "@/src/store/entry/hooks" -import { FEED_COLLECTION_LIST } from "@/src/store/entry/utils" -import { useFeed } from "@/src/store/feed/hooks" export const FeedScreen: NavigationControllerView<{ feedId: string diff --git a/apps/mobile/src/screens/OnboardingScreen.tsx b/apps/mobile/src/screens/OnboardingScreen.tsx index 65cddf8ff..9eec96bb9 100644 --- a/apps/mobile/src/screens/OnboardingScreen.tsx +++ b/apps/mobile/src/screens/OnboardingScreen.tsx @@ -1,3 +1,4 @@ +import { isNewUserQueryKey, isOnboardingFinishedStorageKey } from "@follow/store/src/user/constants" import { tracker } from "@follow/tracker" import { useCallback, useEffect, useState } from "react" import { useTranslation } from "react-i18next" @@ -13,7 +14,6 @@ import { StepFinished } from "../modules/onboarding/step-finished" import { StepInterests } from "../modules/onboarding/step-interests" import { StepPreferences } from "../modules/onboarding/step-preferences" import { StepWelcome } from "../modules/onboarding/step-welcome" -import { isNewUserQueryKey, isOnboardingFinishedStorageKey } from "../store/user/constants" export const OnboardingScreen: NavigationControllerView = () => { const { t } = useTranslation("common") diff --git a/apps/mobile/src/screens/PlayerScreen.tsx b/apps/mobile/src/screens/PlayerScreen.tsx index 0ba45a1d2..20df7ca6f 100644 --- a/apps/mobile/src/screens/PlayerScreen.tsx +++ b/apps/mobile/src/screens/PlayerScreen.tsx @@ -1,3 +1,4 @@ +import { usePrefetchImageColors } from "@follow/store/src/image/hooks" import { cn } from "@follow/utils" import { LinearGradient } from "expo-linear-gradient" import { useEffect, useMemo } from "react" @@ -19,7 +20,6 @@ import { useActiveTrack, useIsPlaying } from "../lib/player" import { PlayerScreenContext, usePlayerScreenContext } from "../modules/player/context" import { ControlGroup, ProgressBar, VolumeBar } from "../modules/player/control" import { useCoverGradient } from "../modules/player/hooks" -import { usePrefetchImageColors } from "../store/image/hooks" function CoverArt({ cover }: { cover?: string }) { const scale = useSharedValue(1) diff --git a/apps/mobile/src/store/entry/getter.ts b/apps/mobile/src/store/entry/getter.ts deleted file mode 100644 index 1b9ab9cbe..000000000 --- a/apps/mobile/src/store/entry/getter.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { FeedViewType } from "@follow/constants" - -import type { SelectedFeed, SelectedTimeline } from "@/src/modules/screen/atoms" - -import { getSubscriptionByCategory } from "../subscription/getter" -import { useEntryStore } from "./store" -import type { EntryModel, FetchEntriesProps } from "./types" -import { FEED_COLLECTION_LIST } from "./utils" - -const get = useEntryStore.getState - -export const getEntry = (id: string): EntryModel | undefined => { - return get().data[id] -} - -export const getFetchEntryPayload = ( - selectedFeed: SelectedTimeline | SelectedFeed, - view: FeedViewType = FeedViewType.Articles, -): FetchEntriesProps | null => { - if (!selectedFeed) { - return null - } - - let payload: FetchEntriesProps = {} - switch (selectedFeed.type) { - case "view": { - payload = { view: selectedFeed.viewId } - break - } - case "feed": { - payload = { feedId: selectedFeed.feedId } - break - } - case "category": { - payload = { - feedIdList: getSubscriptionByCategory({ category: selectedFeed.categoryName, view }), - } - break - } - case "list": { - payload = { listId: selectedFeed.listId } - break - } - case "inbox": { - payload = { inboxId: selectedFeed.inboxId } - break - } - // No default - } - const isCollection = - selectedFeed && selectedFeed.type === "feed" && selectedFeed?.feedId === FEED_COLLECTION_LIST - if (isCollection) { - payload.view = view - payload.isCollection = true - } - - return payload -} diff --git a/apps/mobile/src/store/internal/base.ts b/apps/mobile/src/store/internal/base.ts deleted file mode 100644 index cb58aae60..000000000 --- a/apps/mobile/src/store/internal/base.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface Hydratable { - hydrate: () => Promise -} diff --git a/packages/internal/constants/src/tabs.tsx b/packages/internal/constants/src/tabs.tsx index 21f7861ef..af3397938 100644 --- a/packages/internal/constants/src/tabs.tsx +++ b/packages/internal/constants/src/tabs.tsx @@ -17,6 +17,7 @@ export interface ViewDefinition { view: FeedViewType wideMode?: boolean gridMode?: boolean + activeColor: string } export const views: ViewDefinition[] = [ { @@ -26,6 +27,7 @@ export const views: ViewDefinition[] = [ peerClassName: "peer-checked:text-accent dark:peer-checked:text-accent", translation: "title,description", view: FeedViewType.Articles, + activeColor: "#FF5C00", }, { name: "feed_view_type.social_media", @@ -35,6 +37,8 @@ export const views: ViewDefinition[] = [ wideMode: true, translation: "content", view: FeedViewType.SocialMedia, + // sky-500 + activeColor: "#0ea5e9", }, { name: "feed_view_type.pictures", @@ -45,6 +49,8 @@ export const views: ViewDefinition[] = [ wideMode: true, translation: "title", view: FeedViewType.Pictures, + // green-500 + activeColor: "#22c55e", }, { name: "feed_view_type.videos", @@ -55,6 +61,8 @@ export const views: ViewDefinition[] = [ wideMode: true, translation: "title", view: FeedViewType.Videos, + // red-500 + activeColor: "#ef4444", }, { name: "feed_view_type.audios", @@ -63,6 +71,8 @@ export const views: ViewDefinition[] = [ peerClassName: "peer-checked:text-purple-600 peer-checked:dark:text-purple-500", translation: "title", view: FeedViewType.Audios, + // purple-500 + activeColor: "#a855f7", }, { name: "feed_view_type.notifications", @@ -71,6 +81,8 @@ export const views: ViewDefinition[] = [ peerClassName: "peer-checked:text-yellow-600 peer-checked:dark:text-yellow-500", translation: "title", view: FeedViewType.Notifications, + // yellow-500 + activeColor: "#eab308", }, ] diff --git a/packages/internal/store/package.json b/packages/internal/store/package.json new file mode 100644 index 000000000..9a3be8535 --- /dev/null +++ b/packages/internal/store/package.json @@ -0,0 +1,39 @@ +{ + "name": "@follow/store", + "type": "module", + "private": true, + "author": "Folo Team", + "license": "GPL-3.0-only", + "homepage": "https://github.com/RSSNext", + "repository": { + "url": "https://github.com/RSSNext/follow", + "type": "git" + }, + "sideEffects": false, + "exports": { + "./src/*": { + "types": "./src/*.ts", + "require": "./src/*.ts", + "import": "./src/*.ts" + } + }, + "scripts": { + "typecheck": "tsc --noEmit" + }, + "peerDependencies": { + "react": "^19.0.0" + }, + "dependencies": { + "@follow/configs": "workspace:*", + "@follow/constants": "workspace:*", + "@follow/database": "workspace:*", + "@follow/models": "workspace:*", + "@follow/shared": "workspace:*", + "@follow/tracker": "workspace:*", + "@follow/utils": "workspace:*", + "@tanstack/react-query": "5.74.7", + "es-toolkit": "1.36.0", + "immer": "10.1.1", + "zustand": "5.0.3" + } +} diff --git a/apps/mobile/src/store/action/hooks.ts b/packages/internal/store/src/action/hooks.ts similarity index 82% rename from apps/mobile/src/store/action/hooks.ts rename to packages/internal/store/src/action/hooks.ts index 848490488..b415f529a 100644 --- a/apps/mobile/src/store/action/hooks.ts +++ b/packages/internal/store/src/action/hooks.ts @@ -2,9 +2,7 @@ import { useMutation, useQuery } from "@tanstack/react-query" import { FetchError } from "ofetch" import { useCallback } from "react" -import { useNavigation } from "@/src/lib/navigation/hooks" -import { toast } from "@/src/lib/toast" - +import type { GeneralMutationOptions } from "../types" import { actionSyncService, useActionStore } from "./store" export const usePrefetchActions = () => { @@ -14,22 +12,20 @@ export const usePrefetchActions = () => { }) } -export const useUpdateActionsMutation = () => { - const navigation = useNavigation() +export const useUpdateActionsMutation = (options?: GeneralMutationOptions) => { return useMutation({ mutationFn: () => actionSyncService.saveRules(), onSuccess() { - navigation.back() - toast.success("Actions saved") + options?.onSuccess?.() }, onError(err) { if (err instanceof FetchError && err.response?._data) { const { message } = err.response._data - toast.error(message) + options?.onError?.(message) return } - toast.error("Error saving actions") + options?.onError?.("Error saving actions") }, }) } diff --git a/apps/mobile/src/store/action/store.ts b/packages/internal/store/src/action/store.ts similarity index 99% rename from apps/mobile/src/store/action/store.ts rename to packages/internal/store/src/action/store.ts index eddb24094..3ff4b52ba 100644 --- a/apps/mobile/src/store/action/store.ts +++ b/packages/internal/store/src/action/store.ts @@ -7,8 +7,6 @@ import type { } from "@follow/models/src/types" import { merge } from "es-toolkit/compat" -import { apiClient } from "@/src/lib/api-fetch" - import { createImmerSetter, createZustandStore } from "../internal/helper" type ActionStore = { diff --git a/apps/mobile/src/store/collection/hooks.ts b/packages/internal/store/src/collection/hooks.ts similarity index 100% rename from apps/mobile/src/store/collection/hooks.ts rename to packages/internal/store/src/collection/hooks.ts diff --git a/apps/mobile/src/store/collection/store.ts b/packages/internal/store/src/collection/store.ts similarity index 98% rename from apps/mobile/src/store/collection/store.ts rename to packages/internal/store/src/collection/store.ts index 6fadd569f..4d3dd1996 100644 --- a/apps/mobile/src/store/collection/store.ts +++ b/packages/internal/store/src/collection/store.ts @@ -2,8 +2,6 @@ import type { FeedViewType } from "@follow/constants" import type { CollectionSchema } from "@follow/database/src/schemas/types" import { CollectionService } from "@follow/database/src/services/collection" -import { apiClient } from "@/src/lib/api-fetch" - import type { Hydratable } from "../internal/base" import { createTransaction, createZustandStore } from "../internal/helper" diff --git a/apps/mobile/src/store/collection/types.ts b/packages/internal/store/src/collection/types.ts similarity index 100% rename from apps/mobile/src/store/collection/types.ts rename to packages/internal/store/src/collection/types.ts diff --git a/packages/internal/store/src/entry/getter.ts b/packages/internal/store/src/entry/getter.ts new file mode 100644 index 000000000..142fca1bd --- /dev/null +++ b/packages/internal/store/src/entry/getter.ts @@ -0,0 +1,8 @@ +import { useEntryStore } from "./store" +import type { EntryModel } from "./types" + +const get = useEntryStore.getState + +export const getEntry = (id: string): EntryModel | undefined => { + return get().data[id] +} diff --git a/apps/mobile/src/store/entry/hooks.ts b/packages/internal/store/src/entry/hooks.ts similarity index 78% rename from apps/mobile/src/store/entry/hooks.ts rename to packages/internal/store/src/entry/hooks.ts index 8b3e5617b..fb02ac774 100644 --- a/apps/mobile/src/store/entry/hooks.ts +++ b/packages/internal/store/src/entry/hooks.ts @@ -1,19 +1,25 @@ import type { FeedViewType } from "@follow/constants" -import { useInfiniteQuery, useMutation, useQuery } from "@tanstack/react-query" -import { useCallback, useEffect } from "react" - -import { useGeneralSettingKey } from "@/src/atoms/settings/general" +import { useInfiniteQuery, useQuery } from "@tanstack/react-query" +import { useCallback } from "react" import { getEntry } from "./getter" import { entrySyncServices, useEntryStore } from "./store" -import type { EntryModel, FetchEntriesProps } from "./types" +import type { EntryModel, FetchEntriesProps, FetchEntriesPropsSettings } from "./types" + +export const usePrefetchEntries = ( + props: Omit & FetchEntriesPropsSettings, +) => { + const { + feedId, + inboxId, + listId, + view, + limit, + feedIdList, + unreadOnly, + hidePrivateSubscriptionsInTimeline, + } = props || {} -export const usePrefetchEntries = (props: Omit | null) => { - const { feedId, inboxId, listId, view, limit, feedIdList } = props || {} - const unreadOnly = useGeneralSettingKey("unreadOnly") - const hidePrivateSubscriptionsInTimeline = useGeneralSettingKey( - "hidePrivateSubscriptionsInTimeline", - ) return useInfiniteQuery({ queryKey: [ "entries", @@ -147,15 +153,3 @@ export const useEntryIdsByListId = (listId: string) => { ), ) } - -export const useFetchEntryContentByStream = (remoteEntryIds?: string[]) => { - const { mutate: updateEntryContent } = useMutation({ - mutationKey: ["stream-entry-content", remoteEntryIds], - mutationFn: entrySyncServices.fetchEntryContentByStream, - }) - - useEffect(() => { - if (!remoteEntryIds) return - updateEntryContent(remoteEntryIds) - }, [remoteEntryIds, updateEntryContent]) -} diff --git a/apps/mobile/src/store/entry/store.ts b/packages/internal/store/src/entry/store.ts similarity index 93% rename from apps/mobile/src/store/entry/store.ts rename to packages/internal/store/src/entry/store.ts index 3203719d9..9715ffdfe 100644 --- a/apps/mobile/src/store/entry/store.ts +++ b/packages/internal/store/src/entry/store.ts @@ -1,24 +1,19 @@ import { FeedViewType } from "@follow/constants" import { EntryService } from "@follow/database/src/services/entry" import { debounce } from "es-toolkit/compat" -import { fetch as expoFetch } from "expo/fetch" - -import { getGeneralSettings } from "@/src/atoms/settings/general" -import { apiClient } from "@/src/lib/api-fetch" -import { getCookie } from "@/src/lib/auth" -import { dbStoreMorph } from "@/src/morph/db-store" -import { honoMorph } from "@/src/morph/hono" -import { storeDbMorph } from "@/src/morph/store-db" import { collectionActions } from "../collection/store" import { feedActions } from "../feed/store" -import type { Hydratable } from "../internal/base" +import type { Hydratable, HydrationOptions } from "../internal/base" import { createImmerSetter, createTransaction, createZustandStore } from "../internal/helper" +import { dbStoreMorph } from "../morph/db-store" +import { honoMorph } from "../morph/hono" +import { storeDbMorph } from "../morph/store-db" import { getSubscription } from "../subscription/getter" import { getDefaultCategory } from "../subscription/utils" import type { PublishAtTimeRangeFilter } from "../unread/types" import { getEntry } from "./getter" -import type { EntryModel, FetchEntriesProps } from "./types" +import type { EntryModel, FetchEntriesProps, FetchEntriesPropsSettings } from "./types" import { getEntriesParams } from "./utils" type EntryId = string @@ -59,12 +54,12 @@ export const useEntryStore = createZustandStore("entry")(() => defau const immerSet = createImmerSetter(useEntryStore) class EntryActions implements Hydratable { - async hydrate() { + async hydrate(options?: HydrationOptions) { const entries = await EntryService.getEntryAll() - const { unreadOnly } = getGeneralSettings() + entryActions.upsertManyInSession( entries.map((e) => dbStoreMorph.toEntryModel(e)), - { unreadOnly }, + options, ) } @@ -73,16 +68,17 @@ class EntryActions implements Hydratable { feedId, entryId, sources, + hidePrivateSubscriptionsInTimeline, }: { draft: EntryState feedId?: FeedId | null entryId: EntryId sources?: string[] | null + hidePrivateSubscriptionsInTimeline?: boolean }) { if (!feedId) return const subscription = getSubscription(feedId) - const { hidePrivateSubscriptionsInTimeline } = getGeneralSettings() const ignore = hidePrivateSubscriptionsInTimeline && subscription?.isPrivate if (typeof subscription?.view === "number" && !ignore) { @@ -175,9 +171,9 @@ class EntryActions implements Hydratable { } } - upsertManyInSession(entries: EntryModel[], options?: { unreadOnly?: boolean }) { + upsertManyInSession(entries: EntryModel[], options?: FetchEntriesPropsSettings) { if (entries.length === 0) return - const { unreadOnly } = options ?? {} + const { unreadOnly, hidePrivateSubscriptionsInTimeline } = options || {} immerSet((draft) => { for (const entry of entries) { @@ -206,6 +202,7 @@ class EntryActions implements Hydratable { feedId, entryId: entry.id, sources, + hidePrivateSubscriptionsInTimeline, }) this.addEntryIdToCategory({ @@ -522,7 +519,13 @@ class EntrySyncServices { return entry } - async fetchEntryContentByStream(remoteEntryIds?: string[]) { + async fetchEntryContentByStream( + remoteEntryIds?: string[], + options?: { + fetch?: typeof fetch + cookie?: string + }, + ) { if (!remoteEntryIds || remoteEntryIds.length === 0) return const onlyNoStored = true @@ -544,11 +547,13 @@ class EntrySyncServices { const readStream = async () => { // https://github.com/facebook/react-native/issues/37505 // TODO: And it seems we can not just use fetch from expo for ofetch, need further investigation - const response = await expoFetch(apiClient.entries.stream.$url().toString(), { + const response = await (options?.fetch || fetch)(apiClient.entries.stream.$url().toString(), { method: "POST", - headers: { - cookie: getCookie(), - }, + headers: options?.cookie + ? { + cookie: options.cookie, + } + : undefined, body: JSON.stringify({ ids: nextIds, }), diff --git a/apps/mobile/src/store/entry/types.ts b/packages/internal/store/src/entry/types.ts similarity index 81% rename from apps/mobile/src/store/entry/types.ts rename to packages/internal/store/src/entry/types.ts index 98eeb2352..b76776491 100644 --- a/apps/mobile/src/store/entry/types.ts +++ b/packages/internal/store/src/entry/types.ts @@ -16,3 +16,8 @@ export type FetchEntriesProps = { isCollection?: boolean excludePrivate?: boolean } + +export type FetchEntriesPropsSettings = { + hidePrivateSubscriptionsInTimeline: boolean + unreadOnly: boolean +} diff --git a/apps/mobile/src/store/entry/utils.ts b/packages/internal/store/src/entry/utils.ts similarity index 100% rename from apps/mobile/src/store/entry/utils.ts rename to packages/internal/store/src/entry/utils.ts diff --git a/apps/mobile/src/store/feed/getter.ts b/packages/internal/store/src/feed/getter.ts similarity index 100% rename from apps/mobile/src/store/feed/getter.ts rename to packages/internal/store/src/feed/getter.ts diff --git a/apps/mobile/src/store/feed/hooks.ts b/packages/internal/store/src/feed/hooks.ts similarity index 100% rename from apps/mobile/src/store/feed/hooks.ts rename to packages/internal/store/src/feed/hooks.ts diff --git a/apps/mobile/src/store/feed/store.ts b/packages/internal/store/src/feed/store.ts similarity index 98% rename from apps/mobile/src/store/feed/store.ts rename to packages/internal/store/src/feed/store.ts index 76f4bf801..0114e4df3 100644 --- a/apps/mobile/src/store/feed/store.ts +++ b/packages/internal/store/src/feed/store.ts @@ -1,8 +1,6 @@ import type { FeedSchema } from "@follow/database/src/schemas/types" import { FeedService } from "@follow/database/src/services/feed" -import { apiClient } from "@/src/lib/api-fetch" - import type { Hydratable } from "../internal/base" import { createImmerSetter, createTransaction, createZustandStore } from "../internal/helper" import type { FeedModel } from "./types" diff --git a/apps/mobile/src/store/feed/types.ts b/packages/internal/store/src/feed/types.ts similarity index 100% rename from apps/mobile/src/store/feed/types.ts rename to packages/internal/store/src/feed/types.ts diff --git a/apps/mobile/src/store/image/getters.ts b/packages/internal/store/src/image/getters.ts similarity index 100% rename from apps/mobile/src/store/image/getters.ts rename to packages/internal/store/src/image/getters.ts diff --git a/apps/mobile/src/store/image/hooks.ts b/packages/internal/store/src/image/hooks.ts similarity index 100% rename from apps/mobile/src/store/image/hooks.ts rename to packages/internal/store/src/image/hooks.ts diff --git a/apps/mobile/src/store/image/store.ts b/packages/internal/store/src/image/store.ts similarity index 100% rename from apps/mobile/src/store/image/store.ts rename to packages/internal/store/src/image/store.ts diff --git a/apps/mobile/src/store/inbox/hooks.ts b/packages/internal/store/src/inbox/hooks.ts similarity index 100% rename from apps/mobile/src/store/inbox/hooks.ts rename to packages/internal/store/src/inbox/hooks.ts diff --git a/apps/mobile/src/store/inbox/store.ts b/packages/internal/store/src/inbox/store.ts similarity index 100% rename from apps/mobile/src/store/inbox/store.ts rename to packages/internal/store/src/inbox/store.ts diff --git a/apps/mobile/src/store/index.ts b/packages/internal/store/src/index.ts similarity index 77% rename from apps/mobile/src/store/index.ts rename to packages/internal/store/src/index.ts index ce4529812..da8de17b3 100644 --- a/apps/mobile/src/store/index.ts +++ b/packages/internal/store/src/index.ts @@ -3,7 +3,7 @@ import { entryActions } from "./entry/store" import { feedActions } from "./feed/store" import { imageActions } from "./image/store" import { inboxActions } from "./inbox/store" -import type { Hydratable } from "./internal/base" +import type { Hydratable, HydrationOptions } from "./internal/base" import { listActions } from "./list/store" import { subscriptionActions } from "./subscription/store" import { translationActions } from "./translation/store" @@ -23,6 +23,6 @@ const hydrates: Hydratable[] = [ translationActions, ] -export const hydrateDatabaseToStore = async () => { - await Promise.all(hydrates.map((h) => h.hydrate())) +export const hydrateDatabaseToStore = async (options?: HydrationOptions) => { + await Promise.all(hydrates.map((h) => h.hydrate(options))) } diff --git a/packages/internal/store/src/internal/base.ts b/packages/internal/store/src/internal/base.ts new file mode 100644 index 000000000..e050a8c89 --- /dev/null +++ b/packages/internal/store/src/internal/base.ts @@ -0,0 +1,7 @@ +import type { FetchEntriesPropsSettings } from "../entry/types" + +export interface Hydratable { + hydrate: (options?: HydrationOptions) => Promise +} + +export type HydrationOptions = FetchEntriesPropsSettings diff --git a/apps/mobile/src/store/internal/helper.ts b/packages/internal/store/src/internal/helper.ts similarity index 100% rename from apps/mobile/src/store/internal/helper.ts rename to packages/internal/store/src/internal/helper.ts diff --git a/apps/mobile/src/store/list/getters.ts b/packages/internal/store/src/list/getters.ts similarity index 100% rename from apps/mobile/src/store/list/getters.ts rename to packages/internal/store/src/list/getters.ts diff --git a/apps/mobile/src/store/list/hooks.ts b/packages/internal/store/src/list/hooks.ts similarity index 100% rename from apps/mobile/src/store/list/hooks.ts rename to packages/internal/store/src/list/hooks.ts diff --git a/apps/mobile/src/store/list/store.ts b/packages/internal/store/src/list/store.ts similarity index 96% rename from apps/mobile/src/store/list/store.ts rename to packages/internal/store/src/list/store.ts index 9247c4bd1..1f43d9e30 100644 --- a/apps/mobile/src/store/list/store.ts +++ b/packages/internal/store/src/list/store.ts @@ -1,13 +1,11 @@ import type { ListSchema } from "@follow/database/src/schemas/types" import { ListService } from "@follow/database/src/services/list" -import { apiClient } from "@/src/lib/api-fetch" -import { honoMorph } from "@/src/morph/hono" -import { storeDbMorph } from "@/src/morph/store-db" - import { feedActions } from "../feed/store" import type { Hydratable } from "../internal/base" import { createImmerSetter, createTransaction, createZustandStore } from "../internal/helper" +import { honoMorph } from "../morph/hono" +import { storeDbMorph } from "../morph/store-db" import { getList } from "./getters" import type { CreateListModel } from "./types" diff --git a/apps/mobile/src/store/list/types.ts b/packages/internal/store/src/list/types.ts similarity index 100% rename from apps/mobile/src/store/list/types.ts rename to packages/internal/store/src/list/types.ts diff --git a/apps/mobile/src/morph/db-store.ts b/packages/internal/store/src/morph/db-store.ts similarity index 73% rename from apps/mobile/src/morph/db-store.ts rename to packages/internal/store/src/morph/db-store.ts index 7038a94cc..90a6809ad 100644 --- a/apps/mobile/src/morph/db-store.ts +++ b/packages/internal/store/src/morph/db-store.ts @@ -1,7 +1,7 @@ import type { EntrySchema, SubscriptionSchema } from "@follow/database/src/schemas/types" -import type { EntryModel } from "../store/entry/types" -import type { SubscriptionModel } from "../store/subscription/store" +import type { EntryModel } from "../entry/types" +import type { SubscriptionModel } from "../subscription/store" class DbStoreMorph { toSubscriptionModel(subscription: SubscriptionSchema): SubscriptionModel { diff --git a/apps/mobile/src/morph/hono.ts b/packages/internal/store/src/morph/hono.ts similarity index 94% rename from apps/mobile/src/morph/hono.ts rename to packages/internal/store/src/morph/hono.ts index 64c60688a..9dd7836ee 100644 --- a/apps/mobile/src/morph/hono.ts +++ b/packages/internal/store/src/morph/hono.ts @@ -1,12 +1,12 @@ import type { FeedViewType } from "@follow/constants" import type { FeedSchema, InboxSchema } from "@follow/database/src/schemas/types" -import type { CollectionModel } from "../store/collection/types" -import type { EntryModel } from "../store/entry/types" -import type { FeedModel } from "../store/feed/types" -import type { ListModel } from "../store/list/store" -import type { SubscriptionModel } from "../store/subscription/store" -import type { MeModel } from "../store/user/store" +import type { CollectionModel } from "../collection/types" +import type { EntryModel } from "../entry/types" +import type { FeedModel } from "../feed/types" +import type { ListModel } from "../list/store" +import type { SubscriptionModel } from "../subscription/store" +import type { MeModel } from "../user/store" import type { HonoApiClient } from "./types" class Morph { diff --git a/apps/mobile/src/morph/store-db.ts b/packages/internal/store/src/morph/store-db.ts similarity index 83% rename from apps/mobile/src/morph/store-db.ts rename to packages/internal/store/src/morph/store-db.ts index 551b78c0f..6760fb058 100644 --- a/apps/mobile/src/morph/store-db.ts +++ b/packages/internal/store/src/morph/store-db.ts @@ -4,9 +4,9 @@ import type { SubscriptionSchema, } from "@follow/database/src/schemas/types" -import type { EntryModel } from "../store/entry/types" -import type { ListModel } from "../store/list/store" -import type { SubscriptionModel } from "../store/subscription/store" +import type { EntryModel } from "../entry/types" +import type { ListModel } from "../list/store" +import type { SubscriptionModel } from "../subscription/store" class StoreDbMorph { toListSchema(list: ListModel): ListSchema { diff --git a/apps/mobile/src/morph/types.ts b/packages/internal/store/src/morph/types.ts similarity index 91% rename from apps/mobile/src/morph/types.ts rename to packages/internal/store/src/morph/types.ts index e7381ada1..852b92665 100644 --- a/apps/mobile/src/morph/types.ts +++ b/packages/internal/store/src/morph/types.ts @@ -1,7 +1,5 @@ /* eslint-disable @typescript-eslint/no-namespace */ -import type { AuthSession } from "@follow/shared" - -import type { apiClient } from "../lib/api-fetch" +import type { AuthSession } from "@follow/shared/src/hono" // Add ExtractData type utility type ExtractData any> = diff --git a/apps/mobile/src/store/subscription/getter.ts b/packages/internal/store/src/subscription/getter.ts similarity index 100% rename from apps/mobile/src/store/subscription/getter.ts rename to packages/internal/store/src/subscription/getter.ts diff --git a/apps/mobile/src/store/subscription/hooks.ts b/packages/internal/store/src/subscription/hooks.ts similarity index 85% rename from apps/mobile/src/store/subscription/hooks.ts rename to packages/internal/store/src/subscription/hooks.ts index aeb13daa3..15e3c6933 100644 --- a/apps/mobile/src/store/subscription/hooks.ts +++ b/packages/internal/store/src/subscription/hooks.ts @@ -1,11 +1,8 @@ -import { FeedViewType } from "@follow/constants" -import { sortByAlphabet } from "@follow/utils" +import { FeedViewType, views } from "@follow/constants" +import { sortByAlphabet } from "@follow/utils/src/utils" import { useQuery } from "@tanstack/react-query" import { useCallback } from "react" -import { getGeneralSettings, useHideAllReadSubscriptions } from "@/src/atoms/settings/general" -import { views } from "@/src/constants/views" - import { getFeed } from "../feed/getter" import { getList } from "../list/getters" import { getUnreadCount } from "../unread/getter" @@ -55,7 +52,13 @@ export const useFeedSubscriptionByView = (view: FeedViewType) => { return useSubscriptionStore(useCallback(() => getFeedSubscriptionByView(view), [view])) } -export const useGroupedSubscription = (view: FeedViewType) => { +export const useGroupedSubscription = ({ + view, + autoGroup, +}: { + view: FeedViewType + autoGroup: boolean +}) => { return useSubscriptionStore( useCallback( (state) => { @@ -63,7 +66,7 @@ export const useGroupedSubscription = (view: FeedViewType) => { const grouped = {} as Record const unGrouped = [] - const { autoGroup } = getGeneralSettings() + const autoGrouped = {} as Record for (const feedId of feedIds) { @@ -103,7 +106,7 @@ export const useGroupedSubscription = (view: FeedViewType) => { unGrouped, } }, - [view], + [autoGroup, view], ), ) } @@ -136,13 +139,19 @@ const sortGroupedSubscriptionByUnread = ( return -(rightUnreadCount - leftUnreadCount) } -export const useSortedGroupedSubscription = ( - view: FeedViewType, - grouped: Record, - sortBy: "alphabet" | "count", - sortOrder: "asc" | "desc", -) => { - const hideAllReadSubscriptions = useHideAllReadSubscriptions() +export const useSortedGroupedSubscription = ({ + view, + grouped, + sortBy, + sortOrder, + hideAllReadSubscriptions, +}: { + view: FeedViewType + grouped: Record + sortBy: "alphabet" | "count" + sortOrder: "asc" | "desc" + hideAllReadSubscriptions: boolean +}) => { return useSubscriptionStore( useCallback(() => { const categories = Object.keys(grouped) @@ -162,13 +171,17 @@ export const useSortedGroupedSubscription = ( ) } -export const useSortedUngroupedSubscription = ( - ids: string[], - sortBy: "alphabet" | "count", - sortOrder: "asc" | "desc", -) => { - const hideAllReadSubscriptions = useHideAllReadSubscriptions() - +export const useSortedUngroupedSubscription = ({ + ids, + sortBy, + sortOrder, + hideAllReadSubscriptions, +}: { + ids: string[] + sortBy: "alphabet" | "count" + sortOrder: "asc" | "desc" + hideAllReadSubscriptions: boolean +}) => { return useSubscriptionStore( useCallback(() => { return ids @@ -223,8 +236,15 @@ export const useListSubscription = (view: FeedViewType) => { ) } -export const useSortedListSubscription = (ids: string[], sortBy: "alphabet" | "unread") => { - const hideAllReadSubscriptions = useHideAllReadSubscriptions() +export const useSortedListSubscription = ({ + ids, + sortBy, + hideAllReadSubscriptions, +}: { + ids: string[] + sortBy: "alphabet" | "unread" + hideAllReadSubscriptions: boolean +}) => { return useSubscriptionStore( useCallback(() => { return ids @@ -279,17 +299,19 @@ export const useSubscriptionByListId = (listId: string) => export const useViewWithSubscription = () => useSubscriptionStore( useCallback((state) => { - return views.filter((view) => { - if ( - view.view === FeedViewType.Articles || - view.view === FeedViewType.SocialMedia || - view.view === FeedViewType.Pictures || - view.view === FeedViewType.Videos - ) { - return true - } else { - return state.feedIdByView[view.view].size > 0 - } - }) + return views + .filter((view) => { + if ( + view.view === FeedViewType.Articles || + view.view === FeedViewType.SocialMedia || + view.view === FeedViewType.Pictures || + view.view === FeedViewType.Videos + ) { + return true + } else { + return state.feedIdByView[view.view].size > 0 + } + }) + .map((v) => v.view) }, []), ) diff --git a/apps/mobile/src/store/subscription/store.ts b/packages/internal/store/src/subscription/store.ts similarity index 97% rename from apps/mobile/src/store/subscription/store.ts rename to packages/internal/store/src/subscription/store.ts index f1cfbaa0a..caeb0666a 100644 --- a/apps/mobile/src/store/subscription/store.ts +++ b/packages/internal/store/src/subscription/store.ts @@ -3,17 +3,14 @@ import type { SubscriptionSchema } from "@follow/database/src/schemas/types" import { SubscriptionService } from "@follow/database/src/services/subscription" import { tracker } from "@follow/tracker" -import { apiClient } from "@/src/lib/api-fetch" -import { toast } from "@/src/lib/toast" -import { dbStoreMorph } from "@/src/morph/db-store" -import { honoMorph } from "@/src/morph/hono" -import { buildSubscriptionDbId, storeDbMorph } from "@/src/morph/store-db" - import { feedActions } from "../feed/store" import { inboxActions } from "../inbox/store" import type { Hydratable } from "../internal/base" import { createImmerSetter, createTransaction, createZustandStore } from "../internal/helper" import { listActions } from "../list/store" +import { dbStoreMorph } from "../morph/db-store" +import { honoMorph } from "../morph/hono" +import { buildSubscriptionDbId, storeDbMorph } from "../morph/store-db" import { whoami } from "../user/getters" import type { SubscriptionForm } from "./types" import { getInboxStoreId, getSubscriptionStoreId } from "./utils" @@ -175,7 +172,6 @@ class SubscriptionSyncService { const subscriptionId = getSubscriptionStoreId(subscription) const current = get().data[subscriptionId] if (!current) { - toast.error("Subscription to edit not found") return } const tx = createTransaction(current) diff --git a/apps/mobile/src/store/subscription/types.ts b/packages/internal/store/src/subscription/types.ts similarity index 100% rename from apps/mobile/src/store/subscription/types.ts rename to packages/internal/store/src/subscription/types.ts diff --git a/apps/mobile/src/store/subscription/utils.ts b/packages/internal/store/src/subscription/utils.ts similarity index 91% rename from apps/mobile/src/store/subscription/utils.ts rename to packages/internal/store/src/subscription/utils.ts index 65957f810..8962cdd1a 100644 --- a/apps/mobile/src/store/subscription/utils.ts +++ b/packages/internal/store/src/subscription/utils.ts @@ -1,4 +1,4 @@ -import { capitalizeFirstLetter, parseUrl } from "@follow/utils" +import { capitalizeFirstLetter, parseUrl } from "@follow/utils/src/utils" import { getFeed } from "../feed/getter" import type { SubscriptionModel } from "./store" diff --git a/apps/mobile/src/store/summary/enum.ts b/packages/internal/store/src/summary/enum.ts similarity index 100% rename from apps/mobile/src/store/summary/enum.ts rename to packages/internal/store/src/summary/enum.ts diff --git a/apps/mobile/src/store/summary/hooks.ts b/packages/internal/store/src/summary/hooks.ts similarity index 57% rename from apps/mobile/src/store/summary/hooks.ts rename to packages/internal/store/src/summary/hooks.ts index 4fccbfa62..230045646 100644 --- a/apps/mobile/src/store/summary/hooks.ts +++ b/packages/internal/store/src/summary/hooks.ts @@ -1,5 +1,7 @@ +import type { SupportedActionLanguage } from "@follow/shared" import { useQuery } from "@tanstack/react-query" +import type { GeneralQueryOptions } from "../types" import { summarySyncService, useSummaryStore } from "./store" export const useSummary = (entryId: string) => { @@ -12,15 +14,20 @@ export const useSummaryStatus = (entryId: string) => { return status } -export const usePrefetchSummary = ( - entryId: string, - target: "content" | "readabilityContent", - options?: { enabled?: boolean }, -) => { +export function usePrefetchSummary({ + entryId, + target, + actionLanguage, + ...options +}: { + entryId: string + target: "content" | "readabilityContent" + actionLanguage: SupportedActionLanguage +} & GeneralQueryOptions) { return useQuery({ queryKey: ["summary", entryId, target], queryFn: () => { - return summarySyncService.generateSummary(entryId, target) + return summarySyncService.generateSummary({ entryId, target, actionLanguage }) }, enabled: options?.enabled, staleTime: 1000 * 60 * 60 * 24, diff --git a/apps/mobile/src/store/summary/store.ts b/packages/internal/store/src/summary/store.ts similarity index 94% rename from apps/mobile/src/store/summary/store.ts rename to packages/internal/store/src/summary/store.ts index 427803936..5f70c7745 100644 --- a/apps/mobile/src/store/summary/store.ts +++ b/packages/internal/store/src/summary/store.ts @@ -1,8 +1,6 @@ import type { SummarySchema } from "@follow/database/src/schemas/types" import { summaryService } from "@follow/database/src/services/summary" - -import { getActionLanguage } from "@/src/atoms/settings/general" -import { apiClient } from "@/src/lib/api-fetch" +import type { SupportedActionLanguage } from "@follow/shared" import { getEntry } from "../entry/getter" import { createImmerSetter, createZustandStore } from "../internal/helper" @@ -99,7 +97,15 @@ export const summaryActions = new SummaryActions() class SummarySyncService { private pendingPromises: Record> = {} - async generateSummary(entryId: string, target: "content" | "readabilityContent") { + async generateSummary({ + entryId, + target, + actionLanguage, + }: { + entryId: string + target: "content" | "readabilityContent" + actionLanguage: SupportedActionLanguage + }) { const entry = getEntry(entryId) if (!entry) return @@ -111,7 +117,6 @@ class SummarySyncService { state.generatingStatus[entryId] = SummaryGeneratingStatus.Pending }) - const actionLanguage = getActionLanguage() // Use Our AI to generate summary const pendingPromise = apiClient.ai.summary .$get({ diff --git a/apps/mobile/src/store/translation/hooks.ts b/packages/internal/store/src/translation/hooks.ts similarity index 64% rename from apps/mobile/src/store/translation/hooks.ts rename to packages/internal/store/src/translation/hooks.ts index f02a729fb..3f632a35f 100644 --- a/apps/mobile/src/store/translation/hooks.ts +++ b/packages/internal/store/src/translation/hooks.ts @@ -1,8 +1,8 @@ +import type { SupportedLanguages } from "@follow/models/src/types" +import type { SupportedActionLanguage } from "@follow/shared" import { useQueries } from "@tanstack/react-query" import { useCallback } from "react" -import { useActionLanguage, useGeneralSettingKey } from "@/src/atoms/settings/general" - import { useEntryList } from "../entry/hooks" import { translationSyncService, useTranslationStore } from "./store" @@ -10,35 +10,38 @@ export const usePrefetchEntryTranslation = ({ entryIds, withContent, target = "content", + translation, + language, + checkLanguage, }: { entryIds: string[] withContent?: boolean target?: "content" | "readabilityContent" + translation: boolean + language: SupportedActionLanguage + checkLanguage: (params: { content: string; language: SupportedActionLanguage }) => boolean }) => { - const translation = useGeneralSettingKey("translation") const entryList = useEntryList(entryIds) ?.filter((entry) => entry !== null && (translation || !!entry?.settings?.translation)) .map((entry) => entry!.id) || [] - const actionLanguage = useActionLanguage() - return useQueries({ queries: entryList.map((entryId) => ({ - queryKey: ["translation", entryId, actionLanguage, withContent, target], + queryKey: ["translation", entryId, language, withContent, target], queryFn: () => translationSyncService.generateTranslation({ entryId, - language: actionLanguage, + language, withContent, target, + checkLanguage, }), })), }) } -export const useEntryTranslation = (entryId: string) => { - const language = useActionLanguage() +export const useEntryTranslation = (entryId: string, language: SupportedLanguages) => { return useTranslationStore( useCallback( (state) => { diff --git a/apps/mobile/src/store/translation/store.ts b/packages/internal/store/src/translation/store.ts similarity index 93% rename from apps/mobile/src/store/translation/store.ts rename to packages/internal/store/src/translation/store.ts index cb013ce0c..f12db9a13 100644 --- a/apps/mobile/src/store/translation/store.ts +++ b/packages/internal/store/src/translation/store.ts @@ -1,9 +1,7 @@ import type { TranslationSchema } from "@follow/database/src/schemas/types" import { TranslationService } from "@follow/database/src/services/translation" - -import { apiClient } from "@/src/lib/api-fetch" -import type { SupportedLanguages } from "@/src/lib/language" -import { checkLanguage } from "@/src/lib/translation" +import type { SupportedLanguages } from "@follow/models/src/types" +import type { SupportedActionLanguage } from "@follow/shared" import { getEntry } from "../entry/getter" import type { Hydratable } from "../internal/base" @@ -77,11 +75,13 @@ class TranslationSyncService { language, withContent, target, + checkLanguage, }: { entryId: string language: SupportedLanguages withContent?: boolean target: "content" | "readabilityContent" + checkLanguage: (params: { content: string; language: SupportedActionLanguage }) => boolean }) { const entry = getEntry(entryId) if (!entry) return diff --git a/apps/mobile/src/store/translation/types.ts b/packages/internal/store/src/translation/types.ts similarity index 100% rename from apps/mobile/src/store/translation/types.ts rename to packages/internal/store/src/translation/types.ts diff --git a/packages/internal/store/src/types.ts b/packages/internal/store/src/types.ts new file mode 100644 index 000000000..a2df0e85e --- /dev/null +++ b/packages/internal/store/src/types.ts @@ -0,0 +1,58 @@ +import type { AppType } from "@follow/shared" +import type { authPlugins } from "@follow/shared/src/hono" +import { inferAdditionalFields, twoFactorClient } from "better-auth/client/plugins" +import type { createAuthClient } from "better-auth/react" +import type { BetterAuthClientPlugin } from "better-auth/types" +import type { hc } from "hono/client" + +type APIClient = ReturnType> + +type AuthPlugin = (typeof authPlugins)[number] + +// eslint-disable-next-line unused-imports/no-unused-vars +const serverPlugins = [ + { + id: "customGetProviders", + $InferServerPlugin: {} as Extract, + }, + { + id: "getAccountInfo", + $InferServerPlugin: {} as Extract, + }, + { + id: "oneTimeToken", + $InferServerPlugin: {} as Extract, + }, + { + id: "getProviders", + $InferServerPlugin: {} as Extract, + }, + inferAdditionalFields({ + user: { + handle: { + type: "string", + required: false, + }, + }, + }), + twoFactorClient(), +] satisfies BetterAuthClientPlugin[] +type AuthClient = ReturnType< + typeof createAuthClient<{ + plugins: typeof serverPlugins + }> +> + +declare global { + const apiClient: APIClient + const authClient: AuthClient +} + +export type GeneralMutationOptions = { + onSuccess?: () => void + onError?: (errorMessage: string) => void +} + +export type GeneralQueryOptions = { + enabled?: boolean +} diff --git a/apps/mobile/src/store/unread/getter.ts b/packages/internal/store/src/unread/getter.ts similarity index 100% rename from apps/mobile/src/store/unread/getter.ts rename to packages/internal/store/src/unread/getter.ts diff --git a/apps/mobile/src/store/unread/hooks.ts b/packages/internal/store/src/unread/hooks.ts similarity index 80% rename from apps/mobile/src/store/unread/hooks.ts rename to packages/internal/store/src/unread/hooks.ts index 1895df837..8cabebbb0 100644 --- a/apps/mobile/src/store/unread/hooks.ts +++ b/packages/internal/store/src/unread/hooks.ts @@ -2,8 +2,6 @@ import type { FeedViewType } from "@follow/constants" import { useMutation, useQuery } from "@tanstack/react-query" import { useCallback, useEffect } from "react" -import { setBadgeCountAsyncWithPermission } from "@/src/lib/permission" - import { useListFeedIds } from "../list/hooks" import { useSubscriptionByView } from "../subscription/hooks" import { unreadSyncService, useUnreadStore } from "./store" @@ -25,18 +23,6 @@ export const useAutoMarkAsRead = (entryId: string) => { }, [entryId, mutate]) } -export function useUnreadCountBadge() { - const unreadCount = useUnreadCounts() - const { mutate, isPending } = useMutation({ - mutationFn: (unread: number) => setBadgeCountAsyncWithPermission(unread), - }) - useEffect(() => { - if (!isPending) { - mutate(unreadCount) - } - }, [unreadCount, mutate, isPending]) -} - export const useUnreadCount = (subscriptionId: string) => { return useUnreadStore((state) => state.data[subscriptionId]) } diff --git a/apps/mobile/src/store/unread/store.ts b/packages/internal/store/src/unread/store.ts similarity index 91% rename from apps/mobile/src/store/unread/store.ts rename to packages/internal/store/src/unread/store.ts index f138c77e5..ae1db0ec3 100644 --- a/apps/mobile/src/store/unread/store.ts +++ b/packages/internal/store/src/unread/store.ts @@ -3,17 +3,12 @@ import type { UnreadSchema } from "@follow/database/src/schemas/types" import { EntryService } from "@follow/database/src/services/entry" import { UnreadService } from "@follow/database/src/services/unread" -import { getGeneralSettings } from "@/src/atoms/settings/general" -import { apiClient } from "@/src/lib/api-fetch" -import { setBadgeCountAsyncWithPermission } from "@/src/lib/permission" - import { getEntry } from "../entry/getter" import { entryActions } from "../entry/store" import type { Hydratable } from "../internal/base" import { createTransaction, createZustandStore } from "../internal/helper" import { getListFeedIds } from "../list/getters" import { getSubscriptionByView } from "../subscription/getter" -import { getAllUnreadCount } from "./getter" import type { PublishAtTimeRangeFilter, UnreadUpdateOptions } from "./types" type SubscriptionId = string @@ -35,13 +30,6 @@ class UnreadSyncService { return res.data } - async updateBadgeAtBackground() { - await this.resetFromRemote() - const allUnreadCount = getAllUnreadCount() - setBadgeCountAsyncWithPermission(allUnreadCount) - return true - } - private async updateUnreadStatus(feedIds: string[], time?: PublishAtTimeRangeFilter) { if (time) { await this.resetFromRemote() @@ -60,6 +48,7 @@ class UnreadSyncService { view, filter, time, + excludePrivate, }: { view: FeedViewType filter?: { @@ -69,12 +58,12 @@ class UnreadSyncService { inboxId?: string } | null time?: PublishAtTimeRangeFilter + excludePrivate: boolean }) { - const { hidePrivateSubscriptionsInTimeline } = getGeneralSettings() await apiClient.reads.all.$post({ json: { view, - excludePrivate: hidePrivateSubscriptionsInTimeline, + excludePrivate, ...filter, ...time, }, diff --git a/apps/mobile/src/store/unread/types.ts b/packages/internal/store/src/unread/types.ts similarity index 100% rename from apps/mobile/src/store/unread/types.ts rename to packages/internal/store/src/unread/types.ts diff --git a/apps/mobile/src/store/user/constants.ts b/packages/internal/store/src/user/constants.ts similarity index 100% rename from apps/mobile/src/store/user/constants.ts rename to packages/internal/store/src/user/constants.ts diff --git a/apps/mobile/src/store/user/getters.ts b/packages/internal/store/src/user/getters.ts similarity index 100% rename from apps/mobile/src/store/user/getters.ts rename to packages/internal/store/src/user/getters.ts diff --git a/apps/mobile/src/store/user/hooks.ts b/packages/internal/store/src/user/hooks.ts similarity index 56% rename from apps/mobile/src/store/user/hooks.ts rename to packages/internal/store/src/user/hooks.ts index b8039fd43..606c86a12 100644 --- a/apps/mobile/src/store/user/hooks.ts +++ b/packages/internal/store/src/user/hooks.ts @@ -2,12 +2,8 @@ import { tracker } from "@follow/tracker" import { useQuery } from "@tanstack/react-query" import { useEffect } from "react" -import { apiClient } from "@/src/lib/api-fetch" -import { kv } from "@/src/lib/kv" -import { useNavigation } from "@/src/lib/navigation/hooks" -import { OnboardingScreen } from "@/src/screens/OnboardingScreen" - -import { isNewUserQueryKey, isOnboardingFinishedStorageKey } from "./constants" +import type { GeneralQueryOptions } from "../types" +import { isNewUserQueryKey } from "./constants" import { userSyncService, useUserStore } from "./store" export const whoamiQueryKey = ["user", "whoami"] @@ -39,30 +35,14 @@ export const useUser = (userId?: string) => { return useUserStore((state) => (userId ? state.users[userId] : undefined)) } -export function useIsNewUser(enabled = true) { +export function useIsNewUser(options?: GeneralQueryOptions) { const { data } = useQuery({ - enabled, + enabled: options?.enabled, queryKey: isNewUserQueryKey, queryFn: async () => { - const isOnboardingFinished = await kv.get(isOnboardingFinishedStorageKey) - if (isOnboardingFinished) { - return false - } - const subscriptions = await apiClient.subscriptions.$get({ query: {} }) return subscriptions.data.length < 5 }, }) return !!data } - -export function useOnboarding() { - const whoami = useWhoami() - const isNewUser = useIsNewUser(!!whoami) - const navigation = useNavigation() - useEffect(() => { - if (isNewUser) { - navigation.presentControllerView(OnboardingScreen, undefined, "fullScreenModal") - } - }, [isNewUser, navigation]) -} diff --git a/apps/mobile/src/store/user/store.ts b/packages/internal/store/src/user/store.ts similarity index 90% rename from apps/mobile/src/store/user/store.ts rename to packages/internal/store/src/user/store.ts index 48e119e78..92b825ce4 100644 --- a/apps/mobile/src/store/user/store.ts +++ b/packages/internal/store/src/user/store.ts @@ -1,15 +1,11 @@ import { UserRole } from "@follow/constants" import type { UserSchema } from "@follow/database/src/schemas/types" import { UserService } from "@follow/database/src/services/user" -import type { AuthSession } from "@follow/shared" - -import { apiClient } from "@/src/lib/api-fetch" -import { changeEmail, sendVerificationEmail, twoFactor, updateUser } from "@/src/lib/auth" -import { toast } from "@/src/lib/toast" -import { honoMorph } from "@/src/morph/hono" +import type { AuthSession } from "@follow/shared/src/hono" import type { Hydratable } from "../internal/base" import { createImmerSetter, createTransaction, createZustandStore } from "../internal/helper" +import { honoMorph } from "../morph/hono" import type { UserProfileEditable } from "./types" export type UserModel = UserSchema @@ -65,7 +61,7 @@ class UserSyncService { }) tx.request(async () => { - await updateUser({ + await authClient.updateUser({ ...data, }) }) @@ -90,8 +86,7 @@ class UserSyncService { async sendVerificationEmail() { const me = get().whoami if (!me?.email) return - await sendVerificationEmail({ email: me.email! }) - toast.success("Verification email sent") + await authClient.sendVerificationEmail({ email: me.email! }) } async updateTwoFactor(enabled: boolean, password: string) { @@ -100,8 +95,8 @@ class UserSyncService { if (!me) throw new Error("user not login") const res = enabled - ? await twoFactor.enable({ password }) - : await twoFactor.disable({ password }) + ? await authClient.twoFactor.enable({ password }) + : await authClient.twoFactor.disable({ password }) if (!res.error) { immerSet((state) => { @@ -128,7 +123,7 @@ class UserSyncService { tx.request(async () => { const { whoami } = get() if (!whoami) return - await changeEmail({ newEmail: email }) + await authClient.changeEmail({ newEmail: email }) }) tx.rollback(() => { immerSet((state) => { diff --git a/apps/mobile/src/store/user/types.ts b/packages/internal/store/src/user/types.ts similarity index 100% rename from apps/mobile/src/store/user/types.ts rename to packages/internal/store/src/user/types.ts diff --git a/packages/internal/store/tsconfig.json b/packages/internal/store/tsconfig.json new file mode 100644 index 000000000..9a5618388 --- /dev/null +++ b/packages/internal/store/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "@follow/configs/tsconfig.extend.json", + "compilerOptions": { + "types": ["vite/client"] + }, + "include": ["src/**/*"] +} diff --git a/packages/internal/utils/package.json b/packages/internal/utils/package.json index fb65682ac..2558904c2 100644 --- a/packages/internal/utils/package.json +++ b/packages/internal/utils/package.json @@ -20,6 +20,11 @@ "require": "./src/*.ts", "import": "./src/*.ts", "types": "./src/*.ts" + }, + "./src/*": { + "require": "./src/*.ts", + "import": "./src/*.ts", + "types": "./src/*.ts" } }, "main": "./exports.ts", diff --git a/packages/internal/utils/src/utils.ts b/packages/internal/utils/src/utils.ts index d22edbd4e..7f2be4bda 100644 --- a/packages/internal/utils/src/utils.ts +++ b/packages/internal/utils/src/utils.ts @@ -4,6 +4,8 @@ import dayjs from "dayjs" import { extendTailwindMerge } from "tailwind-merge" import { parse } from "tldts" +type Nullable = T | null | undefined + const twMerge = extendTailwindMerge({ extend: { theme: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3042bda46..47bbe51c1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -778,6 +778,9 @@ importers: '@follow/shared': specifier: workspace:* version: link:../../packages/internal/shared + '@follow/store': + specifier: workspace:* + version: link:../../packages/internal/store '@follow/tracker': specifier: workspace:* version: link:../../packages/internal/tracker @@ -1689,6 +1692,45 @@ importers: specifier: 3.24.3 version: 3.24.3 + packages/internal/store: + dependencies: + '@follow/configs': + specifier: workspace:* + version: link:../../configs + '@follow/constants': + specifier: workspace:* + version: link:../constants + '@follow/database': + specifier: workspace:* + version: link:../database + '@follow/models': + specifier: workspace:* + version: link:../models + '@follow/shared': + specifier: workspace:* + version: link:../shared + '@follow/tracker': + specifier: workspace:* + version: link:../tracker + '@follow/utils': + specifier: workspace:* + version: link:../utils + '@tanstack/react-query': + specifier: 5.74.7 + version: 5.74.7(react@19.0.0) + es-toolkit: + specifier: 1.36.0 + version: 1.36.0 + immer: + specifier: 10.1.1 + version: 10.1.1(patch_hash=594c60b929bc0a3b56576f1a1787da1aec2a1fba51e3c21ec09c0ed38280af6c) + react: + specifier: 19.0.0 + version: 19.0.0 + zustand: + specifier: 5.0.3 + version: 5.0.3(@types/react@19.1.3)(immer@10.1.1(patch_hash=594c60b929bc0a3b56576f1a1787da1aec2a1fba51e3c21ec09c0ed38280af6c))(react@19.0.0)(use-sync-external-store@1.5.0(react@19.0.0)) + packages/internal/tracker: devDependencies: '@follow/configs': @@ -20164,7 +20206,7 @@ snapshots: debug: 2.6.9 invariant: 2.2.4 metro: 0.82.4(bufferutil@4.0.9) - metro-config: 0.82.4(bufferutil@4.0.9)(utf-8-validate@6.0.5) + metro-config: 0.82.4(bufferutil@4.0.9) metro-core: 0.82.4 semver: 7.7.1 transitivePeerDependencies: @@ -27250,6 +27292,21 @@ snapshots: transitivePeerDependencies: - supports-color + metro-config@0.82.4(bufferutil@4.0.9): + dependencies: + connect: 3.7.0 + cosmiconfig: 5.2.1 + flow-enums-runtime: 0.0.6 + jest-validate: 29.7.0 + metro: 0.82.4(bufferutil@4.0.9) + metro-cache: 0.82.4 + metro-core: 0.82.4 + metro-runtime: 0.82.4 + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + metro-config@0.82.4(bufferutil@4.0.9)(utf-8-validate@6.0.5): dependencies: connect: 3.7.0 @@ -27264,6 +27321,7 @@ snapshots: - bufferutil - supports-color - utf-8-validate + optional: true metro-core@0.82.4: dependencies: @@ -27375,6 +27433,7 @@ snapshots: - bufferutil - supports-color - utf-8-validate + optional: true metro@0.82.4(bufferutil@4.0.9): dependencies: @@ -27402,7 +27461,7 @@ snapshots: metro-babel-transformer: 0.82.4 metro-cache: 0.82.4 metro-cache-key: 0.82.4 - metro-config: 0.82.4(bufferutil@4.0.9)(utf-8-validate@6.0.5) + metro-config: 0.82.4(bufferutil@4.0.9) metro-core: 0.82.4 metro-file-map: 0.82.4 metro-resolver: 0.82.4 @@ -27469,6 +27528,7 @@ snapshots: - bufferutil - supports-color - utf-8-validate + optional: true micromark-core-commonmark@2.0.3: dependencies: