Skip to content

Commit 82a3764

Browse files
committed
refactor: useWhoami from user store
1 parent 0f656d5 commit 82a3764

File tree

35 files changed

+65
-82
lines changed

35 files changed

+65
-82
lines changed
Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1-
import type { UserRole } from "@follow/constants"
2-
import type { AuthSession } from "@follow/shared/hono"
31
import { atom } from "jotai"
42

53
import { createAtomHooks } from "~/lib/jotai"
64

7-
export const [, , useWhoami, , whoami, setWhoami] = createAtomHooks(
8-
atom<Nullable<NonNullable<AuthSession>["user"]>>(null),
9-
)
10-
115
export const [, , useLoginModalShow, useSetLoginModalShow, getLoginModalShow, setLoginModalShow] =
126
createAtomHooks(atom<boolean>(false))
13-
14-
/**
15-
* For public beta trial user
16-
*/
17-
export const [, , useUserRole, , getUserRole, setUserRole] = createAtomHooks(
18-
atom<Nullable<UserRole>>(null),
19-
)

apps/desktop/layer/renderer/src/hooks/biz/useEntryActions.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { entrySyncServices } from "@follow/store/entry/store"
88
import type { EntryModel } from "@follow/store/entry/types"
99
import { useFeedById } from "@follow/store/feed/hooks"
1010
import { useIsInbox } from "@follow/store/inbox/hooks"
11+
import { whoami } from "@follow/store/user/getters"
12+
import { useRole } from "@follow/store/user/hooks"
1113
import { doesTextContainHTML } from "@follow/utils/utils"
1214
import { useMemo } from "react"
1315

@@ -21,7 +23,6 @@ import {
2123
useEntryIsInReadability,
2224
} from "~/atoms/readability"
2325
import { useShowSourceContent } from "~/atoms/source-content"
24-
import { useUserRole, whoami } from "~/atoms/user"
2526
import { ipcServices } from "~/lib/client"
2627
import { COMMAND_ID } from "~/modules/command/commands/id"
2728
import { getCommand, useRunCommandFn } from "~/modules/command/hooks/use-command"
@@ -178,7 +179,7 @@ export const useEntryActions = ({
178179
const runCmdFn = useRunCommandFn()
179180
const hasEntry = !!entry
180181

181-
const userRole = useUserRole()
182+
const userRole = useRole()
182183

183184
const shortcuts = useCommandShortcuts()
184185

apps/desktop/layer/renderer/src/hooks/biz/useFeedActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
useSubscriptionsByFeedIds,
1313
} from "@follow/store/subscription/hooks"
1414
import { unreadSyncService } from "@follow/store/unread/store"
15+
import { whoami } from "@follow/store/user/getters"
1516
import { isBizId } from "@follow/utils/utils"
1617
import { useMutation } from "@tanstack/react-query"
1718
import { useMemo } from "react"
@@ -21,7 +22,6 @@ import { toast } from "sonner"
2122
import type { FollowMenuItem, MenuItemInput } from "~/atoms/context-menu"
2223
import { MenuItemSeparator, MenuItemText } from "~/atoms/context-menu"
2324
import { useIsInMASReview } from "~/atoms/server-configs"
24-
import { whoami } from "~/atoms/user"
2525
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
2626
import { copyToClipboard } from "~/lib/clipboard"
2727
import { UrlBuilder } from "~/lib/url-builder"

apps/desktop/layer/renderer/src/hooks/biz/useFollow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import {
55
useFeedSubscriptionCount,
66
useListSubscriptionCount,
77
} from "@follow/store/subscription/hooks"
8+
import { useRole } from "@follow/store/user/hooks"
89
import { t } from "i18next"
910
import { useCallback } from "react"
1011
import { withoutTrailingSlash, withTrailingSlash } from "ufo"
1112
import { useEventCallback } from "usehooks-ts"
1213

1314
import { useServerConfigs } from "~/atoms/server-configs"
14-
import { useUserRole } from "~/atoms/user"
1515
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
1616
import { CustomSafeError } from "~/errors/CustomSafeError"
1717
import { useActivationModal } from "~/modules/activation"
@@ -21,7 +21,7 @@ import type { ListFormDataValuesType } from "~/modules/discover/ListForm"
2121
import { ListForm } from "~/modules/discover/ListForm"
2222

2323
const useCanFollowMoreInboxAndNotify = () => {
24-
const role = useUserRole()
24+
const role = useRole()
2525
const listCurrentCount = useListSubscriptionCount()
2626
const feedCurrentCount = useFeedSubscriptionCount()
2727
const presentActivationModal = useActivationModal()

apps/desktop/layer/renderer/src/initialize/sentry.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { ELECTRON_BUILD } from "@follow/shared/constants"
22
import { env } from "@follow/shared/env.desktop"
3+
import { whoami } from "@follow/store/user/getters"
34
import { appSessionTraceId } from "@follow/utils/environment"
45
import { version } from "@pkg"
56
import { nanoid } from "nanoid"
67
import { useEffect } from "react"
78
import { createRoutesFromChildren, matchRoutes, useLocation, useNavigationType } from "react-router"
89

9-
import { whoami } from "~/atoms/user"
10-
1110
import { SentryConfig } from "./sentry.config"
1211

1312
Object.defineProperty(window.Error.prototype, "traceId", {

apps/desktop/layer/renderer/src/modules/app-layout/subscription-column/MainDestopLayout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RootPortal } from "@follow/components/ui/portal/index.jsx"
22
import { DEV, IN_ELECTRON, PROD } from "@follow/shared/constants"
3+
import { useWhoami } from "@follow/store/user/hooks"
34
import { preventDefault } from "@follow/utils/dom"
45
import type { PropsWithChildren } from "react"
56
import * as React from "react"
@@ -8,7 +9,7 @@ import { Outlet } from "react-router"
89

910
import { setMainContainerElement, setRootContainerElement } from "~/atoms/dom"
1011
import { useUISettingKey } from "~/atoms/settings/ui"
11-
import { useLoginModalShow, useWhoami } from "~/atoms/user"
12+
import { useLoginModalShow } from "~/atoms/user"
1213
import { AppErrorBoundary } from "~/components/common/AppErrorBoundary"
1314
import { ErrorComponentType } from "~/components/errors/enum"
1415
import { PlainModal } from "~/components/ui/modal/stacked/custom-modal"

apps/desktop/layer/renderer/src/modules/app-layout/subscription-column/components/NewUserGuide.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { useWhoami } from "@follow/store/user/hooks"
12
import { lazy, Suspense } from "react"
23

3-
import { useWhoami } from "~/atoms/user"
44
import { useAuthQuery } from "~/hooks/common/useBizQuery"
55
import { settings } from "~/queries/settings"
66

apps/desktop/layer/renderer/src/modules/app/EnvironmentIndicator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import {
77
} from "@follow/components/ui/tooltip/index.jsx"
88
import { DEV, MODE } from "@follow/shared/constants"
99
import { env } from "@follow/shared/env.desktop"
10+
import { useRole } from "@follow/store/user/hooks"
1011

11-
import { useUserRole } from "~/atoms/user"
1212
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
1313

1414
import { DebugRegistry } from "../debug/registry"
1515

1616
export const EnvironmentIndicator = () => {
17-
const role = useUserRole()
17+
const role = useRole()
1818
const { present } = useModalStack()
1919
return (
2020
<Tooltip>

apps/desktop/layer/renderer/src/modules/command/commands/entry.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { collectionSyncService } from "@follow/store/collection/store"
66
import { getEntry } from "@follow/store/entry/getter"
77
import { entrySyncServices } from "@follow/store/entry/store"
88
import { unreadSyncService } from "@follow/store/unread/store"
9+
import { useRole } from "@follow/store/user/hooks"
910
import { cn, resolveUrlWithBase } from "@follow/utils/utils"
1011
import { useMutation } from "@tanstack/react-query"
1112
import { useTranslation } from "react-i18next"
@@ -22,7 +23,6 @@ import {
2223
toggleShowSourceContent,
2324
useSourceContentModal,
2425
} from "~/atoms/source-content"
25-
import { useUserRole } from "~/atoms/user"
2626
import { SharePanel } from "~/components/common/SharePanel"
2727
import { toggleEntryReadability } from "~/hooks/biz/useEntryActions"
2828
import { navigateEntry } from "~/hooks/biz/useNavigateEntry"
@@ -109,7 +109,7 @@ export const useRegisterEntryCommands = () => {
109109
const read = useRead()
110110
const unread = useUnread()
111111

112-
const role = useUserRole()
112+
const role = useRole()
113113
const presentActivationModal = useActivationModal()
114114

115115
const voice = useGeneralSettingKey("voice")

apps/desktop/layer/renderer/src/modules/discover/DiscoverInboxList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Button } from "@follow/components/ui/button/index.js"
22
import { UserRole } from "@follow/constants"
3+
import { useRole } from "@follow/store/user/hooks"
34
import { repository } from "@pkg"
45
import { useTranslation } from "react-i18next"
56
import { useEventCallback } from "usehooks-ts"
67

7-
import { useUserRole } from "~/atoms/user"
88
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
99
import { CustomSafeError } from "~/errors/CustomSafeError"
1010

@@ -13,7 +13,7 @@ import { InboxTable } from "./Inbox"
1313
import { InboxForm } from "./InboxForm"
1414

1515
const useCanCreateMoreInboxAndNotify = () => {
16-
const role = useUserRole()
16+
const role = useRole()
1717
const presentActivationModal = useActivationModal()
1818

1919
return useEventCallback(() => {

0 commit comments

Comments
 (0)