Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / drive-store / utils / publicRedirectSpotlight.ts
bloba080c37f7edeff78e04fe6642832684e00abe89b
1 // This module manages the logic for showing a spotlight on the public page on the "Open in Drive" button.
2 // The spotlight is designed to be shown only once to each user after they just "Saved" a public share in their Drive.
3 // It uses localStorage to track the spotlight's status across sessions.
4 // Status:
5 // - "pending": Waiting for the spotlight to be showed
6 // - "shown": Spotlight has been shown for this user
8 export const PUBLIC_SHARE_REDIRECT_SPOTLIGHT_KEY = 'public-share-redirect-spotlight';
9 enum PublicShareRedirectSpotlightStatus {
10     Pending = 'pending',
11     Shown = 'shown',
13 export const setPublicRedirectSpotlightToPending = () => {
14     try {
15         localStorage.setItem(PUBLIC_SHARE_REDIRECT_SPOTLIGHT_KEY, PublicShareRedirectSpotlightStatus.Pending);
16     } catch (e) {
17         console.warn(`localStorage was not available to set key ${PUBLIC_SHARE_REDIRECT_SPOTLIGHT_KEY}`);
18     }
21 export const setPublicRedirectSpotlightToShown = () => {
22     try {
23         localStorage.setItem(PUBLIC_SHARE_REDIRECT_SPOTLIGHT_KEY, PublicShareRedirectSpotlightStatus.Shown);
24     } catch (e) {
25         console.warn(`localStorage was not available to set key ${PUBLIC_SHARE_REDIRECT_SPOTLIGHT_KEY}`);
26     }
29 export const needPublicRedirectSpotlight = () => {
30     try {
31         return localStorage.getItem(PUBLIC_SHARE_REDIRECT_SPOTLIGHT_KEY) === PublicShareRedirectSpotlightStatus.Pending;
32     } catch (e) {
33         console.warn(`localStorage was not available to get key ${PUBLIC_SHARE_REDIRECT_SPOTLIGHT_KEY}`);
34         return false;
35     }
38 export const publicRedirectSpotlightWasShown = () => {
39     try {
40         return localStorage.getItem(PUBLIC_SHARE_REDIRECT_SPOTLIGHT_KEY) === PublicShareRedirectSpotlightStatus.Shown;
41     } catch (e) {
42         console.warn(`localStorage was not available to get key ${PUBLIC_SHARE_REDIRECT_SPOTLIGHT_KEY}`);
43         return false;
44     }