From f007da93d387ab804b725cdf8c34777719ff97ce Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Fri, 13 Jan 2023 07:36:20 -0800 Subject: [PATCH] Show the banner only once per day Summary: ^ Reviewed By: jknoxville Differential Revision: D42499338 fbshipit-source-id: 85c1edc676d00a1e442c5490575f8a14465d5a4f --- desktop/plugins/public/layout/index.tsx | 33 ++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/desktop/plugins/public/layout/index.tsx b/desktop/plugins/public/layout/index.tsx index eb1cd45e2..a27c068bf 100644 --- a/desktop/plugins/public/layout/index.tsx +++ b/desktop/plugins/public/layout/index.tsx @@ -337,7 +337,38 @@ export default class LayoutPlugin extends FlipperPlugin< return; } - const key = `open-ui-debugger-${Date.now()}`; + const lastShownTimestampKey = + 'layout-plugin-UIDebuggerBannerLastShownTimestamp'; + let lastShownTimestampFromStorage = undefined; + try { + lastShownTimestampFromStorage = window.localStorage.getItem( + lastShownTimestampKey, + ); + } catch (e) {} + + if (lastShownTimestampFromStorage) { + const WithinOneDay = (timestamp: number) => { + const Day = 1 * 24 * 60 * 60 * 1000; + const DayAgo = Date.now() - Day; + + return timestamp > DayAgo; + }; + const lastShownTimestamp = Number(lastShownTimestampFromStorage); + if (WithinOneDay(lastShownTimestamp)) { + // The banner was shown less than 24-hours ago, don't show it again. + return; + } + } + + const lastShownTimestamp = Date.now(); + try { + window.localStorage.setItem( + lastShownTimestampKey, + String(lastShownTimestamp), + ); + } catch (e) {} + + const key = `open-ui-debugger-${lastShownTimestamp}`; const btn = (