@@ -2,7 +2,7 @@ import { DialogButton, Focusable, PanelSection } from '@decky/ui';
22import { useEffect , useMemo , useState } from 'react' ;
33import { FaTimes } from 'react-icons/fa' ;
44
5- import { Motd , getMotd } from '../store' ;
5+ import { Announcement , getLatestAnnouncement } from '../store' ;
66import { useSetting } from '../utils/hooks/useSetting' ;
77
88const 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 ) ;
0 commit comments