mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-06-17 08:47:49 +00:00
change announcements to be stack
This commit is contained in:
@@ -2,7 +2,7 @@ import { DialogButton, Focusable, PanelSection } from '@decky/ui';
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { FaTimes } from 'react-icons/fa';
|
import { FaTimes } from 'react-icons/fa';
|
||||||
|
|
||||||
import { Announcement, getLatestAnnouncement } from '../store';
|
import { Announcement, getAnnouncements } from '../store';
|
||||||
import { useSetting } from '../utils/hooks/useSetting';
|
import { useSetting } from '../utils/hooks/useSetting';
|
||||||
|
|
||||||
const SEVERITIES = {
|
const SEVERITIES = {
|
||||||
@@ -29,13 +29,13 @@ const welcomeAnnouncement: Announcement = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function AnnouncementsDisplay() {
|
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
|
// 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', []);
|
const [hiddenAnnouncementIds, setHiddenAnnouncementIds] = useSetting<string[]>('hiddenAnnouncementIds', []);
|
||||||
|
|
||||||
async function fetchAnnouncement() {
|
async function fetchAnnouncement() {
|
||||||
const announcement = await getLatestAnnouncement();
|
const announcements = await getAnnouncements();
|
||||||
announcement && setAnnouncement(announcement);
|
announcements && setAnnouncements((oldAnnouncements) => [...announcements, ...oldAnnouncements]);
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -43,22 +43,20 @@ export function AnnouncementsDisplay() {
|
|||||||
}, []);
|
}, []);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hiddenAnnouncementIds.length > 0) {
|
if (hiddenAnnouncementIds.length > 0) {
|
||||||
setAnnouncement(welcomeAnnouncement);
|
setAnnouncements((oldAnnouncement) => [welcomeAnnouncement, ...oldAnnouncement]);
|
||||||
}
|
}
|
||||||
}, [hiddenAnnouncementIds]);
|
}, [hiddenAnnouncementIds]);
|
||||||
|
|
||||||
function hideAnnouncement() {
|
const currentlyDisplayingAnnouncement: Announcement | null = useMemo(() => {
|
||||||
if (announcement) {
|
return announcements.find((announcement) => !hiddenAnnouncementIds.includes(announcement.id)) || null;
|
||||||
setHiddenAnnouncementIds([...hiddenAnnouncementIds, announcement.id]);
|
}, [announcements, hiddenAnnouncementIds]);
|
||||||
void fetchAnnouncement();
|
|
||||||
}
|
function hideAnnouncement(id: string) {
|
||||||
|
setHiddenAnnouncementIds([...hiddenAnnouncementIds, id]);
|
||||||
|
void fetchAnnouncement();
|
||||||
}
|
}
|
||||||
|
|
||||||
const hidden = useMemo(() => {
|
if (!currentlyDisplayingAnnouncement) {
|
||||||
return !announcement?.id || hiddenAnnouncementIds.includes(announcement.id);
|
|
||||||
}, [hiddenAnnouncementIds, announcement]);
|
|
||||||
|
|
||||||
if (!announcement || !announcement.title || hidden) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +80,7 @@ export function AnnouncementsDisplay() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||||
<span style={{ fontWeight: 'bold' }}>{announcement.title}</span>
|
<span style={{ fontWeight: 'bold' }}>{currentlyDisplayingAnnouncement.title}</span>
|
||||||
<DialogButton
|
<DialogButton
|
||||||
style={{
|
style={{
|
||||||
width: '1rem',
|
width: '1rem',
|
||||||
@@ -96,7 +94,7 @@ export function AnnouncementsDisplay() {
|
|||||||
top: '.75rem',
|
top: '.75rem',
|
||||||
right: '.75rem',
|
right: '.75rem',
|
||||||
}}
|
}}
|
||||||
onClick={hideAnnouncement}
|
onClick={() => hideAnnouncement(currentlyDisplayingAnnouncement.id)}
|
||||||
>
|
>
|
||||||
<FaTimes
|
<FaTimes
|
||||||
style={{
|
style={{
|
||||||
@@ -105,7 +103,7 @@ export function AnnouncementsDisplay() {
|
|||||||
/>
|
/>
|
||||||
</DialogButton>
|
</DialogButton>
|
||||||
</div>
|
</div>
|
||||||
<span style={{ fontSize: '0.75rem', whiteSpace: 'pre-line' }}>{announcement.text}</span>
|
<span style={{ fontSize: '0.75rem', whiteSpace: 'pre-line' }}>{currentlyDisplayingAnnouncement.text}</span>
|
||||||
</Focusable>
|
</Focusable>
|
||||||
</PanelSection>
|
</PanelSection>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export async function getStore(): Promise<Store> {
|
|||||||
return await getSetting<Store>('store', Store.Default);
|
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 version = await window.DeckyPluginLoader.updateVersion();
|
||||||
let store = await getSetting<Store | null>('store', null);
|
let store = await getSetting<Store | null>('store', null);
|
||||||
let customURL = await getSetting<string>(
|
let customURL = await getSetting<string>(
|
||||||
@@ -91,9 +91,9 @@ export async function getLatestAnnouncement(): Promise<Announcement | null> {
|
|||||||
'X-Decky-Version': version.current,
|
'X-Decky-Version': version.current,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (res.status !== 200) return null;
|
if (res.status !== 200) return [];
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
return json?.[0] ?? null;
|
return json ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPluginList(
|
export async function getPluginList(
|
||||||
|
|||||||
Reference in New Issue
Block a user