Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions apps/desktop/layer/renderer/src/atoms/user.ts
Original file line number Diff line number Diff line change
@@ -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),
)
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/layer/renderer/src/hooks/biz/useFollow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions apps/desktop/layer/renderer/src/initialize/sentry.ts
Original file line number Diff line number Diff line change
@@ -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", {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -125,8 +126,7 @@ function EmailManagementForm() {
toast.success(t("profile.email.changed_verification_sent"))
} else {
if (user) {
setWhoami({
...user,
userActions.updateWhoami({
email: variables.email,
})
}
Expand Down
3 changes: 1 addition & 2 deletions apps/desktop/layer/renderer/src/modules/profile/hooks.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -113,7 +114,7 @@ export const ProfileSettingForm = ({
},
onSuccess: (_, variables) => {
if (user && variables) {
setWhoami({ ...user, ...variables })
userActions.updateWhoami({ ...variables })
}
toast(t("profile.updateSuccess"), {
duration: 3000,
Expand Down
13 changes: 4 additions & 9 deletions apps/desktop/layer/renderer/src/modules/profile/two-factor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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>
Expand All @@ -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 })
}
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading
Loading