Skip to content
Merged
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
59 changes: 57 additions & 2 deletions frontend/app/components/TopNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Link from "next/link";
import { usePathname } from "next/navigation";
import { useMemo } from "react";
import { useEffect, useMemo, useState } from "react";

import NotificationsPanel from "./NotificationsPanel";

Expand All @@ -27,6 +27,35 @@ const NAVIGATION_ITEMS = [
export default function TopNavbar() {
const pathname = usePathname();

const [persistedRoute, setPersistedRoute] =
useState("Home");

const [navigationRecovered, setNavigationRecovered] =
useState(false);

useEffect(() => {
const savedRoute =
sessionStorage.getItem(
"flowforge-active-route"
);

if (savedRoute) {
setPersistedRoute(savedRoute);
setNavigationRecovered(true);
}
}, []);

useEffect(() => {
if (!pathname) {
return;
}

sessionStorage.setItem(
"flowforge-last-path",
pathname
);
}, [pathname]);

const navigationItems = useMemo(() => {
return NAVIGATION_ITEMS.map((item) => ({
...item,
Expand All @@ -42,6 +71,17 @@ export default function TopNavbar() {
);
}, [navigationItems]);

useEffect(() => {
sessionStorage.setItem(
"flowforge-active-route",
activeRouteLabel
);

setPersistedRoute(
activeRouteLabel
);
}, [activeRouteLabel]);

const profileImage = useMemo(
() => "https://i.pravatar.cc/80?img=32",
[]
Expand Down Expand Up @@ -90,9 +130,24 @@ export default function TopNavbar() {
font-medium
"
>
{activeRouteLabel}
{persistedRoute}
</span>

{navigationRecovered && (
<span
className="
hidden xl:inline-flex
rounded-full
bg-primary-container
px-2 py-1
text-[10px]
font-medium
"
>
State Restored
</span>
)}

<button
className="
rounded-full p-2
Expand Down
Loading