Files
papermark/lib/webstorage.ts
RajuGangitla 9af1596a5e feat: Add "report" button to document viewer to report abuse (#997)
* added last_used

* improved last used

* Update lib/webstorage.ts

* Update lib/webstorage.ts

* Update lib/webstorage.ts

* resolve merge conflicts

* report button added

* improoved ui

* Squashed commit of the following:

commit 2a293053a8d15ba1bb335a901b4556cfe7a86f16
Author: Marc Seitz <marc@mfts.io>
Date:   Wed Oct 16 18:47:50 2024 +0900

    refactor: change redis keys for better clarify

    - move flag button around

---------

Co-authored-by: Marc Seitz <4049052+mfts@users.noreply.github.com>
Co-authored-by: Marc Seitz <marc@mfts.io>
2024-10-16 19:11:02 +09:00

34 lines
1.1 KiB
TypeScript

/**
* Provides a wrapper around localStorage(and sessionStorage(TODO when needed)) to avoid errors in case of restricted storage access.
*
* TODO: In case of an embed if localStorage is not available(third party), use localStorage of parent(first party) that contains the iframe.
*/
export const localStorage = {
getItem(key: string) {
try {
return window.localStorage.getItem(key);
} catch (e) {
// In case storage is restricted. Possible reasons
// 1. Third Party Context in Chrome Incognito mode.
return null;
}
},
setItem(key: string, value: string) {
try {
window.localStorage.setItem(key, value);
} catch (e) {
// In case storage is restricted. Possible reasons
// 1. Third Party Context in Chrome Incognito mode.
// 2. Storage limit reached
return;
}
},
removeItem: (key: string) => {
try {
window.localStorage.removeItem(key);
} catch (e) {
return;
}
},
};