mirror of
https://github.com/nocodb/nocodb.git
synced 2026-05-01 02:07:07 +00:00
57 lines
1.2 KiB
TypeScript
57 lines
1.2 KiB
TypeScript
/**
|
|
* Returns an object with methods to manage the last visited base.
|
|
*
|
|
* @returns An object containing:
|
|
* - `key`: The key used for storage.
|
|
* - `get`: A function to retrieve the last visited base.
|
|
* - `set`: A function to set the last visited base.
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* const lastVisitedBase = ncLastVisitedBase();
|
|
* lastVisitedBase.set('my-base');
|
|
* const lastVisited = lastVisitedBase.get();
|
|
* console.log(lastVisited); // Output: 'my-base'
|
|
* ```
|
|
*/
|
|
export const ncBackRoute = (): {
|
|
get: () => string
|
|
set: (value: string) => void
|
|
} => {
|
|
const key = 'ncBackRoute'
|
|
|
|
return {
|
|
get: () => {
|
|
return sessionStorage.getItem(key) || '/'
|
|
},
|
|
set: (value: string) => {
|
|
if (!value) {
|
|
sessionStorage.removeItem(key)
|
|
return
|
|
}
|
|
|
|
sessionStorage.setItem(key, value)
|
|
},
|
|
}
|
|
}
|
|
|
|
export const ncLastVisitedBase = (): {
|
|
key: string
|
|
get: () => string | null
|
|
set: (value: string | null | undefined) => void
|
|
} => {
|
|
const key = 'ncLastVisitedBase'
|
|
|
|
return {
|
|
key,
|
|
get: () => {
|
|
return localStorage.getItem(key)
|
|
},
|
|
set: (value: string | null | undefined) => {
|
|
if (!value) return
|
|
|
|
localStorage.setItem(key, value)
|
|
},
|
|
}
|
|
}
|