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:
@@ -26,14 +26,24 @@ export function sessionStorageBoolObs(key: string, defValue = false): Observable
|
||||
return getStorageBoolObs(getSessionStorage(), key, defValue);
|
||||
}
|
||||
|
||||
function getStorageObs(store: Storage, key: string, defaultValue?: string) {
|
||||
const obs = Observable.create<string|null>(null, store.getItem(key) ?? defaultValue ?? null);
|
||||
obs.addListener((val) => (val === null) ? store.removeItem(key) : store.setItem(key, val));
|
||||
return obs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to create a string observable whose state is stored in localStorage.
|
||||
*/
|
||||
export function localStorageObs(key: string, defaultValue?: string): Observable<string|null> {
|
||||
const store = getStorage();
|
||||
const obs = Observable.create<string|null>(null, store.getItem(key) ?? defaultValue ?? null);
|
||||
obs.addListener((val) => (val === null) ? store.removeItem(key) : store.setItem(key, val));
|
||||
return obs;
|
||||
return getStorageObs(getStorage(), key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to `localStorageObs`, but always uses sessionStorage (or an in-memory equivalent).
|
||||
*/
|
||||
export function sessionStorageObs(key: string, defaultValue?: string): Observable<string|null> {
|
||||
return getStorageObs(getSessionStorage(), key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user