-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add announcements system #703
Open
beebls
wants to merge
10
commits into
main
Choose a base branch
from
beebls/motd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+174
−0
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1f93599
feat(motd): add motd component (untested)
beebls 6f8c414
fix(motd): run prettier
beebls 29cfe6c
only set motd if value returned
beebls 3193f71
move motd into div with padding
beebls 985dc66
rename motd to announcements and implement new API
beebls af9c2ec
change to use array of hidden announcements
beebls 5b9613c
change announcements to be stack
beebls 91e4d6c
remove duplicates when adding announcements to array
beebls ab3b69f
move welcome announcement to default
beebls 2384f6c
ensure nulls arent passed to sort
beebls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { DialogButton, Focusable, PanelSection } from '@decky/ui'; | ||
import { useEffect, useMemo, useState } from 'react'; | ||
import { FaTimes } from 'react-icons/fa'; | ||
|
||
import { Announcement, getAnnouncements } from '../store'; | ||
import { useSetting } from '../utils/hooks/useSetting'; | ||
|
||
const SEVERITIES = { | ||
High: { | ||
color: '#bb1414', | ||
text: '#fff', | ||
}, | ||
Medium: { | ||
color: '#bbbb14', | ||
text: '#fff', | ||
}, | ||
Low: { | ||
color: '#1488bb', | ||
text: '#fff', | ||
}, | ||
}; | ||
|
||
const welcomeAnnouncement: Announcement = { | ||
id: 'welcomeAnnouncement', | ||
title: 'Welcome to Decky!', | ||
text: 'We hope you enjoy using Decky! If you have any questions or feedback, please let us know.', | ||
created: Date.now().toString(), | ||
updated: Date.now().toString(), | ||
}; | ||
|
||
export function AnnouncementsDisplay() { | ||
const [announcements, setAnnouncements] = useState<Announcement[]>([welcomeAnnouncement]); | ||
// 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', []); | ||
|
||
function addAnnouncements(newAnnouncements: Announcement[]) { | ||
// Removes any duplicates and sorts by created date | ||
setAnnouncements((oldAnnouncements) => { | ||
const newArr = [...oldAnnouncements, ...newAnnouncements]; | ||
const setOfIds = new Set(newArr.map((a) => a.id)); | ||
return ( | ||
( | ||
Array.from(setOfIds) | ||
.map((id) => newArr.find((a) => a.id === id)) | ||
// Typescript doesn't type filter(Boolean) correctly, so I have to assert this | ||
.filter(Boolean) as Announcement[] | ||
).sort((a, b) => { | ||
return new Date(b.created).getTime() - new Date(a.created).getTime(); | ||
}) | ||
); | ||
}); | ||
} | ||
|
||
async function fetchAnnouncement() { | ||
const announcements = await getAnnouncements(); | ||
announcements && addAnnouncements(announcements); | ||
} | ||
|
||
useEffect(() => { | ||
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(); | ||
} | ||
|
||
if (!currentlyDisplayingAnnouncement) { | ||
return null; | ||
} | ||
|
||
// Severity is not implemented in the API currently | ||
const severity = SEVERITIES['Low']; | ||
|
||
return ( | ||
<PanelSection> | ||
<Focusable | ||
style={{ | ||
// Transparency is 20% of the color | ||
backgroundColor: `${severity.color}33`, | ||
color: severity.text, | ||
borderColor: severity.color, | ||
borderWidth: '2px', | ||
borderStyle: 'solid', | ||
padding: '0.7rem', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
position: 'relative', | ||
}} | ||
> | ||
<div style={{ display: 'flex', justifyContent: 'space-between' }}> | ||
<span style={{ fontWeight: 'bold' }}>{currentlyDisplayingAnnouncement.title}</span> | ||
<DialogButton | ||
style={{ | ||
width: '1rem', | ||
minWidth: '1rem', | ||
height: '1rem', | ||
padding: '0', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
position: 'absolute', | ||
top: '.75rem', | ||
right: '.75rem', | ||
}} | ||
onClick={() => hideAnnouncement(currentlyDisplayingAnnouncement.id)} | ||
> | ||
<FaTimes | ||
style={{ | ||
height: '.75rem', | ||
}} | ||
/> | ||
</DialogButton> | ||
</div> | ||
<span style={{ fontSize: '0.75rem', whiteSpace: 'pre-line' }}>{currentlyDisplayingAnnouncement.text}</span> | ||
</Focusable> | ||
</PanelSection> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where should people direct feedback?
(Also i assume this shows the first time you use decky? Might want to add something like start with looking at the store)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, but there is another blocking issue. The text need to be moved in en-US.json and not hardcoded here.