0

feat(admin): auto-expand news item if there is only one

This commit is contained in:
Gabe Kangas 2023-06-29 19:37:52 -07:00
parent 03c06ba0b8
commit f1bde962cc
No known key found for this signature in database
GPG Key ID: 4345B2060657F330

View File

@ -17,6 +17,7 @@ export type ArticleProps = {
url: string; url: string;
content_html: string; content_html: string;
date_published: string; date_published: string;
defaultOpen?: boolean;
}; };
const ArticleItem: FC<ArticleProps> = ({ const ArticleItem: FC<ArticleProps> = ({
@ -24,12 +25,13 @@ const ArticleItem: FC<ArticleProps> = ({
url, url,
content_html: content, content_html: content,
date_published: date, date_published: date,
defaultOpen = false,
}) => { }) => {
const dateObject = new Date(date); const dateObject = new Date(date);
const dateString = format(dateObject, 'MMM dd, yyyy, HH:mm'); const dateString = format(dateObject, 'MMM dd, yyyy, HH:mm');
return ( return (
<article> <article>
<Collapse> <Collapse defaultActiveKey={defaultOpen ? url : null}>
<Panel header={title} key={url}> <Panel header={title} key={url}>
<p className="timestamp"> <p className="timestamp">
{dateString} ( {dateString} (
@ -74,7 +76,7 @@ export const NewsFeed = () => {
<Title level={2}>News &amp; Updates from Owncast</Title> <Title level={2}>News &amp; Updates from Owncast</Title>
{loadingSpinner} {loadingSpinner}
{feed.map(item => ( {feed.map(item => (
<ArticleItem {...item} key={item.url} /> <ArticleItem {...item} key={item.url} defaultOpen={feed.length === 1} />
))} ))}
{noNews} {noNews}