mirror of
https://github.com/owncast/owncast.git
synced 2024-12-23 17:50:38 +03:00
d1f3fffe2f
* refactor: move/rename BanUserButton file * refactor: move/rename Chart file * refactor: update generic component filenames to PascalCase * refactor: update config component filenames to PascalCase * refactor: update AdminLayout component filename to PascalCase * refactor: update/move VideoJS component * chore(eslint): disable bad react/require-default-props rule * refactor: normalize ActionButton component * refactor: normalize ActionButtonRow component * refactor: normalize FollowButton component * refactor: normalize NotifyButton component * refactor: normalize ChatActionMessage component * refactor: normalize ChatContainer component * refactor: normalize ChatJoinMessage component * refactor: normalize ChatModerationActionMenu component * refactor: normalize ChatModerationDetailsModal component * refactor: normalize ChatModeratorNotification component * refactor: normalize ChatSocialMessage component * refactor: normalize ChatSystemMessage component * refactor: normalize ChatTextField component * refactor: normalize ChatUserBadge component * refactor: normalize ChatUserMessage component * refactor: normalize ContentHeader component * refactor: normalize OwncastLogo component * refactor: normalize UserDropdown component * chore(eslint): modify react/function-component-definition rule * refactor: normalize CodecSelector component * refactor: update a bunch of functional components using eslint * refactor: update a bunch of functional components using eslint, pt2 * refactor: update a bunch of functional components using eslint, pt3 * refactor: replace all component->component default imports with named imports * refactor: replace all component-stories->component default imports with named imports * refactor: remove default exports from most components * chore(eslint): add eslint config files for the components and pages dirs * fix: use-before-define error in ChatContainer * Fix ChatContainer import * Only process .tsx files in Next builds Co-authored-by: Gabe Kangas <gabek@real-ity.com>
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
/* eslint-disable camelcase */
|
|
/* eslint-disable react/no-danger */
|
|
import React, { useState, useEffect, FC } from 'react';
|
|
import { Collapse, Typography, Skeleton } from 'antd';
|
|
import format from 'date-fns/format';
|
|
|
|
import { fetchExternalData } from '../utils/apis';
|
|
|
|
const { Panel } = Collapse;
|
|
const { Title, Link } = Typography;
|
|
|
|
const OWNCAST_FEED_URL = 'https://owncast.online/news/index.json';
|
|
const OWNCAST_BASE_URL = 'https://owncast.online';
|
|
|
|
export type ArticleProps = {
|
|
title: string;
|
|
url: string;
|
|
content_html: string;
|
|
date_published: string;
|
|
};
|
|
|
|
const ArticleItem: FC<ArticleProps> = ({
|
|
title,
|
|
url,
|
|
content_html: content,
|
|
date_published: date,
|
|
}) => {
|
|
const dateObject = new Date(date);
|
|
const dateString = format(dateObject, 'MMM dd, yyyy, HH:mm');
|
|
return (
|
|
<article>
|
|
<Collapse>
|
|
<Panel header={title} key={url}>
|
|
<p className="timestamp">
|
|
{dateString} (
|
|
<Link href={`${OWNCAST_BASE_URL}${url}`} target="_blank" rel="noopener noreferrer">
|
|
Link
|
|
</Link>
|
|
)
|
|
</p>
|
|
<div dangerouslySetInnerHTML={{ __html: content }} />
|
|
</Panel>
|
|
</Collapse>
|
|
</article>
|
|
);
|
|
};
|
|
|
|
export const NewsFeed = () => {
|
|
const [feed, setFeed] = useState<ArticleProps[]>([]);
|
|
const [loading, setLoading] = useState<Boolean>(true);
|
|
|
|
const getFeed = async () => {
|
|
setLoading(false);
|
|
|
|
try {
|
|
const result = await fetchExternalData(OWNCAST_FEED_URL);
|
|
if (result?.items.length > 0) {
|
|
setFeed(result.items);
|
|
}
|
|
} catch (error) {
|
|
console.log('==== error', error);
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
getFeed();
|
|
}, []);
|
|
|
|
const loadingSpinner = loading ? <Skeleton loading active /> : null;
|
|
const noNews = !loading && feed.length === 0 ? <div>No news.</div> : null;
|
|
|
|
return (
|
|
<section className="news-feed form-module">
|
|
<Title level={2}>News & Updates from Owncast</Title>
|
|
{loadingSpinner}
|
|
{feed.map(item => (
|
|
<ArticleItem {...item} key={item.url} />
|
|
))}
|
|
|
|
{noNews}
|
|
</section>
|
|
);
|
|
};
|