mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-06-13 12:15:09 +03: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 { 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]);
|
||||
|
||||
function hideAnnouncement(id: string) {
|
||||
setHiddenAnnouncementIds([...hiddenAnnouncementIds, id]);
|
||||
void fetchAnnouncement();
|
||||
}
|
||||
|
||||
const hidden = useMemo(() => {
|
||||
return !announcement?.id || hiddenAnnouncementIds.includes(announcement.id);
|
||||
}, [hiddenAnnouncementIds, announcement]);
|
||||
|
||||
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>
|
||||
);
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user