mirror of
				https://github.com/owncast/owncast.git
				synced 2025-11-01 02:44:31 +08:00 
			
		
		
		
	 be5243f5f8
			
		
	
	be5243f5f8
	
	
	
		
			
			* Bump next from 10.2.3 to 11.0.1 Bumps [next](https://github.com/vercel/next.js) from 10.2.3 to 11.0.1. - [Release notes](https://github.com/vercel/next.js/releases) - [Changelog](https://github.com/vercel/next.js/blob/canary/release.js) - [Commits](https://github.com/vercel/next.js/compare/v10.2.3...v11.0.1) --- updated-dependencies: - dependency-name: next dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * 🚨 apply automatic linting * 🎨 remove unused imports * 🔇 allow console.* to give more debugging options * 🎨 move stuff around to reduce linter messages * 🚨 use destructuring so lint won't complain * 📌 link Chartkick and Chart.js Commit uses the linking code which was previously imported with `import "chartkick/chart.js" [1]. Next did not like the import path, but this does works now. ¯\_(ツ)_/¯ [1]: https://github.com/ankane/chartkick.js/blob/master/chart.js/chart.esm.js Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
		
			
				
	
	
		
			79 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| /* eslint-disable camelcase */
 | |
| /* eslint-disable react/no-danger */
 | |
| import React, { useState, useEffect } 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';
 | |
| 
 | |
| interface Article {
 | |
|   title: string;
 | |
|   url: string;
 | |
|   content_html: string;
 | |
|   date_published: string;
 | |
| }
 | |
| 
 | |
| function ArticleItem({ title, url, content_html: content, date_published: date }: Article) {
 | |
|   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 default function NewsFeed() {
 | |
|   const [feed, setFeed] = useState<Article[]>([]);
 | |
|   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>
 | |
|   );
 | |
| }
 |