Skip to content

Commit 985dc66

Browse files
committed
rename motd to announcements and implement new API
1 parent 3193f71 commit 985dc66

File tree

3 files changed

+48
-46
lines changed

3 files changed

+48
-46
lines changed

frontend/src/components/MotdDisplay.tsx renamed to frontend/src/components/AnnouncementsDisplay.tsx

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DialogButton, Focusable, PanelSection } from '@decky/ui';
22
import { useEffect, useMemo, useState } from 'react';
33
import { FaTimes } from 'react-icons/fa';
44

5-
import { Motd, getMotd } from '../store';
5+
import { Announcement, getLatestAnnouncement } from '../store';
66
import { useSetting } from '../utils/hooks/useSetting';
77

88
const SEVERITIES = {
@@ -20,50 +20,51 @@ const SEVERITIES = {
2020
},
2121
};
2222

23-
const welcomeMotd: Motd = {
24-
id: 'welcomeMotd',
25-
name: 'Welcome to Decky!',
26-
date: Date.now().toString(),
27-
description: 'We hope you enjoy using Decky! If you have any questions or feedback, please let us know.',
28-
severity: 'Low',
23+
const welcomeAnnouncement: Announcement = {
24+
id: 'welcomeAnnouncement',
25+
title: 'Welcome to Decky!',
26+
text: 'We hope you enjoy using Decky! If you have any questions or feedback, please let us know.',
27+
created: Date.now().toString(),
28+
updated: Date.now().toString(),
2929
};
3030

31-
export function MotdDisplay() {
32-
const [motd, setMotd] = useState<Motd | null>(null);
31+
export function AnnouncementsDisplay() {
32+
const [announcement, setAnnouncement] = useState<Announcement | null>(null);
3333
// 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
34-
const [hiddenMotdId, setHiddenMotdId] = useSetting('hiddenMotdId', 'showWelcome');
34+
const [hiddenAnnouncementId, setHiddenAnnouncementId] = useSetting('hiddenAnnouncementId', 'showWelcome');
3535

36-
async function fetchMotd() {
37-
const motd = await getMotd();
38-
motd && setMotd(motd);
36+
async function fetchAnnouncement() {
37+
const announcement = await getLatestAnnouncement();
38+
announcement && setAnnouncement(announcement);
3939
}
4040

4141
useEffect(() => {
42-
void fetchMotd();
42+
void fetchAnnouncement();
4343
}, []);
4444

4545
useEffect(() => {
46-
if (hiddenMotdId === 'showWelcome') {
47-
setMotd(welcomeMotd);
46+
if (hiddenAnnouncementId === 'showWelcome') {
47+
setAnnouncement(welcomeAnnouncement);
4848
}
49-
}, [hiddenMotdId]);
49+
}, [hiddenAnnouncementId]);
5050

51-
function hideMotd() {
52-
if (motd) {
53-
setHiddenMotdId(motd.id);
54-
void fetchMotd();
51+
function hideAnnouncement() {
52+
if (announcement) {
53+
setHiddenAnnouncementId(announcement.id);
54+
void fetchAnnouncement();
5555
}
5656
}
5757

5858
const hidden = useMemo(() => {
59-
return hiddenMotdId === motd?.id;
60-
}, [hiddenMotdId, motd]);
59+
return hiddenAnnouncementId === announcement?.id;
60+
}, [hiddenAnnouncementId, announcement]);
6161

62-
if (!motd || !motd?.name || hidden) {
62+
if (!announcement || !announcement.title || hidden) {
6363
return null;
6464
}
6565

66-
const severity = SEVERITIES[motd?.severity || 'Low'];
66+
// Severity is not implemented in the API currently
67+
const severity = SEVERITIES['Low'];
6768

6869
return (
6970
<PanelSection>
@@ -82,7 +83,7 @@ export function MotdDisplay() {
8283
}}
8384
>
8485
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
85-
<span style={{ fontWeight: 'bold' }}>{motd?.name}</span>
86+
<span style={{ fontWeight: 'bold' }}>{announcement.title}</span>
8687
<DialogButton
8788
style={{
8889
width: '1rem',
@@ -96,7 +97,7 @@ export function MotdDisplay() {
9697
top: '.75rem',
9798
right: '.75rem',
9899
}}
99-
onClick={hideMotd}
100+
onClick={hideAnnouncement}
100101
>
101102
<FaTimes
102103
style={{
@@ -105,7 +106,7 @@ export function MotdDisplay() {
105106
/>
106107
</DialogButton>
107108
</div>
108-
<span style={{ fontSize: '0.75rem', whiteSpace: 'pre-line' }}>{motd?.description}</span>
109+
<span style={{ fontSize: '0.75rem', whiteSpace: 'pre-line' }}>{announcement.text}</span>
109110
</Focusable>
110111
</PanelSection>
111112
);

frontend/src/components/PluginView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { useTranslation } from 'react-i18next';
44
import { FaEyeSlash } from 'react-icons/fa';
55

66
import { Plugin } from '../plugin';
7+
import { AnnouncementsDisplay } from './AnnouncementsDisplay';
78
import { useDeckyState } from './DeckyState';
8-
import { MotdDisplay } from './MotdDisplay';
99
import NotificationBadge from './NotificationBadge';
1010
import { useQuickAccessVisible } from './QuickAccessVisibleState';
1111
import TitleView from './TitleView';
@@ -43,7 +43,7 @@ const PluginView: FC = () => {
4343
paddingTop: '16px',
4444
}}
4545
>
46-
<MotdDisplay />
46+
<AnnouncementsDisplay />
4747
<PanelSection>
4848
{pluginList
4949
.filter((p) => p.content)

frontend/src/store.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ export interface PluginInstallRequest {
4040
installType: InstallType;
4141
}
4242

43-
export interface Motd {
43+
export interface Announcement {
4444
id: string;
45-
name: string;
46-
description: string;
47-
date: string;
48-
severity: 'High' | 'Medium' | 'Low';
45+
title: string;
46+
text: string;
47+
created: string;
48+
updated: string;
4949
}
5050

5151
// name: version
@@ -55,10 +55,13 @@ export async function getStore(): Promise<Store> {
5555
return await getSetting<Store>('store', Store.Default);
5656
}
5757

58-
export async function getMotd(): Promise<Motd> {
58+
export async function getLatestAnnouncement(): Promise<Announcement | null> {
5959
let version = await window.DeckyPluginLoader.updateVersion();
6060
let store = await getSetting<Store | null>('store', null);
61-
let customURL = await getSetting<string>('motd-url', 'https://plugins.deckbrew.xyz/v1/motd');
61+
let customURL = await getSetting<string>(
62+
'announcements-url',
63+
'https://plugins.deckbrew.xyz/v1/announcements/-/current',
64+
);
6265

6366
if (store === null) {
6467
console.log('Could not get store, using Default.');
@@ -69,30 +72,28 @@ export async function getMotd(): Promise<Motd> {
6972
let resolvedURL;
7073
switch (store) {
7174
case Store.Default:
72-
resolvedURL = 'https://plugins.deckbrew.xyz/v1/motd';
75+
resolvedURL = 'https://plugins.deckbrew.xyz/v1/announcements/-/current';
7376
break;
7477
case Store.Testing:
75-
resolvedURL = 'https://testing.deckbrew.xyz/v1/motd';
78+
resolvedURL = 'https://testing.deckbrew.xyz/v1/announcements/-/current';
7679
break;
7780
case Store.Custom:
7881
resolvedURL = customURL;
7982
break;
8083
default:
8184
console.error('Somehow you ended up without a standard URL, using the default URL.');
82-
resolvedURL = 'https://plugins.deckbrew.xyz/v1/motd';
85+
resolvedURL = 'https://plugins.deckbrew.xyz/v1/announcements/-/current';
8386
break;
8487
}
85-
return fetch(resolvedURL, {
88+
const res = await fetch(resolvedURL, {
8689
method: 'GET',
8790
headers: {
8891
'X-Decky-Version': version.current,
8992
},
90-
}).then((r) => {
91-
if (r.status === 200) {
92-
return r.json();
93-
}
94-
return null;
9593
});
94+
if (res.status !== 200) return null;
95+
const json = await res.json();
96+
return json?.[0] ?? null;
9697
}
9798

9899
export async function getPluginList(

0 commit comments

Comments
 (0)