(UI fix) UI does not reload when you login / open a new tab (#6909)

* store current page on url

* update menu history
This commit is contained in:
Ishaan Jaff 2024-11-25 22:41:45 -08:00 committed by GitHub
parent c60261c3bc
commit e952c666f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 14 deletions

View file

@ -82,16 +82,26 @@ const CreateKeyPage = () => {
const invitation_id = searchParams.get("invitation_id");
const token = getCookie('token');
// Get page from URL, default to 'api-keys' if not present
const [page, setPage] = useState(() => {
if (typeof window !== 'undefined') {
return localStorage.getItem('selectedPage') || "api-keys";
}
return "api-keys";
return searchParams.get('page') || 'api-keys';
});
useEffect(() => {
localStorage.setItem('selectedPage', page);
}, [page]);
// Custom setPage function that updates URL
const updatePage = (newPage: string) => {
// Update URL without full page reload
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.set('page', newPage);
// Use Next.js router to update URL
window.history.pushState(
null,
'',
`?${newSearchParams.toString()}`
);
setPage(newPage);
};
const [accessToken, setAccessToken] = useState<string | null>(null);
@ -173,7 +183,7 @@ const CreateKeyPage = () => {
<div className="flex flex-1 overflow-auto">
<div className="mt-8">
<Sidebar
setPage={setPage}
setPage={updatePage}
userRole={userRole}
defaultSelectedKey={page}
/>

View file

@ -7,7 +7,7 @@ const { Sider } = Layout;
// Define the props type
interface SidebarProps {
setPage: React.Dispatch<React.SetStateAction<string>>;
setPage: (page: string) => void;
userRole: string;
defaultSelectedKey: string;
}
@ -67,7 +67,15 @@ const Sidebar: React.FC<SidebarProps> = ({
style={{ height: "100%", borderRight: 0 }}
>
{filteredMenuItems.map(item => (
<Menu.Item key={item.key} onClick={() => setPage(item.page)}>
<Menu.Item
key={item.key}
onClick={() => {
const newSearchParams = new URLSearchParams(window.location.search);
newSearchParams.set('page', item.page);
window.history.pushState(null, '', `?${newSearchParams.toString()}`);
setPage(item.page);
}}
>
<Text>{item.label}</Text>
</Menu.Item>
))}