Compare commits

...

1 Commits

Author SHA1 Message Date
openhands
a2f226dc04 feat: store and restore last visited page using local storage 2025-03-21 02:45:51 +00:00
3 changed files with 49 additions and 4 deletions

View File

@@ -8,6 +8,10 @@ export const useAppLogout = () => {
const { saveUserSettings } = useCurrentSettings();
const handleLogout = async () => {
// Save the current page before logging out
const { saveLastPage } = await import('../utils/last-page');
saveLastPage();
if (config?.APP_MODE === "saas") await logout();
else await saveUserSettings({ unset_github_token: true });
};

View File

@@ -101,6 +101,10 @@ export default function MainApp() {
});
}, []);
const userIsAuthed = !!isAuthed && !authError;
const renderWaitlistModal =
!isFetchingAuth && !userIsAuthed && config.data?.APP_MODE === "saas";
React.useEffect(() => {
// Don't allow users to use the app if it 402s
if (error?.status === 402 && pathname !== "/") {
@@ -110,11 +114,31 @@ export default function MainApp() {
searchParams.delete("free_credits");
navigate("/");
}
}, [error?.status, pathname, isFetching]);
}, [error?.status, pathname, isFetching, navigate, searchParams, t]);
const userIsAuthed = !!isAuthed && !authError;
const renderWaitlistModal =
!isFetchingAuth && !userIsAuthed && config.data?.APP_MODE === "saas";
// Handle redirection to last page after login
React.useEffect(() => {
const handleLastPageRedirect = async () => {
if (userIsAuthed && pathname === '/') {
const { getLastPage, clearLastPage } = await import('#/utils/last-page');
const lastPage = getLastPage();
if (lastPage) {
clearLastPage();
navigate(lastPage);
}
}
};
handleLastPageRedirect();
// Save last page when component unmounts
return () => {
if (userIsAuthed && pathname !== '/') {
import('#/utils/last-page').then(({ saveLastPage }) => {
saveLastPage();
});
}
};
}, [userIsAuthed, pathname, navigate]);
return (
<div

View File

@@ -0,0 +1,17 @@
const LAST_PAGE_KEY = 'openhands_last_page';
export const saveLastPage = () => {
const currentPath = window.location.pathname;
// Don't save login/settings pages
if (!currentPath.includes('/settings') && currentPath !== '/') {
localStorage.setItem(LAST_PAGE_KEY, currentPath);
}
};
export const getLastPage = (): string | null => {
return localStorage.getItem(LAST_PAGE_KEY);
};
export const clearLastPage = () => {
localStorage.removeItem(LAST_PAGE_KEY);
};