Skip to content

Commit

Permalink
Show the banner only once per day
Browse files Browse the repository at this point in the history
Summary: ^

Reviewed By: jknoxville

Differential Revision: D42499338

fbshipit-source-id: 85c1edc676d00a1e442c5490575f8a14465d5a4f
  • Loading branch information
lblasa authored and facebook-github-bot committed Jan 13, 2023
1 parent 8111513 commit f007da9
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion desktop/plugins/public/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f007da9

Please sign in to comment.