diff options
| author | Beebles <102569435+beebls@users.noreply.github.com> | 2024-09-13 18:12:56 -0600 |
|---|---|---|
| committer | Beebles <102569435+beebls@users.noreply.github.com> | 2025-08-01 06:54:40 -0600 |
| commit | 5a02f5fbe7aa4fed255c971663345bd37a5eb148 (patch) | |
| tree | 7b088d4cf87914405f6df22289b4210047da8e0c | |
| parent | 83ae98a7091669e80a178d39cfebba1258e57782 (diff) | |
| download | decky-loader-5a02f5fbe7aa4fed255c971663345bd37a5eb148.tar.gz decky-loader-5a02f5fbe7aa4fed255c971663345bd37a5eb148.zip | |
change announcements to be stack
| -rw-r--r-- | frontend/src/components/AnnouncementsDisplay.tsx | 34 | ||||
| -rw-r--r-- | frontend/src/store.ts | 6 |
2 files changed, 19 insertions, 21 deletions
diff --git a/frontend/src/components/AnnouncementsDisplay.tsx b/frontend/src/components/AnnouncementsDisplay.tsx index 8ce5bc4e..66154192 100644 --- a/frontend/src/components/AnnouncementsDisplay.tsx +++ b/frontend/src/components/AnnouncementsDisplay.tsx @@ -2,7 +2,7 @@ import { DialogButton, Focusable, PanelSection } from '@decky/ui'; import { useEffect, useMemo, useState } from 'react'; import { FaTimes } from 'react-icons/fa'; -import { Announcement, getLatestAnnouncement } from '../store'; +import { Announcement, getAnnouncements } from '../store'; import { useSetting } from '../utils/hooks/useSetting'; const SEVERITIES = { @@ -29,13 +29,13 @@ const welcomeAnnouncement: Announcement = { }; export function AnnouncementsDisplay() { - const [announcement, setAnnouncement] = useState<Announcement | null>(null); + const [announcements, setAnnouncements] = useState<Announcement[]>([]); // 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 [hiddenAnnouncementIds, setHiddenAnnouncementIds] = useSetting<string[]>('hiddenAnnouncementIds', []); async function fetchAnnouncement() { - const announcement = await getLatestAnnouncement(); - announcement && setAnnouncement(announcement); + const announcements = await getAnnouncements(); + announcements && setAnnouncements((oldAnnouncements) => [...announcements, ...oldAnnouncements]); } useEffect(() => { @@ -43,22 +43,20 @@ export function AnnouncementsDisplay() { }, []); useEffect(() => { if (hiddenAnnouncementIds.length > 0) { - setAnnouncement(welcomeAnnouncement); + setAnnouncements((oldAnnouncement) => [welcomeAnnouncement, ...oldAnnouncement]); } }, [hiddenAnnouncementIds]); - function hideAnnouncement() { - if (announcement) { - setHiddenAnnouncementIds([...hiddenAnnouncementIds, announcement.id]); - void fetchAnnouncement(); - } - } + const currentlyDisplayingAnnouncement: Announcement | null = useMemo(() => { + return announcements.find((announcement) => !hiddenAnnouncementIds.includes(announcement.id)) || null; + }, [announcements, hiddenAnnouncementIds]); - const hidden = useMemo(() => { - return !announcement?.id || hiddenAnnouncementIds.includes(announcement.id); - }, [hiddenAnnouncementIds, announcement]); + function hideAnnouncement(id: string) { + setHiddenAnnouncementIds([...hiddenAnnouncementIds, id]); + void fetchAnnouncement(); + } - if (!announcement || !announcement.title || hidden) { + if (!currentlyDisplayingAnnouncement) { return null; } @@ -82,7 +80,7 @@ export function AnnouncementsDisplay() { }} > <div style={{ display: 'flex', justifyContent: 'space-between' }}> - <span style={{ fontWeight: 'bold' }}>{announcement.title}</span> + <span style={{ fontWeight: 'bold' }}>{currentlyDisplayingAnnouncement.title}</span> <DialogButton style={{ width: '1rem', @@ -96,7 +94,7 @@ export function AnnouncementsDisplay() { top: '.75rem', right: '.75rem', }} - onClick={hideAnnouncement} + onClick={() => hideAnnouncement(currentlyDisplayingAnnouncement.id)} > <FaTimes style={{ @@ -105,7 +103,7 @@ export function AnnouncementsDisplay() { /> </DialogButton> </div> - <span style={{ fontSize: '0.75rem', whiteSpace: 'pre-line' }}>{announcement.text}</span> + <span style={{ fontSize: '0.75rem', whiteSpace: 'pre-line' }}>{currentlyDisplayingAnnouncement.text}</span> </Focusable> </PanelSection> ); diff --git a/frontend/src/store.ts b/frontend/src/store.ts index 1cfe36cd..cb2a58bd 100644 --- a/frontend/src/store.ts +++ b/frontend/src/store.ts @@ -57,7 +57,7 @@ export async function getStore(): Promise<Store> { return await getSetting<Store>('store', Store.Default); } -export async function getLatestAnnouncement(): Promise<Announcement | null> { +export async function getAnnouncements(): Promise<Announcement[]> { let version = await window.DeckyPluginLoader.updateVersion(); let store = await getSetting<Store | null>('store', null); let customURL = await getSetting<string>( @@ -93,9 +93,9 @@ export async function getLatestAnnouncement(): Promise<Announcement | null> { 'X-Decky-Version': version.current, }, }); - if (res.status !== 200) return null; + if (res.status !== 200) return []; const json = await res.json(); - return json?.[0] ?? null; + return json ?? []; } export async function getPluginList( |
