2025-02-11 19:16:11 +02:00
|
|
|
import type { EventData } from "../components/app_context.js";
|
|
|
|
import type FNote from "../entities/fnote.js";
|
2024-09-08 22:04:22 +03:00
|
|
|
import { t } from "../services/i18n.js";
|
2021-05-26 22:41:55 +02:00
|
|
|
import protectedSessionService from "../services/protected_session.js";
|
2021-12-20 17:30:47 +01:00
|
|
|
import SwitchWidget from "./switch.js";
|
2021-05-26 22:41:55 +02:00
|
|
|
|
2021-12-20 17:30:47 +01:00
|
|
|
export default class ProtectedNoteSwitchWidget extends SwitchWidget {
|
|
|
|
doRender() {
|
|
|
|
super.doRender();
|
2021-05-26 22:41:55 +02:00
|
|
|
|
2025-01-21 04:21:01 +02:00
|
|
|
this.switchOnName = t("protect_note.toggle-on");
|
|
|
|
this.switchOnTooltip = t("protect_note.toggle-on-hint");
|
2021-05-26 22:41:55 +02:00
|
|
|
|
2025-01-21 04:21:01 +02:00
|
|
|
this.switchOffName = t("protect_note.toggle-off");
|
|
|
|
this.switchOffTooltip = t("protect_note.toggle-off-hint");
|
2021-12-20 17:30:47 +01:00
|
|
|
}
|
2021-05-26 22:41:55 +02:00
|
|
|
|
2021-12-20 17:30:47 +01:00
|
|
|
switchOn() {
|
2025-02-11 19:16:11 +02:00
|
|
|
if (this.noteId) {
|
|
|
|
protectedSessionService.protectNote(this.noteId, true, false);
|
|
|
|
}
|
2021-12-20 17:30:47 +01:00
|
|
|
}
|
2021-05-26 22:41:55 +02:00
|
|
|
|
2021-12-20 17:30:47 +01:00
|
|
|
switchOff() {
|
2025-02-11 19:16:11 +02:00
|
|
|
if (this.noteId) {
|
|
|
|
protectedSessionService.protectNote(this.noteId, false, false);
|
|
|
|
}
|
2021-05-26 22:41:55 +02:00
|
|
|
}
|
|
|
|
|
2025-02-11 19:16:11 +02:00
|
|
|
async refreshWithNote(note: FNote) {
|
2025-01-21 04:21:01 +02:00
|
|
|
this.isToggled = note.isProtected;
|
2021-05-26 22:41:55 +02:00
|
|
|
}
|
|
|
|
|
2025-02-11 19:16:11 +02:00
|
|
|
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
2021-05-26 22:41:55 +02:00
|
|
|
if (loadResults.isNoteReloaded(this.noteId)) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|