From 0f1402bf47e687a531db5a10410557825f77f303 Mon Sep 17 00:00:00 2001 From: Beebles <102569435+beebls@users.noreply.github.com> Date: Fri, 17 Nov 2023 17:16:07 -0700 Subject: [PATCH] add hide motd button --- .../pythonMethods/pluginSettingsMethods.ts | 13 ++++++ src/components/QAMTab/MOTDDisplay.tsx | 43 ++++++++++++++++--- src/index.tsx | 7 +++ src/state/CssLoaderState.tsx | 3 ++ 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/backend/pythonMethods/pluginSettingsMethods.ts b/src/backend/pythonMethods/pluginSettingsMethods.ts index e2fbc37..e13e01f 100644 --- a/src/backend/pythonMethods/pluginSettingsMethods.ts +++ b/src/backend/pythonMethods/pluginSettingsMethods.ts @@ -18,3 +18,16 @@ export function toggleWatchState(bool: boolean, onlyThisSession: boolean = false } ); } + +// Todo: when i rewrite store interop, move this +export function setHiddenMotd(id: string) { + return server!.callPluginMethod<{ key: string; val: string }>("store_write", { + key: "hiddenMotd", + val: id, + }); +} +export function getHiddenMotd() { + return server!.callPluginMethod<{ key: string }, string>("store_read", { + key: "hiddenMotd", + }); +} diff --git a/src/components/QAMTab/MOTDDisplay.tsx b/src/components/QAMTab/MOTDDisplay.tsx index c3c704b..644d4cf 100644 --- a/src/components/QAMTab/MOTDDisplay.tsx +++ b/src/components/QAMTab/MOTDDisplay.tsx @@ -1,10 +1,14 @@ -import { Focusable, PanelSection } from "decky-frontend-lib"; -import { useEffect, useState } from "react"; +import { DialogButton, Focusable, PanelSection } from "decky-frontend-lib"; +import { useEffect, useState, useMemo } from "react"; import { Motd } from "../../apiTypes/Motd"; import { genericGET } from "../../api"; +import { FaTimes } from "react-icons/fa"; +import { useCssLoaderState } from "../../state"; +import { getHiddenMotd, setHiddenMotd } from "../../backend/pythonMethods/pluginSettingsMethods"; export function MOTDDisplay() { const [motd, setMotd] = useState(); + const { hiddenMotd, setGlobalState } = useCssLoaderState(); useEffect(() => { async function getMotd() { const res = await genericGET("/motd", false); @@ -12,6 +16,15 @@ export function MOTDDisplay() { } getMotd(); }, []); + async function dismiss() { + if (motd) { + await setHiddenMotd(motd.id); + const res = await getHiddenMotd(); + if (res.success) { + setGlobalState("hiddenMotd", res.result); + } + } + } const SEVERITIES = { High: { @@ -28,13 +41,16 @@ export function MOTDDisplay() { }, }; + const hidden = useMemo(() => { + return hiddenMotd === motd?.id; + }, [hiddenMotd, motd]); + const severity = SEVERITIES[motd?.severity || "Low"]; - if (motd && motd?.name) { + if (motd && motd?.name && !hidden) { return ( {}} style={{ // Transparency is 20% of the color backgroundColor: `${severity.color}33`, @@ -46,9 +62,24 @@ export function MOTDDisplay() { display: "flex", flexDirection: "column", }} - focusWithinClassName="gpfocuswithin" > - {motd?.name} +
+ {motd?.name} + + + +
{motd?.description}
diff --git a/src/index.tsx b/src/index.tsx index c36bc4c..c0eb4b0 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -156,6 +156,13 @@ export default definePlugin((serverApi: ServerAPI) => { } }); + // Hidden MOTD + python.resolve(python.storeRead("hiddenMotd"), (id: string) => { + if (id) { + state.setGlobalState("hiddenMotd", id); + } + }); + // Nav Patch python.resolve(python.storeRead("enableNavPatch"), (value: string) => { if (value === "true") { diff --git a/src/state/CssLoaderState.tsx b/src/state/CssLoaderState.tsx index 702bf2f..1f46f63 100644 --- a/src/state/CssLoaderState.tsx +++ b/src/state/CssLoaderState.tsx @@ -53,6 +53,7 @@ interface PublicCssLoaderState { currentExpandedTheme: PartialCSSThemeInfo | undefined; browserCardSize: number; backendVersion: number; + hiddenMotd: string; } interface PublicCssLoaderContext extends PublicCssLoaderState { @@ -150,6 +151,7 @@ export class CssLoaderState { }; private submissionThemeList: ThemeQueryResponse = { total: 0, items: [] }; private backendVersion: number = 6; + private hiddenMotd: string = ""; // You can listen to this eventBus' 'stateUpdate' event and use that to trigger a useState or other function that causes a re-render public eventBus = new EventTarget(); @@ -172,6 +174,7 @@ export class CssLoaderState { currentSettingsPageTheme: this.currentSettingsPageTheme, unpinnedThemes: this.unpinnedThemes, isInstalling: this.isInstalling, + hiddenMotd: this.hiddenMotd, navPatchInstance: this.navPatchInstance, selectedRepo: this.selectedRepo,