refactor: useWhoami from user store (#4061)
* refactor: useWhoami from user store * update * update * update * update * return all
This commit is contained in:
@@ -1,19 +1,6 @@
|
||||
import type { UserRole } from "@follow/constants"
|
||||
import type { AuthSession } from "@follow/shared/hono"
|
||||
import { atom } from "jotai"
|
||||
|
||||
import { createAtomHooks } from "~/lib/jotai"
|
||||
|
||||
export const [, , useWhoami, , whoami, setWhoami] = createAtomHooks(
|
||||
atom<Nullable<NonNullable<AuthSession>["user"]>>(null),
|
||||
)
|
||||
|
||||
export const [, , useLoginModalShow, useSetLoginModalShow, getLoginModalShow, setLoginModalShow] =
|
||||
createAtomHooks(atom<boolean>(false))
|
||||
|
||||
/**
|
||||
* For public beta trial user
|
||||
*/
|
||||
export const [, , useUserRole, , getUserRole, setUserRole] = createAtomHooks(
|
||||
atom<Nullable<UserRole>>(null),
|
||||
)
|
||||
|
||||
@@ -8,6 +8,8 @@ import { entrySyncServices } from "@follow/store/entry/store"
|
||||
import type { EntryModel } from "@follow/store/entry/types"
|
||||
import { useFeedById } from "@follow/store/feed/hooks"
|
||||
import { useIsInbox } from "@follow/store/inbox/hooks"
|
||||
import { whoami } from "@follow/store/user/getters"
|
||||
import { useUserRole } from "@follow/store/user/hooks"
|
||||
import { doesTextContainHTML } from "@follow/utils/utils"
|
||||
import { useMemo } from "react"
|
||||
|
||||
@@ -21,7 +23,6 @@ import {
|
||||
useEntryIsInReadability,
|
||||
} from "~/atoms/readability"
|
||||
import { useShowSourceContent } from "~/atoms/source-content"
|
||||
import { useUserRole, whoami } from "~/atoms/user"
|
||||
import { ipcServices } from "~/lib/client"
|
||||
import { COMMAND_ID } from "~/modules/command/commands/id"
|
||||
import { getCommand, useRunCommandFn } from "~/modules/command/hooks/use-command"
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
useSubscriptionsByFeedIds,
|
||||
} from "@follow/store/subscription/hooks"
|
||||
import { unreadSyncService } from "@follow/store/unread/store"
|
||||
import { whoami } from "@follow/store/user/getters"
|
||||
import { isBizId } from "@follow/utils/utils"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { useMemo } from "react"
|
||||
@@ -21,7 +22,6 @@ import { toast } from "sonner"
|
||||
import type { FollowMenuItem, MenuItemInput } from "~/atoms/context-menu"
|
||||
import { MenuItemSeparator, MenuItemText } from "~/atoms/context-menu"
|
||||
import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { whoami } from "~/atoms/user"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { copyToClipboard } from "~/lib/clipboard"
|
||||
import { UrlBuilder } from "~/lib/url-builder"
|
||||
|
||||
@@ -5,13 +5,13 @@ import {
|
||||
useFeedSubscriptionCount,
|
||||
useListSubscriptionCount,
|
||||
} from "@follow/store/subscription/hooks"
|
||||
import { useUserRole } from "@follow/store/user/hooks"
|
||||
import { t } from "i18next"
|
||||
import { useCallback } from "react"
|
||||
import { withoutTrailingSlash, withTrailingSlash } from "ufo"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
import { useServerConfigs } from "~/atoms/server-configs"
|
||||
import { useUserRole } from "~/atoms/user"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { CustomSafeError } from "~/errors/CustomSafeError"
|
||||
import { useActivationModal } from "~/modules/activation"
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { ELECTRON_BUILD } from "@follow/shared/constants"
|
||||
import { env } from "@follow/shared/env.desktop"
|
||||
import { whoami } from "@follow/store/user/getters"
|
||||
import { appSessionTraceId } from "@follow/utils/environment"
|
||||
import { version } from "@pkg"
|
||||
import { nanoid } from "nanoid"
|
||||
import { useEffect } from "react"
|
||||
import { createRoutesFromChildren, matchRoutes, useLocation, useNavigationType } from "react-router"
|
||||
|
||||
import { whoami } from "~/atoms/user"
|
||||
|
||||
import { SentryConfig } from "./sentry.config"
|
||||
|
||||
Object.defineProperty(window.Error.prototype, "traceId", {
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
import { RootPortal } from "@follow/components/ui/portal/index.jsx"
|
||||
import { DEV, IN_ELECTRON, PROD } from "@follow/shared/constants"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { preventDefault } from "@follow/utils/dom"
|
||||
import type { PropsWithChildren } from "react"
|
||||
import * as React from "react"
|
||||
@@ -8,7 +9,7 @@ import { Outlet } from "react-router"
|
||||
|
||||
import { setMainContainerElement, setRootContainerElement } from "~/atoms/dom"
|
||||
import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
import { useLoginModalShow, useWhoami } from "~/atoms/user"
|
||||
import { useLoginModalShow } from "~/atoms/user"
|
||||
import { AppErrorBoundary } from "~/components/common/AppErrorBoundary"
|
||||
import { ErrorComponentType } from "~/components/errors/enum"
|
||||
import { PlainModal } from "~/components/ui/modal/stacked/custom-modal"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { lazy, Suspense } from "react"
|
||||
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { useAuthQuery } from "~/hooks/common/useBizQuery"
|
||||
import { settings } from "~/queries/settings"
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
} from "@follow/components/ui/tooltip/index.jsx"
|
||||
import { DEV, MODE } from "@follow/shared/constants"
|
||||
import { env } from "@follow/shared/env.desktop"
|
||||
import { useUserRole } from "@follow/store/user/hooks"
|
||||
|
||||
import { useUserRole } from "~/atoms/user"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
|
||||
import { DebugRegistry } from "../debug/registry"
|
||||
|
||||
@@ -6,6 +6,7 @@ import { collectionSyncService } from "@follow/store/collection/store"
|
||||
import { getEntry } from "@follow/store/entry/getter"
|
||||
import { entrySyncServices } from "@follow/store/entry/store"
|
||||
import { unreadSyncService } from "@follow/store/unread/store"
|
||||
import { useUserRole } from "@follow/store/user/hooks"
|
||||
import { cn, resolveUrlWithBase } from "@follow/utils/utils"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -22,7 +23,6 @@ import {
|
||||
toggleShowSourceContent,
|
||||
useSourceContentModal,
|
||||
} from "~/atoms/source-content"
|
||||
import { useUserRole } from "~/atoms/user"
|
||||
import { SharePanel } from "~/components/common/SharePanel"
|
||||
import { toggleEntryReadability } from "~/hooks/biz/useEntryActions"
|
||||
import { navigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Button } from "@follow/components/ui/button/index.js"
|
||||
import { UserRole } from "@follow/constants"
|
||||
import { useUserRole } from "@follow/store/user/hooks"
|
||||
import { repository } from "@pkg"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
import { useUserRole } from "~/atoms/user"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { CustomSafeError } from "~/errors/CustomSafeError"
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { FeedViewType, views } from "@follow/constants"
|
||||
import { useIsOnline } from "@follow/hooks"
|
||||
import { getFeedById } from "@follow/store/feed/getter"
|
||||
import { useFeedById } from "@follow/store/feed/hooks"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { stopPropagation } from "@follow/utils/dom"
|
||||
import { cn, isBizId } from "@follow/utils/utils"
|
||||
import type { FC } from "react"
|
||||
@@ -15,7 +16,6 @@ import { useNavigate } from "react-router"
|
||||
import { previewBackPath } from "~/atoms/preview"
|
||||
import { useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
import { useTimelineColumnShow } from "~/atoms/sidebar"
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { FEED_COLLECTION_LIST, ROUTE_ENTRY_PENDING } from "~/constants"
|
||||
import { useFollow } from "~/hooks/biz/useFollow"
|
||||
import { getRouteParams, useRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
|
||||
@@ -2,12 +2,12 @@ import { useEntry, useEntryReadHistory } from "@follow/store/entry/hooks"
|
||||
import { useFeedById } from "@follow/store/feed/hooks"
|
||||
import { useInboxById } from "@follow/store/inbox/hooks"
|
||||
import { useEntryTranslation } from "@follow/store/translation/hooks"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { formatEstimatedMins, formatTimeToSeconds } from "@follow/utils"
|
||||
import { titleCase } from "title-case"
|
||||
|
||||
import { useActionLanguage } from "~/atoms/settings/general"
|
||||
import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { RelativeTime } from "~/components/ui/datetime"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { useFeedSafeUrl } from "~/hooks/common/useFeedSafeUrl"
|
||||
|
||||
@@ -3,11 +3,11 @@ import { Divider } from "@follow/components/ui/divider/index.js"
|
||||
import { useEntry } from "@follow/store/entry/hooks"
|
||||
import { useFeedById } from "@follow/store/feed/hooks"
|
||||
import { getUserList } from "@follow/store/user/getters"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { useBoostModal } from "~/modules/boost/hooks"
|
||||
import { useFeedBoostersQuery } from "~/modules/boost/query"
|
||||
import { FeedIcon } from "~/modules/feed/feed-icon"
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
import { AvatarGroup } from "@follow/components/ui/avatar-group/index.js"
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import { useEntryReadHistory } from "@follow/store/entry/hooks"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { useAppLayoutGridContainerWidth } from "~/providers/app-grid-layout-container-provider"
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ import {
|
||||
TooltipTrigger,
|
||||
} from "@follow/components/ui/tooltip/index.jsx"
|
||||
import type { FeedOrListRespModel } from "@follow/models/types"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { replaceImgUrlIfNeed } from "~/lib/img-proxy"
|
||||
import { usePresentUserProfileModal } from "~/modules/profile/hooks"
|
||||
|
||||
|
||||
+1
-1
@@ -1,10 +1,10 @@
|
||||
import { LoadingCircle } from "@follow/components/ui/loading/index.js"
|
||||
import { Tabs, TabsList, TabsTrigger } from "@follow/components/ui/tabs/index.jsx"
|
||||
import { TransactionTypes } from "@follow/models/types"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { getBlockchainExplorerUrl } from "~/lib/utils"
|
||||
import { SettingSectionTitle } from "~/modules/settings/section"
|
||||
import { useWallet, useWalletTransactions } from "~/queries/wallet"
|
||||
|
||||
+1
-1
@@ -14,10 +14,10 @@ import {
|
||||
} from "@follow/components/ui/tooltip/index.jsx"
|
||||
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
|
||||
import type { TransactionTypes } from "@follow/models"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { RelativeTime } from "~/components/ui/datetime"
|
||||
import { getBlockchainExplorerUrl } from "~/lib/utils"
|
||||
import { useWalletTransactions } from "~/queries/wallet"
|
||||
|
||||
+1
-1
@@ -1,10 +1,10 @@
|
||||
import { Logo } from "@follow/components/icons/logo.jsx"
|
||||
import { MotionButtonBase } from "@follow/components/ui/button/index.js"
|
||||
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { usePresentUserProfileModal } from "~/modules/profile/hooks"
|
||||
import { UserAvatar } from "~/modules/user/UserAvatar"
|
||||
import { Balance } from "~/modules/wallet/balance"
|
||||
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
} from "@follow/components/ui/form/index.js"
|
||||
import { Input } from "@follow/components/ui/input/Input.js"
|
||||
import { Label } from "@follow/components/ui/label/index.js"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { userActions } from "@follow/store/user/store"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
@@ -18,7 +20,6 @@ import { useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
import { z } from "zod"
|
||||
|
||||
import { setWhoami, useWhoami } from "~/atoms/user"
|
||||
import { AnimatedCommandButton } from "~/components/ui/button/AnimatedCommandButton"
|
||||
import { CopyButton } from "~/components/ui/button/CopyButton"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
@@ -125,8 +126,7 @@ function EmailManagementForm() {
|
||||
toast.success(t("profile.email.changed_verification_sent"))
|
||||
} else {
|
||||
if (user) {
|
||||
setWhoami({
|
||||
...user,
|
||||
userActions.updateWhoami({
|
||||
email: variables.email,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { isMobile } from "@follow/components/hooks/useMobile.js"
|
||||
import { usePrefetchUser } from "@follow/store/user/hooks"
|
||||
import { usePrefetchUser, useWhoami } from "@follow/store/user/hooks"
|
||||
import { capitalizeFirstLetter } from "@follow/utils/utils"
|
||||
import { createElement, lazy, useCallback } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
import { parse } from "tldts"
|
||||
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { useAsyncModal } from "~/components/ui/modal/helper/useAsyncModal"
|
||||
import { PlainModal } from "~/components/ui/modal/stacked/custom-modal"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
FormMessage,
|
||||
} from "@follow/components/ui/form/index.jsx"
|
||||
import { Input, TextArea } from "@follow/components/ui/input/index.js"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { userActions } from "@follow/store/user/store"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
@@ -18,7 +20,6 @@ import { useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
import { z } from "zod"
|
||||
|
||||
import { setWhoami, useWhoami } from "~/atoms/user"
|
||||
import { AvatarUploadModal } from "~/components/ui/crop/AvatarUploadModal"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { updateUser } from "~/lib/auth"
|
||||
@@ -113,7 +114,7 @@ export const ProfileSettingForm = ({
|
||||
},
|
||||
onSuccess: (_, variables) => {
|
||||
if (user && variables) {
|
||||
setWhoami({ ...user, ...variables })
|
||||
userActions.updateWhoami({ ...variables })
|
||||
}
|
||||
toast(t("profile.updateSuccess"), {
|
||||
duration: 3000,
|
||||
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
} from "@follow/components/ui/form/index.jsx"
|
||||
import { Input, InputOTP, InputOTPGroup, InputOTPSlot } from "@follow/components/ui/input/index.js"
|
||||
import { Label } from "@follow/components/ui/label/index.js"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { userActions } from "@follow/store/user/store"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { m, useAnimation } from "motion/react"
|
||||
@@ -19,7 +21,6 @@ import QRCode from "react-qr-code"
|
||||
import { toast } from "sonner"
|
||||
import { z } from "zod"
|
||||
|
||||
import { setWhoami, useWhoami } from "~/atoms/user"
|
||||
import { useCurrentModal, useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { twoFactor } from "~/lib/auth"
|
||||
import { getFetchErrorInfo } from "~/lib/error-parser"
|
||||
@@ -221,10 +222,7 @@ export const TwoFactorForm = () => {
|
||||
}
|
||||
toast.success(t("profile.two_factor.enabled"))
|
||||
modal.dismiss()
|
||||
setWhoami((prev) => {
|
||||
if (!prev) return prev
|
||||
return { ...prev, twoFactorEnabled: true }
|
||||
})
|
||||
userActions.updateWhoami({ twoFactorEnabled: true })
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
@@ -242,10 +240,7 @@ export const TwoFactorForm = () => {
|
||||
} else {
|
||||
toast.success(t("profile.two_factor.disabled"))
|
||||
modal.dismiss()
|
||||
setWhoami((prev) => {
|
||||
if (!prev) return prev
|
||||
return { ...prev, twoFactorEnabled: false }
|
||||
})
|
||||
userActions.updateWhoami({ twoFactorEnabled: false })
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
+1
-2
@@ -6,7 +6,7 @@ import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
|
||||
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@follow/components/ui/tooltip/index.js"
|
||||
import type { ExtractBizResponse } from "@follow/models"
|
||||
import { usePrefetchUser, useUserById } from "@follow/store/user/hooks"
|
||||
import { usePrefetchUser, useUserById, useWhoami } from "@follow/store/user/hooks"
|
||||
import { nextFrame, stopPropagation } from "@follow/utils/dom"
|
||||
import { getStorageNS } from "@follow/utils/ns"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
@@ -18,7 +18,6 @@ import type { FC } from "react"
|
||||
import { Fragment, memo, useEffect, useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { m } from "~/components/common/Motion"
|
||||
import { useCurrentModal } from "~/components/ui/modal/stacked/hooks"
|
||||
import { useFollow } from "~/hooks/biz/useFollow"
|
||||
|
||||
@@ -10,13 +10,13 @@ import {
|
||||
import { Input } from "@follow/components/ui/input/Input.js"
|
||||
import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
|
||||
import type { RSSHubModel } from "@follow/models"
|
||||
import { whoami } from "@follow/store/user/getters"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useEffect } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { z } from "zod"
|
||||
|
||||
import { whoami } from "~/atoms/user"
|
||||
import { ShikiHighLighter } from "~/components/ui/code-highlighter"
|
||||
import { useShikiDefaultTheme } from "~/components/ui/code-highlighter/shiki/hooks"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
|
||||
@@ -10,13 +10,13 @@ import {
|
||||
} from "@follow/components/ui/form/index.jsx"
|
||||
import { Input } from "@follow/components/ui/input/Input.js"
|
||||
import type { RSSHubModel } from "@follow/models"
|
||||
import { whoami } from "@follow/store/user/getters"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useEffect } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { Trans, useTranslation } from "react-i18next"
|
||||
import { z } from "zod"
|
||||
|
||||
import { whoami } from "~/atoms/user"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { UserAvatar } from "~/modules/user/UserAvatar"
|
||||
import { Queries } from "~/queries"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useUserRole } from "@follow/store/user/hooks"
|
||||
import { useMemo } from "react"
|
||||
|
||||
import { useIsInMASReview, useServerConfigs } from "~/atoms/server-configs"
|
||||
import { useUserRole } from "~/atoms/user"
|
||||
|
||||
import { getMemoizedSettings } from "../settings-glob"
|
||||
import type { SettingPageContext } from "../utils"
|
||||
|
||||
-2
@@ -6,7 +6,6 @@ import {
|
||||
} from "@follow/store/subscription/hooks"
|
||||
import { subscriptionActions } from "@follow/store/subscription/store"
|
||||
import { usePrefetchUnread, useUnreadByView } from "@follow/store/unread/hooks"
|
||||
import { usePrefetchSessionUser } from "@follow/store/user/hooks"
|
||||
import { stopPropagation } from "@follow/utils"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
@@ -17,7 +16,6 @@ import { SortButton } from "./SortButton"
|
||||
|
||||
export const ListHeader = ({ view }: { view: FeedViewType }) => {
|
||||
usePrefetchSubscription()
|
||||
usePrefetchSessionUser()
|
||||
usePrefetchUnread()
|
||||
|
||||
const { t } = useTranslation()
|
||||
|
||||
@@ -4,6 +4,7 @@ import { RootPortal } from "@follow/components/ui/portal/index.js"
|
||||
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/EllipsisWithTooltip.js"
|
||||
import { UserRole } from "@follow/constants"
|
||||
import { useMeasure } from "@follow/hooks"
|
||||
import { useUserRole } from "@follow/store/user/hooks"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { repository } from "@pkg"
|
||||
import type { FC } from "react"
|
||||
@@ -14,7 +15,6 @@ import { useNavigate } from "react-router"
|
||||
import rsshubLogoUrl from "~/assets/rsshub-icon.png?url"
|
||||
import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { useIsZenMode, useSetZenMode } from "~/atoms/settings/ui"
|
||||
import { useUserRole } from "~/atoms/user"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -62,7 +62,7 @@ export const ProfileButton: FC<ProfileButtonProps> = memo((props) => {
|
||||
|
||||
const shortcuts = useCommandShortcuts()
|
||||
|
||||
if (status !== "authenticated") {
|
||||
if (status === "unauthenticated") {
|
||||
return <LoginButton {...props} />
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@follow/components/ui/avatar/index.jsx"
|
||||
import { usePrefetchUser } from "@follow/store/user/hooks"
|
||||
import { usePrefetchUser, useWhoami } from "@follow/store/user/hooks"
|
||||
import { getColorScheme, stringToHue } from "@follow/utils/color"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { replaceImgUrlIfNeed } from "~/lib/img-proxy"
|
||||
import { usePresentUserProfileModal } from "~/modules/profile/hooks"
|
||||
import { useSession } from "~/queries/auth"
|
||||
|
||||
@@ -3,12 +3,12 @@ import { useScrollElementUpdate } from "@follow/components/ui/scroll-area/hooks.
|
||||
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@follow/components/ui/tabs/index.jsx"
|
||||
import { UserRole } from "@follow/constants"
|
||||
import { useUserRole } from "@follow/store/user/hooks"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { createElement } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useSearchParams } from "react-router"
|
||||
|
||||
import { useUserRole } from "~/atoms/user"
|
||||
import { AppErrorBoundary } from "~/components/common/AppErrorBoundary"
|
||||
import { ErrorComponentType } from "~/components/errors/enum"
|
||||
import { useActivationModal } from "~/modules/activation"
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Logo } from "@follow/components/icons/logo.jsx"
|
||||
import { Button } from "@follow/components/ui/button/index.js"
|
||||
import type { RSSHubModel } from "@follow/models"
|
||||
import { whoami } from "@follow/store/user/getters"
|
||||
import { cn, formatNumber } from "@follow/utils/utils"
|
||||
import { memo, useCallback, useEffect } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import RSSHubIconUrl from "~/assets/rsshub-icon.png?url"
|
||||
import { whoami } from "~/atoms/user"
|
||||
import { ErrorTooltip } from "~/components/common/ErrorTooltip"
|
||||
import { HeaderActionButton, HeaderActionGroup } from "~/components/ui/button/HeaderActionButton"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { UserRole } from "@follow/constants"
|
||||
import { useEffect } from "react"
|
||||
|
||||
import { setUserRole, setWhoami } from "~/atoms/user"
|
||||
import { setIntegrationIdentify } from "~/initialize/helper"
|
||||
import { useSession } from "~/queries/auth"
|
||||
|
||||
@@ -10,10 +8,6 @@ export const UserProvider = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (!session?.user) return
|
||||
setWhoami(session.user)
|
||||
if (session.role) {
|
||||
setUserRole(session.role as UserRole)
|
||||
}
|
||||
// @ts-expect-error FIXME
|
||||
setIntegrationIdentify(session.user)
|
||||
}, [session?.role, session?.user])
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import type { AuthSession } from "@follow/shared/hono"
|
||||
import { whoamiQueryKey } from "@follow/store/user/hooks"
|
||||
import { userActions, userSyncService } from "@follow/store/user/store"
|
||||
import { tracker } from "@follow/tracker"
|
||||
import { clearStorage } from "@follow/utils/ns"
|
||||
import type { FetchError } from "ofetch"
|
||||
|
||||
import { setWhoami } from "~/atoms/user"
|
||||
import { QUERY_PERSIST_KEY } from "~/constants"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { getAccountInfo, getSession, signOut as signOutFn } from "~/lib/auth"
|
||||
import { getAccountInfo, signOut as signOutFn } from "~/lib/auth"
|
||||
import { ipcServices } from "~/lib/client"
|
||||
import { defineQuery } from "~/lib/defineQuery"
|
||||
import { clearLocalPersistStoreData } from "~/store/utils/clear"
|
||||
|
||||
export const auth = {
|
||||
getSession: () => defineQuery(["auth", "session"], () => getSession()),
|
||||
getSession: () => defineQuery(whoamiQueryKey, () => userSyncService.whoami()),
|
||||
getAccounts: () => defineQuery(["auth", "accounts"], () => getAccountInfo()),
|
||||
}
|
||||
|
||||
@@ -58,18 +59,18 @@ export const useSession = (options?: { enabled?: boolean }) => {
|
||||
const fetchError = error as FetchError
|
||||
|
||||
return {
|
||||
session: data?.data as AuthSession,
|
||||
session: data as AuthSession,
|
||||
...rest,
|
||||
status: isLoading
|
||||
? "loading"
|
||||
: data?.data
|
||||
: data
|
||||
? "authenticated"
|
||||
: fetchError
|
||||
? "error"
|
||||
: data?.data === null
|
||||
: data === null
|
||||
? "unauthenticated"
|
||||
: "unknown",
|
||||
}
|
||||
} as const
|
||||
}
|
||||
|
||||
export const handleSessionChanges = () => {
|
||||
@@ -81,7 +82,7 @@ export const signOut = async () => {
|
||||
// Clear query cache
|
||||
localStorage.removeItem(QUERY_PERSIST_KEY)
|
||||
|
||||
setWhoami(null)
|
||||
userActions.removeCurrentUser()
|
||||
// clear local store data
|
||||
await clearLocalPersistStoreData()
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UserRole } from "@follow/constants"
|
||||
import type { ServerConfigs } from "@follow/models/types"
|
||||
import { useRole, useWhoami } from "@follow/store/user/hooks"
|
||||
import { useUserRole, useWhoami } from "@follow/store/user/hooks"
|
||||
import * as FileSystem from "expo-file-system"
|
||||
import type { ParseKeys } from "i18next"
|
||||
import type { FC } from "react"
|
||||
@@ -198,7 +198,7 @@ const NavigationLinkGroup: FC<{
|
||||
links: GroupNavigationLink[]
|
||||
}> = ({ links }) => {
|
||||
const navigation = useNavigation()
|
||||
const role = useRole()
|
||||
const role = useUserRole()
|
||||
const { t } = useTranslation("settings")
|
||||
|
||||
return (
|
||||
|
||||
@@ -17,7 +17,7 @@ export const usePrefetchSessionUser = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (query.data) {
|
||||
const user = query.data
|
||||
const { user } = query.data
|
||||
tracker.identify(user)
|
||||
}
|
||||
}, [query.data])
|
||||
@@ -38,7 +38,7 @@ export const useWhoami = () => {
|
||||
return useUserStore((state) => state.whoami)
|
||||
}
|
||||
|
||||
export const useRole = () => {
|
||||
export const useUserRole = () => {
|
||||
return useUserStore((state) => state.role)
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ class UserSyncService {
|
||||
})
|
||||
userActions.upsertMany([user])
|
||||
|
||||
return res.user
|
||||
return res
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
@@ -213,6 +213,13 @@ class UserActions implements Hydratable {
|
||||
})
|
||||
}
|
||||
|
||||
updateWhoami(data: Partial<MeModel>) {
|
||||
immerSet((state) => {
|
||||
if (!state.whoami) return
|
||||
state.whoami = { ...state.whoami, ...data }
|
||||
})
|
||||
}
|
||||
|
||||
async upsertMany(users: UserModel[]) {
|
||||
const tx = createTransaction()
|
||||
tx.store(() => this.upsertManyInSession(users))
|
||||
|
||||
Reference in New Issue
Block a user