mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 22:44:25 +01:00
refactor(react/launch_bar): port protected session status widget
This commit is contained in:
parent
991f07e148
commit
c3b22ff737
@ -1,21 +0,0 @@
|
|||||||
import { t } from "../../services/i18n.js";
|
|
||||||
import protectedSessionHolder from "../../services/protected_session_holder.js";
|
|
||||||
import CommandButtonWidget from "./command_button.js";
|
|
||||||
|
|
||||||
export default class ProtectedSessionStatusWidget extends CommandButtonWidget {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.class("launcher-button");
|
|
||||||
|
|
||||||
this.settings.icon = () => (protectedSessionHolder.isProtectedSessionAvailable() ? "bx-check-shield" : "bx-shield-quarter");
|
|
||||||
|
|
||||||
this.settings.title = () => (protectedSessionHolder.isProtectedSessionAvailable() ? t("protected_session_status.active") : t("protected_session_status.inactive"));
|
|
||||||
|
|
||||||
this.settings.command = () => (protectedSessionHolder.isProtectedSessionAvailable() ? "leaveProtectedSession" : "enterProtectedSession");
|
|
||||||
}
|
|
||||||
|
|
||||||
protectedSessionStartedEvent() {
|
|
||||||
this.refreshIcon();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
import CalendarWidget from "../buttons/calendar.js";
|
import CalendarWidget from "../buttons/calendar.js";
|
||||||
import ProtectedSessionStatusWidget from "../buttons/protected_session_status.js";
|
|
||||||
import SyncStatusWidget from "../sync_status.js";
|
import SyncStatusWidget from "../sync_status.js";
|
||||||
import BasicWidget, { wrapReactWidgets } from "../basic_widget.js";
|
import BasicWidget, { wrapReactWidgets } from "../basic_widget.js";
|
||||||
import NoteLauncher from "../buttons/launcher/note_launcher.js";
|
import NoteLauncher from "../buttons/launcher/note_launcher.js";
|
||||||
@ -14,6 +13,7 @@ import BookmarkButtons from "../launch_bar/BookmarkButtons.jsx";
|
|||||||
import SpacerWidget from "../launch_bar/SpacerWidget.jsx";
|
import SpacerWidget from "../launch_bar/SpacerWidget.jsx";
|
||||||
import HistoryNavigationButton from "../launch_bar/HistoryNavigation.jsx";
|
import HistoryNavigationButton from "../launch_bar/HistoryNavigation.jsx";
|
||||||
import AiChatButton from "../launch_bar/AiChatButton.jsx";
|
import AiChatButton from "../launch_bar/AiChatButton.jsx";
|
||||||
|
import ProtectedSessionStatusWidget from "../launch_bar/ProtectedSessionStatusWidget.jsx";
|
||||||
|
|
||||||
interface InnerWidget extends BasicWidget {
|
interface InnerWidget extends BasicWidget {
|
||||||
settings?: {
|
settings?: {
|
||||||
@ -113,7 +113,7 @@ export default class LauncherWidget extends BasicWidget {
|
|||||||
case "bookmarks":
|
case "bookmarks":
|
||||||
return <BookmarkButtons isHorizontalLayout={this.isHorizontalLayout} />
|
return <BookmarkButtons isHorizontalLayout={this.isHorizontalLayout} />
|
||||||
case "protectedSession":
|
case "protectedSession":
|
||||||
return new ProtectedSessionStatusWidget();
|
return <ProtectedSessionStatusWidget />
|
||||||
case "syncStatus":
|
case "syncStatus":
|
||||||
return new SyncStatusWidget();
|
return new SyncStatusWidget();
|
||||||
case "backInHistoryButton":
|
case "backInHistoryButton":
|
||||||
|
|||||||
@ -0,0 +1,33 @@
|
|||||||
|
import { useState } from "preact/hooks";
|
||||||
|
import protected_session_holder from "../../services/protected_session_holder";
|
||||||
|
import { LaunchBarActionButton } from "./launch_bar_widgets";
|
||||||
|
import { useTriliumEvent } from "../react/hooks";
|
||||||
|
import { t } from "../../services/i18n";
|
||||||
|
|
||||||
|
export default function ProtectedSessionStatusWidget() {
|
||||||
|
const protectedSessionAvailable = useProtectedSessionAvailable();
|
||||||
|
|
||||||
|
return (
|
||||||
|
protectedSessionAvailable ? (
|
||||||
|
<LaunchBarActionButton
|
||||||
|
icon="bx bx-check-shield"
|
||||||
|
text={t("protected_session_status.active")}
|
||||||
|
triggerCommand="leaveProtectedSession"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<LaunchBarActionButton
|
||||||
|
icon="bx bx-shield-quarter"
|
||||||
|
text={t("protected_session_status.inactive")}
|
||||||
|
triggerCommand="enterProtectedSession"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function useProtectedSessionAvailable() {
|
||||||
|
const [ protectedSessionAvailable, setProtectedSessionAvailable ] = useState(protected_session_holder.isProtectedSessionAvailable());
|
||||||
|
useTriliumEvent("protectedSessionStarted", () => {
|
||||||
|
setProtectedSessionAvailable(protected_session_holder.isProtectedSessionAvailable());
|
||||||
|
});
|
||||||
|
return protectedSessionAvailable;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user