Show the banner only once per day

Summary: ^

Reviewed By: jknoxville

Differential Revision: D42499338

fbshipit-source-id: 85c1edc676d00a1e442c5490575f8a14465d5a4f
This commit is contained in:
Lorenzo Blasa
2023-01-13 07:36:20 -08:00
committed by Facebook GitHub Bot
parent 8111513e95
commit f007da93d3

View File

@@ -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 = (
<Button
type="primary"