2024-04-10 21:24:11 +02:00
|
|
|
import {z} from "zod";
|
2023-05-18 16:18:24 +02:00
|
|
|
|
2021-06-15 16:17:28 +02:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-07-06 16:11:26 +02:00
|
|
|
import * as dialog_widget from "./dialog_widget";
|
|
|
|
import {$t_html} from "./i18n";
|
2021-06-15 16:17:28 +02:00
|
|
|
import {localstorage} from "./localstorage";
|
|
|
|
|
2023-05-18 16:22:20 +02:00
|
|
|
export function get_hotkey_deprecation_notice(
|
|
|
|
originalHotkey: string,
|
|
|
|
replacementHotkey: string,
|
|
|
|
): string {
|
2021-07-06 16:11:26 +02:00
|
|
|
return $t_html(
|
2021-06-15 16:17:28 +02:00
|
|
|
{
|
|
|
|
defaultMessage:
|
|
|
|
'We\'ve replaced the "{originalHotkey}" hotkey with "{replacementHotkey}" to make this common shortcut easier to trigger.',
|
|
|
|
},
|
|
|
|
{originalHotkey, replacementHotkey},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-18 16:22:20 +02:00
|
|
|
let shown_deprecation_notices: string[] = [];
|
2021-06-15 16:17:28 +02:00
|
|
|
|
2023-05-18 16:22:20 +02:00
|
|
|
export function maybe_show_deprecation_notice(key: string): void {
|
2021-06-15 16:17:28 +02:00
|
|
|
let message;
|
2023-02-03 12:25:44 +01:00
|
|
|
switch (key) {
|
2023-03-08 21:49:08 +01:00
|
|
|
case "Shift + C":
|
|
|
|
message = get_hotkey_deprecation_notice("Shift + C", "X");
|
2023-02-03 12:25:44 +01:00
|
|
|
break;
|
|
|
|
case "Shift + S":
|
|
|
|
message = get_hotkey_deprecation_notice("Shift + S", "S");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
blueslip.error("Unexpected deprecation notice for hotkey:", {key});
|
|
|
|
return;
|
2021-06-15 16:17:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Here we handle the tracking for showing deprecation notices,
|
|
|
|
// whether or not local storage is available.
|
|
|
|
if (localstorage.supported()) {
|
2023-05-18 16:18:24 +02:00
|
|
|
const notices_from_storage = localStorage.getItem("shown_deprecation_notices");
|
2021-06-15 16:17:28 +02:00
|
|
|
if (notices_from_storage !== null) {
|
2023-05-18 16:18:24 +02:00
|
|
|
const parsed_notices_from_storage = z
|
|
|
|
.array(z.string())
|
|
|
|
.parse(JSON.parse(notices_from_storage));
|
|
|
|
|
|
|
|
shown_deprecation_notices = parsed_notices_from_storage;
|
2021-06-15 16:17:28 +02:00
|
|
|
} else {
|
|
|
|
shown_deprecation_notices = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!shown_deprecation_notices.includes(key)) {
|
2021-07-06 16:11:26 +02:00
|
|
|
dialog_widget.launch({
|
|
|
|
html_heading: $t_html({defaultMessage: "Deprecation notice"}),
|
|
|
|
html_body: message,
|
|
|
|
html_submit_button: $t_html({defaultMessage: "Got it"}),
|
2023-05-18 16:22:20 +02:00
|
|
|
on_click() {
|
|
|
|
return;
|
|
|
|
},
|
2021-07-06 16:11:26 +02:00
|
|
|
close_on_submit: true,
|
|
|
|
focus_submit_on_open: true,
|
|
|
|
single_footer_button: true,
|
|
|
|
});
|
2021-06-15 16:18:09 +02:00
|
|
|
|
2021-06-15 16:17:28 +02:00
|
|
|
shown_deprecation_notices.push(key);
|
|
|
|
if (localstorage.supported()) {
|
|
|
|
localStorage.setItem(
|
|
|
|
"shown_deprecation_notices",
|
|
|
|
JSON.stringify(shown_deprecation_notices),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|