feat(auth): implement login requirement for various actions
- Introduced `requiresLogin` property for menu items and actions across multiple components to enforce user authentication. - Added `useRequireLogin` hook to manage login checks and modal presentation. - Updated context menus, action buttons, and settings to utilize the new login guard functionality. - Enhanced user experience by prompting login where necessary, ensuring actions are only accessible to authenticated users. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import { getOS, transformShortcut } from "@follow/utils/utils"
|
||||
import { atom } from "jotai"
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { useRequireLogin } from "~/hooks/common/useRequireLogin"
|
||||
import { ipcServices } from "~/lib/client"
|
||||
import { createAtomHooks } from "~/lib/jotai"
|
||||
import type { ElectronMenuItem } from "~/lib/native-menu"
|
||||
@@ -136,10 +137,32 @@ export enum MenuItemType {
|
||||
|
||||
export const useShowContextMenu = () => {
|
||||
const showWebContextMenu = useShowWebContextMenu()
|
||||
const { withLoginGuard } = useRequireLogin()
|
||||
|
||||
const guardMenuItems = useCallback(
|
||||
(items: FollowMenuItem[]): FollowMenuItem[] =>
|
||||
items.map((item) => {
|
||||
if (item instanceof MenuItemSeparator) {
|
||||
return item
|
||||
}
|
||||
|
||||
const nextSubmenu = item.submenu.length > 0 ? guardMenuItems(item.submenu) : item.submenu
|
||||
let nextItem = nextSubmenu !== item.submenu ? item.extend({ submenu: nextSubmenu }) : item
|
||||
|
||||
if (item.requiresLogin) {
|
||||
nextItem = nextItem.extend({
|
||||
click: withLoginGuard(nextItem.click),
|
||||
})
|
||||
}
|
||||
|
||||
return nextItem
|
||||
}),
|
||||
[withLoginGuard],
|
||||
)
|
||||
|
||||
const showContextMenu = useCallback(
|
||||
async (inputMenu: Array<MenuItemInput>, e: MouseEvent | React.MouseEvent) => {
|
||||
const menuItems = filterNullableMenuItems(inputMenu)
|
||||
const menuItems = guardMenuItems(filterNullableMenuItems(inputMenu))
|
||||
// only show native menu on macOS electron, because in other platform, the native ui is not good
|
||||
if (IN_ELECTRON && getOS() === "macOS") {
|
||||
withDebugMenu(menuItems, e)
|
||||
@@ -148,7 +171,7 @@ export const useShowContextMenu = () => {
|
||||
}
|
||||
await showWebContextMenu(menuItems, e)
|
||||
},
|
||||
[showWebContextMenu],
|
||||
[guardMenuItems, showWebContextMenu],
|
||||
)
|
||||
|
||||
return showContextMenu
|
||||
@@ -170,6 +193,7 @@ export type BaseMenuItemTextConfig = {
|
||||
disabled?: boolean
|
||||
checked?: boolean
|
||||
supportMultipleSelection?: boolean
|
||||
requiresLogin?: boolean
|
||||
}
|
||||
|
||||
export class BaseMenuItemText {
|
||||
@@ -213,6 +237,10 @@ export class BaseMenuItemText {
|
||||
public get supportMultipleSelection() {
|
||||
return this.configs.supportMultipleSelection
|
||||
}
|
||||
|
||||
public get requiresLogin() {
|
||||
return this.configs.requiresLogin || false
|
||||
}
|
||||
}
|
||||
|
||||
export type MenuItemTextConfig = Prettify<
|
||||
|
||||
@@ -26,6 +26,7 @@ import { ipcServices } from "~/lib/client"
|
||||
import { COMMAND_ID } from "~/modules/command/commands/id"
|
||||
import { getCommand, useRunCommandFn } from "~/modules/command/hooks/use-command"
|
||||
import { useCommandShortcuts } from "~/modules/command/hooks/use-command-binding"
|
||||
import { isMutationCommandId } from "~/modules/command/mutation-command-ids"
|
||||
import type { FollowCommandId } from "~/modules/command/types"
|
||||
import { useToolbarOrderMap } from "~/modules/customize-toolbar/hooks"
|
||||
|
||||
@@ -76,6 +77,7 @@ interface EntryActionMenuItemConfig {
|
||||
disabled?: boolean
|
||||
notice?: boolean
|
||||
entryId: string
|
||||
requiresLogin?: boolean
|
||||
}
|
||||
|
||||
export class EntryActionMenuItem extends MenuItemText {
|
||||
@@ -83,14 +85,19 @@ export class EntryActionMenuItem extends MenuItemText {
|
||||
|
||||
constructor(config: EntryActionMenuItemConfig) {
|
||||
const cmd = getCommand(config.id) || null
|
||||
const requiresLogin = config.requiresLogin ?? isMutationCommandId(config.id)
|
||||
super({
|
||||
...config,
|
||||
label: cmd?.label.title || "",
|
||||
click: () => config.onClick?.(),
|
||||
hide: !cmd || config.hide,
|
||||
requiresLogin,
|
||||
})
|
||||
|
||||
this.privateConfig = config
|
||||
this.privateConfig = {
|
||||
...config,
|
||||
requiresLogin,
|
||||
}
|
||||
}
|
||||
|
||||
public get id() {
|
||||
@@ -123,14 +130,19 @@ export class EntryActionDropdownItem extends MenuItemText {
|
||||
|
||||
constructor(config: EntryActionMenuItemConfig & { children?: EntryActionMenuItem[] }) {
|
||||
const cmd = getCommand(config.id) || null
|
||||
const requiresLogin = config.requiresLogin ?? isMutationCommandId(config.id)
|
||||
super({
|
||||
...config,
|
||||
label: cmd?.label.title || "",
|
||||
click: () => config.onClick?.(),
|
||||
hide: !cmd || config.hide,
|
||||
requiresLogin,
|
||||
})
|
||||
|
||||
this.privateConfig = config
|
||||
this.privateConfig = {
|
||||
...config,
|
||||
requiresLogin,
|
||||
}
|
||||
this.children = config.children || []
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ import { useCategoryCreationModal } from "~/modules/settings/tabs/lists/hooks"
|
||||
import { ListCreationModalContent } from "~/modules/settings/tabs/lists/modals"
|
||||
import { useResetFeed } from "~/queries/feed"
|
||||
|
||||
import { useNavigateEntry } from "./useNavigateEntry"
|
||||
import { useBatchUpdateSubscription, useDeleteSubscription } from "./useSubscriptionActions"
|
||||
|
||||
export const useFeedActions = ({
|
||||
@@ -72,7 +71,6 @@ export const useFeedActions = ({
|
||||
const deleteSubscription = useDeleteSubscription({})
|
||||
const claimFeed = useFeedClaimModal()
|
||||
|
||||
const navigateEntry = useNavigateEntry()
|
||||
const isEntryList = type === "entryList"
|
||||
|
||||
const { mutateAsync: addFeedToListMutation } = useAddFeedToFeedList()
|
||||
@@ -101,6 +99,7 @@ export const useFeedActions = ({
|
||||
disabled: isEntryList,
|
||||
click: () => unreadSyncService.markFeedAsRead(isMultipleSelection ? feedIds : [feedId]),
|
||||
supportMultipleSelection: true,
|
||||
requiresLogin: true,
|
||||
}),
|
||||
new MenuItemSeparator(isEntryList),
|
||||
new MenuItemText({
|
||||
@@ -114,6 +113,7 @@ export const useFeedActions = ({
|
||||
content: ({ dismiss }) => <FeedForm id={feedId} onSuccess={dismiss} />,
|
||||
})
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
new MenuItemText({
|
||||
label: isMultipleSelection
|
||||
@@ -131,12 +131,14 @@ export const useFeedActions = ({
|
||||
}
|
||||
deleteSubscription.mutate({ subscription })
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
new MenuItemSeparator(isEntryList),
|
||||
new MenuItemText({
|
||||
label: t("sidebar.feed_column.context_menu.add_feeds_to_list"),
|
||||
disabled: isInbox,
|
||||
supportMultipleSelection: true,
|
||||
requiresLogin: true,
|
||||
submenu: [
|
||||
...listByView.map((list) => {
|
||||
const isIncluded = list.feedIds.includes(feedId)
|
||||
@@ -164,6 +166,7 @@ export const useFeedActions = ({
|
||||
})
|
||||
}
|
||||
},
|
||||
requiresLogin: true,
|
||||
})
|
||||
}),
|
||||
listByView.length > 0 && new MenuItemSeparator(),
|
||||
@@ -176,6 +179,7 @@ export const useFeedActions = ({
|
||||
content: () => <ListCreationModalContent />,
|
||||
})
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@@ -183,6 +187,7 @@ export const useFeedActions = ({
|
||||
label: t("sidebar.feed_column.context_menu.add_feeds_to_category"),
|
||||
disabled: isInbox,
|
||||
supportMultipleSelection: true,
|
||||
requiresLogin: true,
|
||||
submenu: [
|
||||
...Array.from(categories.values()).map((category) => {
|
||||
const isIncluded = isMultipleSelection
|
||||
@@ -198,6 +203,7 @@ export const useFeedActions = ({
|
||||
view: view!,
|
||||
})
|
||||
},
|
||||
requiresLogin: true,
|
||||
})
|
||||
}),
|
||||
listByView.length > 0 && MenuItemSeparator.default,
|
||||
@@ -207,6 +213,7 @@ export const useFeedActions = ({
|
||||
click() {
|
||||
presentCategoryCreationModal(view!, isMultipleSelection ? feedIds : [feedId])
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@@ -222,6 +229,7 @@ export const useFeedActions = ({
|
||||
claimFeed({ feedId })
|
||||
},
|
||||
disabled: isEntryList,
|
||||
requiresLogin: true,
|
||||
}),
|
||||
...(isFeedOwner
|
||||
? [
|
||||
@@ -235,6 +243,7 @@ export const useFeedActions = ({
|
||||
click: () => {
|
||||
resetFeed(feedId)
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
MenuItemSeparator.default,
|
||||
]
|
||||
@@ -293,7 +302,6 @@ export const useFeedActions = ({
|
||||
isInbox,
|
||||
isMultipleSelection,
|
||||
listByView,
|
||||
navigateEntry,
|
||||
present,
|
||||
presentCategoryCreationModal,
|
||||
presentDeleteSubscription,
|
||||
@@ -318,7 +326,6 @@ export const useListActions = ({ listId, view }: { listId: string; view?: FeedVi
|
||||
const { mutateAsync: deleteSubscription } = useDeleteSubscription({})
|
||||
|
||||
const shortcuts = useCommandShortcuts()
|
||||
const navigateEntry = useNavigateEntry()
|
||||
|
||||
const items = useMemo(() => {
|
||||
if (!list) return []
|
||||
@@ -333,11 +340,13 @@ export const useListActions = ({ listId, view }: { listId: string; view?: FeedVi
|
||||
content: ({ dismiss }) => <ListForm id={listId} onSuccess={dismiss} />,
|
||||
})
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
new MenuItemText({
|
||||
label: t("sidebar.feed_actions.unfollow"),
|
||||
shortcut: "$mod+Backspace",
|
||||
click: () => deleteSubscription({ subscription }),
|
||||
requiresLogin: true,
|
||||
}),
|
||||
MenuItemSeparator.default,
|
||||
new MenuItemText({
|
||||
@@ -346,6 +355,7 @@ export const useListActions = ({ listId, view }: { listId: string; view?: FeedVi
|
||||
click: () => {
|
||||
unreadSyncService.markFeedAsRead(list.feedIds)
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
MenuItemSeparator.default,
|
||||
...(list.ownerUserId === whoami()?.id
|
||||
@@ -382,7 +392,7 @@ export const useListActions = ({ listId, view }: { listId: string; view?: FeedVi
|
||||
]
|
||||
|
||||
return items
|
||||
}, [list, t, shortcuts, listId, present, deleteSubscription, subscription, navigateEntry, view])
|
||||
}, [list, t, shortcuts, listId, present, deleteSubscription, subscription, view])
|
||||
|
||||
return items
|
||||
}
|
||||
@@ -405,6 +415,7 @@ export const useInboxActions = ({ inboxId }: { inboxId: string }) => {
|
||||
content: () => <InboxForm asWidget id={inboxId} />,
|
||||
})
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
MenuItemSeparator.default,
|
||||
new MenuItemText({
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
export * from "./useBizQuery"
|
||||
export * from "./useContextMenu"
|
||||
export * from "./useI18n"
|
||||
export * from "./useLoginModal"
|
||||
export * from "./usePreventOverscrollBounce"
|
||||
export * from "./useRequireLogin"
|
||||
export * from "./useSyncTheme"
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { PlainModal } from "~/components/ui/modal/stacked/custom-modal"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { LoginModalContent } from "~/modules/auth/LoginModalContent"
|
||||
|
||||
export const useLoginModal = () => {
|
||||
const { present } = useModalStack()
|
||||
|
||||
return useCallback(() => {
|
||||
present({
|
||||
CustomModalComponent: PlainModal,
|
||||
title: "Login",
|
||||
id: "login",
|
||||
content: () => <LoginModalContent runtime={window.electron ? "app" : "browser"} />,
|
||||
clickOutsideToDismiss: true,
|
||||
})
|
||||
}, [present])
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { useIsLoggedIn } from "@follow/store/user/hooks"
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { useLoginModal } from "./useLoginModal"
|
||||
|
||||
export const useRequireLogin = () => {
|
||||
const isLoggedIn = useIsLoggedIn()
|
||||
const showLoginModal = useLoginModal()
|
||||
|
||||
const ensureLogin = useCallback(() => {
|
||||
if (isLoggedIn) {
|
||||
return true
|
||||
}
|
||||
showLoginModal()
|
||||
return false
|
||||
}, [isLoggedIn, showLoginModal])
|
||||
|
||||
const withLoginGuard = useCallback(
|
||||
<T extends (...args: any[]) => unknown>(action: T) => {
|
||||
if (!action) return action
|
||||
|
||||
return ((...args: Parameters<T>) => {
|
||||
if (!ensureLogin()) {
|
||||
return
|
||||
}
|
||||
return action(...args)
|
||||
}) as T
|
||||
},
|
||||
[ensureLogin],
|
||||
)
|
||||
|
||||
return {
|
||||
isLoggedIn,
|
||||
ensureLogin,
|
||||
withLoginGuard,
|
||||
showLoginModal,
|
||||
}
|
||||
}
|
||||
@@ -382,6 +382,7 @@ const RuleListItem = ({
|
||||
label: t("actions.action_card.summary.delete"),
|
||||
icon: <i className="i-mgc-delete-2-cute-re" />,
|
||||
click: () => handleDelete(index),
|
||||
requiresLogin: true,
|
||||
}),
|
||||
],
|
||||
e,
|
||||
|
||||
@@ -18,6 +18,7 @@ import { useAISettingKey } from "~/atoms/settings/ai"
|
||||
import { useActionLanguage } from "~/atoms/settings/general"
|
||||
import { ROUTE_FEED_IN_FOLDER } from "~/constants"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { useRequireLogin } from "~/hooks/common/useRequireLogin"
|
||||
import { useAutoScroll } from "~/modules/ai-chat/hooks/useAutoScroll"
|
||||
import { useLoadMessages } from "~/modules/ai-chat/hooks/useLoadMessages"
|
||||
import { useMainEntryId } from "~/modules/ai-chat/hooks/useMainEntryId"
|
||||
@@ -54,6 +55,7 @@ const ChatInterfaceContent = ({ centerInputOnEmpty }: ChatInterfaceProps) => {
|
||||
const chatActions = useChatActions()
|
||||
const error = useChatError()
|
||||
const messages = useMessages()
|
||||
const { ensureLogin } = useRequireLogin()
|
||||
|
||||
const isFocusWithIn = useFocusable()
|
||||
|
||||
@@ -180,6 +182,9 @@ const ChatInterfaceContent = ({ centerInputOnEmpty }: ChatInterfaceProps) => {
|
||||
}, [])
|
||||
|
||||
const handleSendMessage = useEventCallback((message: string | EditorState) => {
|
||||
if (!ensureLogin()) {
|
||||
return
|
||||
}
|
||||
resetScrollState()
|
||||
|
||||
const blocks = [] as AIChatContextBlock[]
|
||||
@@ -262,6 +267,9 @@ const ChatInterfaceContent = ({ centerInputOnEmpty }: ChatInterfaceProps) => {
|
||||
})
|
||||
|
||||
const handleRetryLastMessage = useEventCallback(() => {
|
||||
if (!ensureLogin()) {
|
||||
return
|
||||
}
|
||||
if (!lastUserMessage) {
|
||||
return
|
||||
}
|
||||
|
||||
+3
@@ -151,15 +151,18 @@ const ShortcutMenuButton: React.FC<ShortcutMenuButtonProps> = ({
|
||||
new MenuItemText({
|
||||
label: t("shortcuts.actions.edit"),
|
||||
click: () => onEdit(shortcut),
|
||||
requiresLogin: true,
|
||||
}),
|
||||
new MenuItemText({
|
||||
label: t("shortcuts.actions.disable"),
|
||||
click: () => onDisable(shortcut.id),
|
||||
requiresLogin: true,
|
||||
}),
|
||||
!isProtected
|
||||
? new MenuItemText({
|
||||
label: t("shortcuts.actions.delete"),
|
||||
click: () => onDelete(shortcut.id),
|
||||
requiresLogin: true,
|
||||
})
|
||||
: null,
|
||||
],
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from "~/atoms/settings/ai"
|
||||
import { ROUTE_FEED_IN_FOLDER } from "~/constants"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { useRequireLogin } from "~/hooks/common/useRequireLogin"
|
||||
import type { ShortcutData } from "~/modules/ai-chat/editor"
|
||||
import { LexicalAIEditorNodes, ShortcutNode } from "~/modules/ai-chat/editor"
|
||||
import { AIPanelRefsContext } from "~/modules/ai-chat/store/AIChatContext"
|
||||
@@ -44,6 +45,7 @@ export const useSendAIShortcut = () => {
|
||||
const chatActions = useChatActions()
|
||||
const blockActions = useBlockActions()
|
||||
const aiPanelRefs = use(AIPanelRefsContext)
|
||||
const { ensureLogin } = useRequireLogin()
|
||||
|
||||
const staticEditor = useMemo(() => {
|
||||
return createEditor({
|
||||
@@ -142,6 +144,9 @@ export const useSendAIShortcut = () => {
|
||||
|
||||
const sendShortcutMessage = useCallback(
|
||||
(editorState: EditorState, shortcutId?: string) => {
|
||||
if (!ensureLogin()) {
|
||||
return
|
||||
}
|
||||
const contextBlocks = buildContextBlocks()
|
||||
|
||||
staticEditor.setEditorState(editorState)
|
||||
@@ -168,7 +173,7 @@ export const useSendAIShortcut = () => {
|
||||
|
||||
void chatActions.sendMessage(message)
|
||||
},
|
||||
[buildContextBlocks, chatActions, staticEditor],
|
||||
[buildContextBlocks, chatActions, ensureLogin, staticEditor],
|
||||
)
|
||||
|
||||
const prefillInput = useCallback(
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { COMMAND_ID } from "./commands/id"
|
||||
import type { FollowCommandId } from "./types"
|
||||
|
||||
const MUTATION_COMMAND_IDS = new Set<FollowCommandId>([
|
||||
COMMAND_ID.entry.star,
|
||||
COMMAND_ID.entry.toggleAITranslation,
|
||||
COMMAND_ID.entry.read,
|
||||
COMMAND_ID.entry.readAbove,
|
||||
COMMAND_ID.entry.readBelow,
|
||||
COMMAND_ID.entry.delete,
|
||||
COMMAND_ID.entry.readability,
|
||||
COMMAND_ID.integration.saveToEagle,
|
||||
COMMAND_ID.integration.saveToReadwise,
|
||||
COMMAND_ID.integration.saveToInstapaper,
|
||||
COMMAND_ID.integration.saveToObsidian,
|
||||
COMMAND_ID.integration.saveToOutline,
|
||||
COMMAND_ID.integration.saveToReadeck,
|
||||
COMMAND_ID.integration.saveToCubox,
|
||||
COMMAND_ID.integration.saveToZotero,
|
||||
COMMAND_ID.integration.saveToQBittorrent,
|
||||
COMMAND_ID.integration.custom,
|
||||
])
|
||||
|
||||
const MUTATION_PREFIXES = ["integration:custom:"]
|
||||
|
||||
export const isMutationCommandId = (id: string | undefined) => {
|
||||
if (!id) return false
|
||||
if (MUTATION_COMMAND_IDS.has(id as FollowCommandId)) {
|
||||
return true
|
||||
}
|
||||
return MUTATION_PREFIXES.some((prefix) => id.startsWith(prefix))
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import { z } from "zod"
|
||||
|
||||
import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { useRequireLogin } from "~/hooks/common/useRequireLogin"
|
||||
import { followClient } from "~/lib/api-client"
|
||||
|
||||
import { DiscoverFeedCard } from "./DiscoverFeedCard"
|
||||
@@ -127,6 +128,7 @@ export function DiscoverForm({ type = "search" }: { type?: string }) {
|
||||
const atomKey = keywordFromSearch + target
|
||||
const { t } = useTranslation()
|
||||
const isInMASReview = useIsInMASReview()
|
||||
const { ensureLogin } = useRequireLogin()
|
||||
|
||||
const jotaiStore = useStore()
|
||||
const mutation = useMutation({
|
||||
@@ -153,6 +155,9 @@ export function DiscoverForm({ type = "search" }: { type?: string }) {
|
||||
const { present, dismissAll } = useModalStack()
|
||||
|
||||
function onSubmit(values: z.infer<typeof formSchema>) {
|
||||
if (!ensureLogin()) {
|
||||
return
|
||||
}
|
||||
if (FEED_DISCOVERY_INFO[type]!.showModal) {
|
||||
present({
|
||||
title: t("feed_form.add_feed"),
|
||||
|
||||
@@ -14,6 +14,7 @@ import { toast } from "sonner"
|
||||
import { HotkeyScope } from "~/constants"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { useI18n } from "~/hooks/common"
|
||||
import { useRequireLogin } from "~/hooks/common/useRequireLogin"
|
||||
import { COMMAND_ID } from "~/modules/command/commands/id"
|
||||
import { useCommandBinding, useCommandShortcuts } from "~/modules/command/hooks/use-command-binding"
|
||||
|
||||
@@ -34,6 +35,7 @@ export const MarkAllReadButton = ({
|
||||
}: MarkAllButtonProps & { ref?: React.Ref<HTMLButtonElement | null> }) => {
|
||||
const { t } = useTranslation()
|
||||
const { t: commonT } = useTranslation("common")
|
||||
const { ensureLogin } = useRequireLogin()
|
||||
|
||||
// const activeScope = useGlobalFocusableScope()
|
||||
const when = useGlobalFocusableScopeSelector(
|
||||
@@ -50,6 +52,9 @@ export const MarkAllReadButton = ({
|
||||
|
||||
useEffect(() => {
|
||||
return EventBus.subscribe(COMMAND_ID.subscription.markAllAsRead, () => {
|
||||
if (!ensureLogin()) {
|
||||
return
|
||||
}
|
||||
let cancel = false
|
||||
const undo = () => {
|
||||
toast.dismiss(id)
|
||||
@@ -77,7 +82,7 @@ export const MarkAllReadButton = ({
|
||||
},
|
||||
})
|
||||
})
|
||||
}, [t])
|
||||
}, [ensureLogin, t])
|
||||
|
||||
const markAllAsReadShortcut = useCommandShortcuts()[COMMAND_ID.subscription.markAllAsRead]
|
||||
return (
|
||||
@@ -100,6 +105,7 @@ export const MarkAllReadButton = ({
|
||||
className={className}
|
||||
ref={ref}
|
||||
onClick={() => {
|
||||
if (!ensureLogin()) return
|
||||
markAllByRoute(getRouteParams())
|
||||
}}
|
||||
>
|
||||
@@ -135,6 +141,7 @@ export const FlatMarkAllReadButton: FC<
|
||||
}
|
||||
> = (props) => {
|
||||
const t = useI18n()
|
||||
const { ensureLogin } = useRequireLogin()
|
||||
|
||||
const { className, filter, which, buttonClassName, iconClassName } = props
|
||||
const [status, setStatus] = useState<"initial" | "confirm" | "done">("initial")
|
||||
@@ -150,6 +157,7 @@ export const FlatMarkAllReadButton: FC<
|
||||
buttonClassName,
|
||||
)}
|
||||
onClick={() => {
|
||||
if (!ensureLogin()) return
|
||||
markAllByRoute(getRouteParams(), filter)
|
||||
.then(() => setStatus("done"))
|
||||
.catch(() => setStatus("initial"))
|
||||
|
||||
@@ -27,6 +27,7 @@ import { useEntryContextMenu } from "~/hooks/biz/useEntryContextMenu"
|
||||
import { getNavigateEntryPath, useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { getRouteParams, useRouteParams, useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { useShowEntryDetailsColumn } from "~/hooks/biz/useShowEntryDetailsColumn"
|
||||
import { useRequireLogin } from "~/hooks/common/useRequireLogin"
|
||||
|
||||
export const EntryItemWrapper: FC<
|
||||
{
|
||||
@@ -195,6 +196,7 @@ const ActionBar = ({
|
||||
const { view } = useRouteParams()
|
||||
|
||||
const { mainAction } = useSortedEntryActions({ entryId, view })
|
||||
const { withLoginGuard } = useRequireLogin()
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -215,9 +217,12 @@ const ActionBar = ({
|
||||
item instanceof EntryActionMenuItem &&
|
||||
!HIDE_ACTIONS_IN_ENTRY_TOOLBAR_ACTIONS.includes(item.id),
|
||||
) as EntryActionMenuItem[]
|
||||
).map((item) => (
|
||||
<CommandActionButton key={item.id} onClick={item.onClick} size="xs" commandId={item.id} />
|
||||
))}
|
||||
).map((item) => {
|
||||
const handler = item.requiresLogin ? withLoginGuard(item.onClick) : item.onClick
|
||||
return (
|
||||
<CommandActionButton key={item.id} onClick={handler} size="xs" commandId={item.id} />
|
||||
)
|
||||
})}
|
||||
|
||||
<ActionButton
|
||||
onClick={openContextMenu}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { RootPortal } from "@follow/components/ui/portal/index.js"
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { memo } from "react"
|
||||
import { memo, useCallback } from "react"
|
||||
|
||||
import { MenuItemText } from "~/atoms/context-menu"
|
||||
import { CommandActionButton } from "~/components/ui/button/CommandActionButton"
|
||||
@@ -11,15 +11,23 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from "~/components/ui/dropdown-menu/dropdown-menu"
|
||||
import { EntryActionDropdownItem, useSortedEntryActions } from "~/hooks/biz/useEntryActions"
|
||||
import { useRequireLogin } from "~/hooks/common/useRequireLogin"
|
||||
import { useCommand } from "~/modules/command/hooks/use-command"
|
||||
import type { FollowCommandId } from "~/modules/command/types"
|
||||
|
||||
export const EntryHeaderActions = ({ entryId, view }: { entryId: string; view: FeedViewType }) => {
|
||||
const { mainAction: actionConfigs } = useSortedEntryActions({ entryId, view })
|
||||
const { withLoginGuard } = useRequireLogin()
|
||||
const resolveClick = useCallback(
|
||||
(action: MenuItemText | EntryActionDropdownItem) =>
|
||||
action.requiresLogin ? withLoginGuard(action.onClick) : action.onClick,
|
||||
[withLoginGuard],
|
||||
)
|
||||
|
||||
return actionConfigs
|
||||
.filter((item) => item instanceof MenuItemText || item instanceof EntryActionDropdownItem)
|
||||
.map((config) => {
|
||||
const clickHandler = resolveClick(config)
|
||||
const baseTrigger = (
|
||||
<CommandActionButton
|
||||
active={config.active}
|
||||
@@ -27,7 +35,7 @@ export const EntryHeaderActions = ({ entryId, view }: { entryId: string; view: F
|
||||
// Handle shortcut globally
|
||||
disableTriggerShortcut
|
||||
commandId={config.id}
|
||||
onClick={config.onClick!}
|
||||
onClick={clickHandler}
|
||||
shortcut={config.shortcut!}
|
||||
clickableDisabled={config.disabled}
|
||||
highlightMotion={config.notice}
|
||||
@@ -45,7 +53,7 @@ export const EntryHeaderActions = ({ entryId, view }: { entryId: string; view: F
|
||||
<CommandDropdownMenuItem
|
||||
key={child.id}
|
||||
commandId={child.id}
|
||||
onClick={child.onClick!}
|
||||
onClick={resolveClick(child)!}
|
||||
active={child.active}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ActionButton } from "@follow/components/ui/button/index.js"
|
||||
import { RootPortal } from "@follow/components/ui/portal/index.js"
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { useMemo } from "react"
|
||||
import { useCallback, useMemo } from "react"
|
||||
|
||||
import { MenuItemText } from "~/atoms/context-menu"
|
||||
import {
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
EntryActionMenuItem,
|
||||
useSortedEntryActions,
|
||||
} from "~/hooks/biz/useEntryActions"
|
||||
import { useRequireLogin } from "~/hooks/common/useRequireLogin"
|
||||
import { COMMAND_ID } from "~/modules/command/commands/id"
|
||||
import { hasCommand, useCommand, useRunCommandFn } from "~/modules/command/hooks/use-command"
|
||||
import type { FollowCommandId } from "~/modules/command/types"
|
||||
@@ -35,6 +36,12 @@ export const MoreActions = ({
|
||||
hideCustomizeToolbar?: boolean
|
||||
}) => {
|
||||
const { moreAction, mainAction } = useSortedEntryActions({ entryId, view })
|
||||
const { withLoginGuard } = useRequireLogin()
|
||||
const resolveClick = useCallback(
|
||||
(action: MenuItemText | EntryActionDropdownItem | EntryActionMenuItem) =>
|
||||
action.requiresLogin ? withLoginGuard(action.onClick) : action.onClick,
|
||||
[withLoginGuard],
|
||||
)
|
||||
|
||||
const actionConfigs = useMemo(
|
||||
() =>
|
||||
@@ -87,11 +94,12 @@ export const MoreActions = ({
|
||||
{mainAction
|
||||
.filter((config) => config instanceof MenuItemText)
|
||||
.map((config) => {
|
||||
const handler = resolveClick(config)
|
||||
return (
|
||||
<CommandDropdownMenuItem
|
||||
key={config.id}
|
||||
commandId={config.id}
|
||||
onClick={config.onClick!}
|
||||
onClick={handler!}
|
||||
active={config.active}
|
||||
/>
|
||||
)
|
||||
@@ -108,7 +116,7 @@ export const MoreActions = ({
|
||||
<DropdownMenuSubTrigger>
|
||||
<CommandDropdownMenuItem
|
||||
commandId={config.id}
|
||||
onClick={config.onClick!}
|
||||
onClick={resolveClick(config)!}
|
||||
active={config.active}
|
||||
asSubTrigger
|
||||
/>
|
||||
@@ -118,7 +126,7 @@ export const MoreActions = ({
|
||||
<CommandDropdownMenuItem
|
||||
key={child.id}
|
||||
commandId={child.id}
|
||||
onClick={child.onClick!}
|
||||
onClick={resolveClick(child)!}
|
||||
active={child.active}
|
||||
/>
|
||||
))}
|
||||
@@ -129,11 +137,12 @@ export const MoreActions = ({
|
||||
|
||||
// Handle regular MenuItemText
|
||||
if (config instanceof MenuItemText) {
|
||||
const handler = resolveClick(config)
|
||||
return (
|
||||
<CommandDropdownMenuItem
|
||||
key={config.id}
|
||||
commandId={config.id}
|
||||
onClick={config.onClick!}
|
||||
onClick={handler!}
|
||||
active={config.active}
|
||||
/>
|
||||
)
|
||||
@@ -148,7 +157,7 @@ export const MoreActions = ({
|
||||
<CommandDropdownMenuItem
|
||||
key={config.id}
|
||||
commandId={config.id}
|
||||
onClick={config.onClick!}
|
||||
onClick={resolveClick(config)!}
|
||||
active={config.active}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -1 +1,10 @@
|
||||
export const SETTING_MODAL_ID = "setting-modal"
|
||||
|
||||
export const GUEST_ALLOWED_SETTING_TABS = ["general", "appearance", "about", "shortcuts"] as const
|
||||
|
||||
const GUEST_ALLOWED_SETTING_TABS_SET = new Set<string>(GUEST_ALLOWED_SETTING_TABS)
|
||||
|
||||
export const isGuestAccessibleSettingTab = (tab?: string | null) => {
|
||||
if (!tab) return false
|
||||
return GUEST_ALLOWED_SETTING_TABS_SET.has(tab)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
|
||||
import { useIsLoggedIn } from "@follow/store/user/hooks"
|
||||
import { clsx, cn } from "@follow/utils"
|
||||
import { repository } from "@pkg"
|
||||
import type { FC } from "react"
|
||||
@@ -16,8 +17,10 @@ import { Trans } from "react-i18next"
|
||||
import { useLoaderData } from "react-router"
|
||||
|
||||
import { ModalClose } from "~/components/ui/modal/stacked/components"
|
||||
import { useRequireLogin } from "~/hooks/common/useRequireLogin"
|
||||
import { SettingsTitle } from "~/modules/settings/title"
|
||||
|
||||
import { isGuestAccessibleSettingTab } from "../constants"
|
||||
import { useAvailableSettings } from "../hooks/use-setting-ctx"
|
||||
import { SettingSectionHighlightIdContext } from "../section"
|
||||
import { getSettingPages } from "../settings-glob"
|
||||
@@ -61,6 +64,8 @@ const Content: FC<{
|
||||
const availableSettings = useAvailableSettings()
|
||||
const tab = useSettingTab()
|
||||
const setTab = useSetSettingTab()
|
||||
const isLoggedIn = useIsLoggedIn()
|
||||
const { ensureLogin } = useRequireLogin()
|
||||
|
||||
useEffect(() => {
|
||||
if (availableSettings.length === 0) return
|
||||
@@ -69,6 +74,12 @@ const Content: FC<{
|
||||
}
|
||||
}, [availableSettings, setTab, tab])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn && tab && !isGuestAccessibleSettingTab(tab)) {
|
||||
ensureLogin()
|
||||
}
|
||||
}, [ensureLogin, isLoggedIn, tab])
|
||||
|
||||
const activeSetting = useMemo(() => {
|
||||
if (availableSettings.length === 0) return
|
||||
if (tab) {
|
||||
@@ -80,6 +91,9 @@ const Content: FC<{
|
||||
return availableSettings[0]
|
||||
}, [availableSettings, tab])
|
||||
|
||||
const tabAccessible =
|
||||
!!activeSetting && (isLoggedIn || isGuestAccessibleSettingTab(activeSetting.path))
|
||||
|
||||
const key = useDeferredValue(activeSetting?.path ?? "")
|
||||
const pages = getSettingPages()
|
||||
const page = key ? pages[key] : undefined
|
||||
@@ -144,6 +158,28 @@ const Content: FC<{
|
||||
const config = (useLoaderData() || loader || {}) as SettingPageConfig
|
||||
if (!Component || !activeSetting) return null
|
||||
|
||||
if (!tabAccessible) {
|
||||
return (
|
||||
<>
|
||||
<SettingsTitle
|
||||
loader={loader}
|
||||
className={clsx(
|
||||
"relative mb-0 border-b border-transparent px-8 transition-colors duration-200",
|
||||
!scrollerAtTop ? "border-border" : "",
|
||||
)}
|
||||
/>
|
||||
<ModalClose />
|
||||
<button
|
||||
type="button"
|
||||
className="flex flex-1 items-center justify-center px-12 text-center text-text-secondary"
|
||||
onClick={ensureLogin}
|
||||
>
|
||||
Please log in to access this setting.
|
||||
</button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Suspense>
|
||||
<SettingsTitle
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Folo } from "@follow/components/icons/folo.js"
|
||||
import { Logo } from "@follow/components/icons/logo.jsx"
|
||||
import { LetsIconsResizeDownRightLight } from "@follow/components/icons/resize.jsx"
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { useIsLoggedIn } from "@follow/store/user/hooks"
|
||||
import { preventDefault } from "@follow/utils/dom"
|
||||
import { cn, getOS } from "@follow/utils/utils"
|
||||
import { atom, useAtomValue, useSetAtom } from "jotai"
|
||||
@@ -17,9 +18,10 @@ import { m } from "~/components/common/Motion"
|
||||
import { resizableOnly } from "~/components/ui/modal"
|
||||
import { useModalResizeAndDrag } from "~/components/ui/modal/stacked/internal/use-drag"
|
||||
import { ElECTRON_CUSTOM_TITLEBAR_HEIGHT } from "~/constants"
|
||||
import { useRequireLogin } from "~/hooks/common/useRequireLogin"
|
||||
import { useUpgradePlanModal } from "~/modules/plan"
|
||||
|
||||
import { SETTING_MODAL_ID } from "../constants"
|
||||
import { isGuestAccessibleSettingTab, SETTING_MODAL_ID } from "../constants"
|
||||
import { EnhancedSettingsIndicator } from "../helper/EnhancedIndicator"
|
||||
import { SettingSyncIndicator } from "../helper/SyncIndicator"
|
||||
import { useAvailableSettings, useSettingPageContext } from "../hooks/use-setting-ctx"
|
||||
@@ -158,13 +160,20 @@ const SettingItemButtonImpl = (props: {
|
||||
path: string
|
||||
isActive: boolean
|
||||
onChange?: (tab: string) => void
|
||||
guestLocked?: boolean
|
||||
}) => {
|
||||
const { setTab, item, path, onChange, isActive } = props
|
||||
const { setTab, item, path, onChange, isActive, guestLocked = false } = props
|
||||
const { disableIf } = item
|
||||
|
||||
const ctx = useSettingPageContext()
|
||||
const { ensureLogin } = useRequireLogin()
|
||||
|
||||
const [disabled, why] = disableIf?.(ctx) || [false, DisableWhy.Noop]
|
||||
const [disabledByConfig, whyFromConfig = DisableWhy.Noop] = disableIf?.(ctx) || [
|
||||
false,
|
||||
DisableWhy.Noop,
|
||||
]
|
||||
const disabled = guestLocked || disabledByConfig
|
||||
const why = disabledByConfig ? whyFromConfig : DisableWhy.Noop
|
||||
const presentActivationModal = useUpgradePlanModal()
|
||||
|
||||
return (
|
||||
@@ -173,10 +182,15 @@ const SettingItemButtonImpl = (props: {
|
||||
"my-0.5 flex w-full items-center rounded-lg px-2.5 py-0.5 leading-loose text-text",
|
||||
isActive && "!bg-theme-item-active !text-text",
|
||||
!IN_ELECTRON && "duration-200 hover:bg-theme-item-hover",
|
||||
disabled && "cursor-not-allowed opacity-50",
|
||||
disabled && "opacity-50",
|
||||
disabledByConfig && "cursor-not-allowed",
|
||||
)}
|
||||
type="button"
|
||||
onClick={useCallback(() => {
|
||||
if (guestLocked) {
|
||||
ensureLogin()
|
||||
return
|
||||
}
|
||||
if (disabled) {
|
||||
switch (why) {
|
||||
case DisableWhy.NotActivation: {
|
||||
@@ -190,7 +204,17 @@ const SettingItemButtonImpl = (props: {
|
||||
}
|
||||
setTab(path)
|
||||
onChange?.(path)
|
||||
}, [disabled, why, presentActivationModal, setTab, path, onChange])}
|
||||
}, [
|
||||
disabled,
|
||||
disabledByConfig,
|
||||
ensureLogin,
|
||||
guestLocked,
|
||||
onChange,
|
||||
path,
|
||||
presentActivationModal,
|
||||
setTab,
|
||||
why,
|
||||
])}
|
||||
>
|
||||
<SettingsSidebarTitle path={path} className="text-[0.94rem] font-medium" />
|
||||
</button>
|
||||
@@ -204,8 +228,11 @@ export const SidebarItems = memo((props: { onChange?: (tab: string) => void }) =
|
||||
const setTab = useSetSettingTab()
|
||||
const tab = useSettingTab()
|
||||
const availableSettings = useAvailableSettings()
|
||||
const isLoggedIn = useIsLoggedIn()
|
||||
|
||||
return availableSettings.map((t) => {
|
||||
const isActive = tab === t.path
|
||||
const guestLocked = !isLoggedIn && !isGuestAccessibleSettingTab(t.path)
|
||||
return (
|
||||
<SettingItemButton
|
||||
key={t.path}
|
||||
@@ -214,6 +241,7 @@ export const SidebarItems = memo((props: { onChange?: (tab: string) => void }) =
|
||||
item={t}
|
||||
path={t.path}
|
||||
onChange={onChange}
|
||||
guestLocked={guestLocked}
|
||||
/>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -197,10 +197,12 @@ function FeedCategoryImpl({
|
||||
click: () => {
|
||||
unreadSyncService.markFeedAsRead(ids)
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
new MenuItemSeparator(),
|
||||
new MenuItemText({
|
||||
label: t("sidebar.feed_column.context_menu.add_feeds_to_list"),
|
||||
requiresLogin: true,
|
||||
submenu: listList
|
||||
?.map(
|
||||
(list) =>
|
||||
@@ -212,6 +214,7 @@ function FeedCategoryImpl({
|
||||
listId: list.id,
|
||||
})
|
||||
},
|
||||
requiresLogin: true,
|
||||
}) as MenuItemInput,
|
||||
)
|
||||
.concat(listList?.length > 0 ? [new MenuItemSeparator()] : [])
|
||||
@@ -224,6 +227,7 @@ function FeedCategoryImpl({
|
||||
content: () => <ListCreationModalContent />,
|
||||
})
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
@@ -241,14 +245,17 @@ function FeedCategoryImpl({
|
||||
click() {
|
||||
return changeCategoryView(v.view)
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
),
|
||||
requiresLogin: true,
|
||||
}),
|
||||
new MenuItemText({
|
||||
label: t("sidebar.feed_column.context_menu.rename_category"),
|
||||
click: () => {
|
||||
setIsCategoryEditing(true)
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
new MenuItemText({
|
||||
label: t("sidebar.feed_column.context_menu.ungroup_category"),
|
||||
@@ -261,6 +268,7 @@ function FeedCategoryImpl({
|
||||
content: () => <CategoryRemoveDialogContent category={folderName!} view={view} />,
|
||||
})
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
new MenuItemText({
|
||||
label: t("sidebar.feed_column.context_menu.unsubscribe_category"),
|
||||
@@ -275,6 +283,7 @@ function FeedCategoryImpl({
|
||||
),
|
||||
})
|
||||
},
|
||||
requiresLogin: true,
|
||||
}),
|
||||
],
|
||||
e,
|
||||
|
||||
@@ -118,10 +118,12 @@ const useSubscriptionTabContextMenu = ({
|
||||
label: t("sidebar.timeline_tabs.hide_tab"),
|
||||
click: handleHide,
|
||||
disabled: !canHide,
|
||||
requiresLogin: true,
|
||||
}),
|
||||
new MenuItemText({
|
||||
label: t("sidebar.timeline_tabs.customize"),
|
||||
click: showTimelineTabsSettingsModal,
|
||||
requiresLogin: true,
|
||||
}),
|
||||
],
|
||||
event,
|
||||
|
||||
@@ -23,14 +23,12 @@ import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
import { setTimelineColumnShow, useSubscriptionColumnShow } from "~/atoms/sidebar"
|
||||
import { Focusable } from "~/components/common/Focusable"
|
||||
import { PlainModal } from "~/components/ui/modal/stacked/custom-modal"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { HotkeyScope } from "~/constants"
|
||||
import { useBackHome } from "~/hooks/biz/useNavigateEntry"
|
||||
import { useReduceMotion } from "~/hooks/biz/useReduceMotion"
|
||||
import { parseView, useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { useTimelineList } from "~/hooks/biz/useTimelineList"
|
||||
import { LoginModalContent } from "~/modules/auth/LoginModalContent"
|
||||
import { useLoginModal } from "~/hooks/common"
|
||||
import { useSettingModal } from "~/modules/settings/modal/useSettingModal"
|
||||
|
||||
import { WindowUnderBlur } from "../../components/ui/background"
|
||||
@@ -288,69 +286,60 @@ const SubscriptionLimitNotice: FC = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="px-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openSettings("plan")}
|
||||
className="-mx-3 my-1 flex items-start gap-2 border-red/30 bg-red/10 px-1.5 py-2 text-left text-xs leading-snug text-red transition-colors hover:border-red hover:bg-red/15 focus:outline-none focus-visible:ring-2 focus-visible:ring-red/40"
|
||||
>
|
||||
<span className="ml-1 text-lg">😢</span>
|
||||
<p>
|
||||
<Trans
|
||||
i18nKey="subscription_limit_warning"
|
||||
values={{
|
||||
feedCount,
|
||||
rsshubCount,
|
||||
feedLimit,
|
||||
rsshubLimit,
|
||||
}}
|
||||
components={{
|
||||
b: <b key="b" />,
|
||||
br: <br key="br" />,
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openSettings("plan")}
|
||||
className="my-1 flex items-start gap-2 border-red/30 bg-red/10 px-1.5 py-2 text-left text-xs leading-snug text-red transition-colors hover:border-red hover:bg-red/15 focus:outline-none focus-visible:ring-2 focus-visible:ring-red/40"
|
||||
>
|
||||
<span className="ml-1 text-lg">😢</span>
|
||||
<p>
|
||||
<Trans
|
||||
i18nKey="subscription_limit_warning"
|
||||
values={{
|
||||
feedCount,
|
||||
rsshubCount,
|
||||
feedLimit,
|
||||
rsshubLimit,
|
||||
}}
|
||||
components={{
|
||||
b: <b key="b" />,
|
||||
br: <br key="br" />,
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
const NotLoggedInNotice: FC = () => {
|
||||
const isLoggedIn = useIsLoggedIn()
|
||||
const modalStack = useModalStack()
|
||||
|
||||
const isInMASReview = useIsInMASReview()
|
||||
|
||||
const presentLoginModal = useLoginModal()
|
||||
if (isLoggedIn || isInMASReview) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="px-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
modalStack.present({
|
||||
CustomModalComponent: PlainModal,
|
||||
title: "Login",
|
||||
id: "login",
|
||||
content: () => <LoginModalContent runtime={window.electron ? "app" : "browser"} />,
|
||||
clickOutsideToDismiss: true,
|
||||
})
|
||||
}}
|
||||
className="-mx-3 my-1 flex items-start gap-2 border-blue/30 bg-blue/10 px-1.5 py-2 text-left text-xs leading-snug text-blue transition-colors hover:border-blue hover:bg-blue/15 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue/40"
|
||||
>
|
||||
<span className="ml-1 text-lg">👤</span>
|
||||
<p>
|
||||
<Trans
|
||||
i18nKey="not_logged_in_notice"
|
||||
components={{
|
||||
b: <b key="b" />,
|
||||
br: <br key="br" />,
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
presentLoginModal()
|
||||
}}
|
||||
className="my-1 flex items-start gap-2 border-blue/30 bg-blue/10 px-1.5 py-2 text-left text-xs leading-snug text-blue transition-colors hover:border-blue hover:bg-blue/15 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue/40"
|
||||
>
|
||||
<span className="ml-1 text-lg">👤</span>
|
||||
<p>
|
||||
<Trans
|
||||
i18nKey="not_logged_in_notice"
|
||||
components={{
|
||||
b: <b key="b" />,
|
||||
br: <br key="br" />,
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
import { UserArrowLeftIcon } from "@follow/components/icons/user.jsx"
|
||||
import { LucideLogIn } from "@follow/components/icons/user.jsx"
|
||||
import { ActionButton } from "@follow/components/ui/button/index.js"
|
||||
import type { FC } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { LoginModalContent } from "~/modules/auth/LoginModalContent"
|
||||
|
||||
import { PlainModal } from "../../components/ui/modal/stacked/custom-modal"
|
||||
import { useModalStack } from "../../components/ui/modal/stacked/hooks"
|
||||
import { useLoginModal } from "~/hooks/common"
|
||||
|
||||
export interface LoginProps {
|
||||
method?: "redirect" | "modal"
|
||||
}
|
||||
export const LoginButton: FC<LoginProps> = (props) => {
|
||||
const { method } = props
|
||||
const modalStack = useModalStack()
|
||||
const presentLoginModal = useLoginModal()
|
||||
const { t } = useTranslation()
|
||||
const Content = (
|
||||
<ActionButton
|
||||
@@ -21,19 +18,13 @@ export const LoginButton: FC<LoginProps> = (props) => {
|
||||
onClick={
|
||||
method === "modal"
|
||||
? () => {
|
||||
modalStack.present({
|
||||
CustomModalComponent: PlainModal,
|
||||
title: "Login",
|
||||
id: "login",
|
||||
content: () => <LoginModalContent runtime={window.electron ? "app" : "browser"} />,
|
||||
clickOutsideToDismiss: true,
|
||||
})
|
||||
presentLoginModal()
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
tooltip={t("words.login")}
|
||||
>
|
||||
<UserArrowLeftIcon className="size-4" />
|
||||
<LucideLogIn className="size-4" />
|
||||
</ActionButton>
|
||||
)
|
||||
return method === "modal" ? Content : <a href="/login">{Content}</a>
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import type { SVGAttributes } from "react"
|
||||
import type { SVGProps } from "react"
|
||||
|
||||
export function UserArrowLeftIcon(props: SVGAttributes<SVGElement>) {
|
||||
export function LucideLogIn(props: SVGProps<SVGSVGElement>) {
|
||||
return (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" {...props}>
|
||||
{/* Icon from Lucide by Lucide Contributors - https://github.com/lucide-icons/lucide/blob/main/LICENSE */}
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M11 2.5C8.52 2.5 6.5 4.52 6.5 7s2.02 4.5 4.5 4.5 4.5-2.02 4.5-4.5-2.02-4.5-4.5-4.5m0 1c1.939 0 3.5 1.561 3.5 3.5s-1.561 3.5-3.5 3.5A3.49 3.49 0 0 1 7.5 7c0-1.939 1.561-3.5 3.5-3.5m5.574 9.1a10.5 10.5 0 0 0-1.857 1.789.975.975 0 0 0 0 1.222c.543.67 1.166 1.271 1.857 1.79l.6-.801c-.425-.319-.776-.716-1.14-1.1H21v-1h-4.967c.365-.384.716-.781 1.14-1.1zM7 14.5c-2.48 0-4.5 2.02-4.5 4.5 0 1.375 1.125 2.5 2.5 2.5h10v-1H5c-.834 0-1.5-.666-1.5-1.5 0-1.939 1.561-3.5 3.5-3.5h4v-1z"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
d="m10 17l5-5l-5-5m5 5H3m12-9h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"
|
||||
/>
|
||||
</svg>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user