From b5eb2ec6db71259d007145fcee9ea3e1db6aa272 Mon Sep 17 00:00:00 2001 From: momofa Date: Mon, 22 Jun 2026 12:18:24 +0800 Subject: [PATCH] fix: preserve current page in sidebar login redirect --- src/components/user/sidebar-user-card.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/user/sidebar-user-card.tsx b/src/components/user/sidebar-user-card.tsx index 59de08a6..3679e41c 100644 --- a/src/components/user/sidebar-user-card.tsx +++ b/src/components/user/sidebar-user-card.tsx @@ -2,7 +2,7 @@ import Image from "next/image" import Link from "next/link" -import { useRouter } from "next/navigation" +import { usePathname, useRouter, useSearchParams } from "next/navigation" import { CalendarDays, CheckCircle2, ChevronLeft, ChevronRight, Heart, Plus, RotateCcw, Settings, Star, Trophy, Users, Wallet, X } from "lucide-react" import { useCallback, useEffect, useMemo, useRef, useState } from "react" @@ -255,8 +255,13 @@ function CalendarPendingStatusIcon({ export function SidebarUserCard({ user, createPostHref = "/write", siteName = "知识型兴趣社区", siteDescription = "把时间浪费在你真正热爱的事情上。这里更适合持续浏览、慢慢讨论、围绕兴趣沉淀长期内容。", siteLogoPath, siteIconPath }: { user: SidebarUserCardData | null; createPostHref?: string; siteName?: string; siteDescription?: string; siteLogoPath?: string | null; siteIconPath?: string | null }) { const router = useRouter() + const pathname = usePathname() + const searchParams = useSearchParams() const { refresh: refreshCurrentUser } = useCurrentUser() const currentUser = user + const currentSearch = searchParams.toString() + const currentPath = `${pathname}${currentSearch ? `?${currentSearch}` : ""}` + const loginHref = buildLoginHrefWithRedirect(currentPath) const [checkInState, setCheckInState] = useState(() => ({ points: user?.points ?? 0, checkedInToday: Boolean(user?.checkedInToday), @@ -386,7 +391,7 @@ export function SidebarUserCard({ user, createPostHref = "/write", siteName = "

{siteDescription}

- +