mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Direct users to last visited site when possible
Summary: When clicking the logo in the top-left corner, or finishing a tutorial, we now direct users to the site they last visited, if possible. If unknown, a new redirect endpoint, /welcome/home, is used instead, which directs users to a sensible location based on the number of sites they have. Test Plan: Browser tests. Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D3878
This commit is contained in:
@@ -85,6 +85,10 @@ export function getLoginOrSignupUrl(nextUrl: string = _getCurrentUrl()): string
|
||||
return _getLoginLogoutUrl('signin', nextUrl);
|
||||
}
|
||||
|
||||
export function getWelcomeHomeUrl() {
|
||||
return _buildUrl('welcome/home').href;
|
||||
}
|
||||
|
||||
// Returns the relative URL (i.e. path) of the current page, except when it's the
|
||||
// "/signed-out" page, in which case it returns the home page ("/").
|
||||
// This is a good URL to use for a post-login redirect.
|
||||
@@ -97,14 +101,19 @@ function _getCurrentUrl(): string {
|
||||
|
||||
// Returns the URL for the given login page, with 'next' param optionally set.
|
||||
function _getLoginLogoutUrl(page: 'login'|'logout'|'signin'|'signup', nextUrl?: string | null): string {
|
||||
const startUrl = new URL(window.location.href);
|
||||
startUrl.pathname = addOrgToPath('', window.location.href, true) + '/' + page;
|
||||
startUrl.search = '';
|
||||
startUrl.hash = '';
|
||||
const startUrl = _buildUrl(page);
|
||||
if (nextUrl) { startUrl.searchParams.set('next', nextUrl); }
|
||||
return startUrl.href;
|
||||
}
|
||||
|
||||
function _buildUrl(page?: string): URL {
|
||||
const startUrl = new URL(window.location.href);
|
||||
startUrl.pathname = addOrgToPath('', window.location.href, true) + '/' + (page ?? '');
|
||||
startUrl.search = '';
|
||||
startUrl.hash = '';
|
||||
return startUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the interface expected by UrlState. It is only exported for the sake of tests; the
|
||||
* only public interface is the urlState() accessor.
|
||||
|
||||
Reference in New Issue
Block a user