mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-18 05:51:55 +08:00
refactor: Remove session update effect and rename NavBar component
This commit is contained in:
parent
d5465246cb
commit
263f62033f
@ -18,12 +18,12 @@ import {
|
||||
TypographyLead,
|
||||
TypographyMuted,
|
||||
} from "@/components/ui/typography";
|
||||
import { NavBar } from "@/components/layout/nav-bar";
|
||||
import { NavBarWrapper } from "@/components/layout/nav-bar-wrapper";
|
||||
|
||||
export default function HomePage() {
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col">
|
||||
<NavBar />
|
||||
<NavBarWrapper />
|
||||
<main className="flex-1">
|
||||
<Section className="pb-0">
|
||||
<Container>
|
||||
|
19
src/components/layout/nav-bar-wrapper.tsx
Normal file
19
src/components/layout/nav-bar-wrapper.tsx
Normal file
@ -0,0 +1,19 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
|
||||
import { NavBar } from "./nav-bar";
|
||||
|
||||
export function NavBarWrapper() {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
useEffect(() => {
|
||||
if (pathname?.startsWith("/dashboard") || pathname?.startsWith("/admin")) {
|
||||
router.refresh();
|
||||
}
|
||||
}, [pathname, router]);
|
||||
|
||||
return <NavBar />;
|
||||
}
|
@ -21,18 +21,11 @@ import { ThemeToggle } from "../theme-toggle";
|
||||
import { Button } from "../ui/button";
|
||||
|
||||
export function NavBar() {
|
||||
const { data: session, status, update } = useSession();
|
||||
const { data: session, status } = useSession();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const user = session?.user;
|
||||
|
||||
// 在 dashboard 或 admin 页面时强制刷新一次 session
|
||||
useEffect(() => {
|
||||
if (pathname?.startsWith("/dashboard") || pathname?.startsWith("/admin")) {
|
||||
update();
|
||||
}
|
||||
}, [pathname, update]);
|
||||
|
||||
const handleSignOut = async () => {
|
||||
await signOut({ redirect: false });
|
||||
router.refresh();
|
||||
|
Loading…
x
Reference in New Issue
Block a user