Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use object (key is type safe) to choice alert message rather than switch #479

Merged
merged 3 commits into from
Jun 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/session/Timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,16 @@ const Timer = ({
setIterationCount(1);

if (window.Notification && Notification.permission !== "granted") {
const alertMessageByNotificationPermission: Readonly<{
[key in NotificationPermission]: string;
}> = {
granted: "Thanks to accept the notification :)",
denied: "You rejected the notification :(Please accept it.",
default: "Can not judge to use notification :(Please accept it.",
};

Notification.requestPermission((result) => {
switch (result) {
case "granted":
alert("Thanks to accept the notification :)");
return;
case "denied":
alert("You rejected the notification :(Please accept it.");
return;
case "default":
alert("Can not judge to use notification :(Please accept it.");
return;
default: {
const _: never = result;
return _;
}
}
alert(alertMessageByNotificationPermission[result]);
});
}
}
Expand Down