Skip to content

Commit e107be5

Browse files
feat: ensure unique splash text on schedule change
1 parent b1e98ca commit e107be5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/views/components/PopupMain.tsx

+13-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,19 @@ export default function PopupMain(): JSX.Element {
6666
};
6767

6868
useEffect(() => {
69-
const randomIndex = Math.floor(Math.random() * splashText.length);
70-
setFunny(
71-
splashText[randomIndex] ?? 'If you are seeing this, something has gone horribly wrong behind the scenes.'
72-
);
73-
}, []);
69+
setFunny(prevFunny => {
70+
// Ensure that the next splash text is not the same as the previous one
71+
const splashTextWithoutCurrent = splashText.filter(text => text !== prevFunny);
72+
const randomIndex = Math.floor(Math.random() * splashTextWithoutCurrent.length);
73+
74+
return (
75+
splashTextWithoutCurrent[randomIndex] ??
76+
'If you are seeing this, something has gone horribly wrong behind the scenes.'
77+
);
78+
});
79+
80+
// Generate a new splash text every time the active schedule changes
81+
}, [activeSchedule.id]);
7482

7583
const handleOpenOptions = async () => {
7684
const url = chrome.runtime.getURL('/options.html');

0 commit comments

Comments
 (0)