From 5a212e95fc2dfb6725b6996b4a72a2acd8a6b942 Mon Sep 17 00:00:00 2001 From: Beebles <102569435+beebls@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:57:21 -0600 Subject: feat(motd): add motd component (untested) --- frontend/src/components/MotdDisplay.tsx | 112 ++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 frontend/src/components/MotdDisplay.tsx (limited to 'frontend/src/components/MotdDisplay.tsx') diff --git a/frontend/src/components/MotdDisplay.tsx b/frontend/src/components/MotdDisplay.tsx new file mode 100644 index 00000000..3c651b11 --- /dev/null +++ b/frontend/src/components/MotdDisplay.tsx @@ -0,0 +1,112 @@ +import {useEffect, useMemo, useState} from 'react' +import { getMotd, Motd } from '../store'; +import { useSetting } from '../utils/hooks/useSetting'; +import { DialogButton, Focusable, PanelSection } from '@decky/ui'; +import { FaTimes } from 'react-icons/fa'; + +const SEVERITIES = { + High: { + color: "#bb1414", + text: "#fff", + }, + Medium: { + color: "#bbbb14", + text: "#fff", + }, + Low: { + color: "#1488bb", + text: "#fff", + }, +}; + +const welcomeMotd: Motd = { + id: "welcomeMotd", + name: "Welcome to Decky!", + date: Date.now().toString(), + description: "We hope you enjoy using Decky! If you have any questions or feedback, please let us know.", + severity: "Low", +} + +export function MotdDisplay() { + const [motd, setMotd] = useState(null); + // showWelcome will display a welcome motd, the welcome motd has an id of "welcome" and once that is saved to hiddenMotdId, it will not show again + const [hiddenMotdId, setHiddenMotdId] = useSetting("hiddenMotdId", "showWelcome") + + async function fetchMotd() { + const motd = await getMotd(); + setMotd(motd); + } + + useEffect(() => { + void fetchMotd(); + }, []) + + useEffect(() => { + if (hiddenMotdId === 'showWelcome') { + setMotd(welcomeMotd); + } + }, [hiddenMotdId]) + + function hideMotd() { + if (motd) { + setHiddenMotdId(motd.id); + void fetchMotd(); + } + } + + const hidden = useMemo(() => { + return hiddenMotdId === motd?.id; + }, [hiddenMotdId, motd]); + + if (!motd || !motd?.name || hidden) { + return null; + } + + const severity = SEVERITIES[motd?.severity || "Low"]; + + return ( + + +
+ {motd?.name} + + + +
+ {motd?.description} +
+
+ ) + +} \ No newline at end of file -- cgit v1.2.3