add news feed (#99)
* add news feed * Prettified Code! Co-authored-by: gingervitis <gingervitis@users.noreply.github.com>
This commit is contained in:
64
web/components/news-feed.tsx
Normal file
64
web/components/news-feed.tsx
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/* eslint-disable camelcase */
|
||||||
|
/* eslint-disable react/no-danger */
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { Typography } from 'antd';
|
||||||
|
import format from 'date-fns/format';
|
||||||
|
|
||||||
|
import { fetchExternalData } from '../utils/apis';
|
||||||
|
|
||||||
|
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>
|
||||||
|
<p className="timestamp">{dateString}</p>
|
||||||
|
<Title level={3}>
|
||||||
|
<Link href={`${OWNCAST_BASE_URL}${url}`} target="_blank" rel="noopener noreferrer">
|
||||||
|
{title}
|
||||||
|
</Link>
|
||||||
|
</Title>
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: content }} />
|
||||||
|
</article>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function NewsFeed() {
|
||||||
|
const [feed, setFeed] = useState<Article[]>([]);
|
||||||
|
const getFeed = async () => {
|
||||||
|
try {
|
||||||
|
const result = await fetchExternalData(OWNCAST_FEED_URL);
|
||||||
|
setFeed(result.items);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('==== error', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getFeed();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!feed.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="news-feed form-module">
|
||||||
|
<Title level={2}>News & Updates from Owncast</Title>
|
||||||
|
{feed.map(item => (
|
||||||
|
<ArticleItem {...item} />
|
||||||
|
))}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import Offline from './offline-notice';
|
|||||||
|
|
||||||
import { LOGS_WARN, fetchData, FETCH_INTERVAL } from '../utils/apis';
|
import { LOGS_WARN, fetchData, FETCH_INTERVAL } from '../utils/apis';
|
||||||
import { formatIPAddress, isEmptyObject } from '../utils/format';
|
import { formatIPAddress, isEmptyObject } from '../utils/format';
|
||||||
|
import NewsFeed from '../components/news-feed';
|
||||||
|
|
||||||
function streamDetailsFormatter(streamDetails) {
|
function streamDetailsFormatter(streamDetails) {
|
||||||
return (
|
return (
|
||||||
@@ -135,13 +136,16 @@ export default function Home() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Row gutter={[16, 16]} className="section stream-details-section">
|
<Row gutter={[16, 16]} className="section stream-details-section">
|
||||||
<Col className="outbound-details" span={12} sm={24} md={24} lg={12}>
|
<Col className="stream-details" span={12} sm={24} md={24} lg={12}>
|
||||||
<Card size="small" title="Outbound Stream Details" type="inner">
|
<Card
|
||||||
|
size="small"
|
||||||
|
title="Outbound Stream Details"
|
||||||
|
type="inner"
|
||||||
|
className="outbound-details"
|
||||||
|
>
|
||||||
{videoQualitySettings}
|
{videoQualitySettings}
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
|
||||||
|
|
||||||
<Col className="inbound-details" span={12} sm={24} md={24} lg={12}>
|
|
||||||
<Card size="small" title="Inbound Stream Details" type="inner">
|
<Card size="small" title="Inbound Stream Details" type="inner">
|
||||||
<Statistic
|
<Statistic
|
||||||
className="stream-details-item"
|
className="stream-details-item"
|
||||||
@@ -161,6 +165,9 @@ export default function Home() {
|
|||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
<Col span={12} xs={24} sm={24} md={24} lg={12}>
|
||||||
|
<NewsFeed />
|
||||||
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { Result, Card, Row, Col } from 'antd';
|
import { Typography, Card, Row, Col } from 'antd';
|
||||||
import {
|
import {
|
||||||
MessageTwoTone,
|
MessageTwoTone,
|
||||||
QuestionCircleTwoTone,
|
QuestionCircleTwoTone,
|
||||||
@@ -9,7 +9,9 @@ import {
|
|||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import OwncastLogo from '../components/logo';
|
import OwncastLogo from '../components/logo';
|
||||||
import LogTable from '../components/log-table';
|
import LogTable from '../components/log-table';
|
||||||
|
import NewsFeed from '../components/news-feed';
|
||||||
|
|
||||||
|
const { Title } = Typography;
|
||||||
const { Meta } = Card;
|
const { Meta } = Card;
|
||||||
|
|
||||||
export default function Offline({ logs = [], config }) {
|
export default function Offline({ logs = [], config }) {
|
||||||
@@ -77,15 +79,20 @@ export default function Offline({ logs = [], config }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Row gutter={[16, 16]} className="offline-content">
|
<Row>
|
||||||
<Col span={12} xs={24} sm={24} md={24} lg={12} className="logo-section">
|
<Col span={12} offset={6}>
|
||||||
<Result
|
<div className="offline-intro">
|
||||||
icon={<OwncastLogo />}
|
<span className="logo">
|
||||||
title="No stream is active."
|
<OwncastLogo />
|
||||||
subTitle="You should start one."
|
</span>
|
||||||
/>
|
<div>
|
||||||
|
<Title level={2}>No stream is active</Title>
|
||||||
|
<p>You should start one.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<Row gutter={[16, 16]} className="offline-content">
|
||||||
<Col span={12} xs={24} sm={24} md={24} lg={12} className="list-section">
|
<Col span={12} xs={24} sm={24} md={24} lg={12} className="list-section">
|
||||||
{data.map(item => (
|
{data.map(item => (
|
||||||
<Card key={item.title} size="small" bordered={false}>
|
<Card key={item.title} size="small" bordered={false}>
|
||||||
@@ -93,6 +100,9 @@ export default function Offline({ logs = [], config }) {
|
|||||||
</Card>
|
</Card>
|
||||||
))}
|
))}
|
||||||
</Col>
|
</Col>
|
||||||
|
<Col span={12} xs={24} sm={24} md={24} lg={12}>
|
||||||
|
<NewsFeed />
|
||||||
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<LogTable logs={logs} pageSize={5} />
|
<LogTable logs={logs} pageSize={5} />
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -34,12 +34,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.outbound-details,
|
.stream-details {
|
||||||
.inbound-details {
|
|
||||||
> .ant-card-bordered {
|
> .ant-card-bordered {
|
||||||
border-color: rgba(255, 255, 255, 0.1);
|
border-color: rgba(255, 255, 255, 0.1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.outbound-details {
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.offline-content {
|
.offline-content {
|
||||||
@@ -75,3 +77,45 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.offline-intro {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 2em;
|
||||||
|
.logo-svg {
|
||||||
|
height: 6em;
|
||||||
|
width: 6em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.news-feed {
|
||||||
|
margin-top: 0;
|
||||||
|
padding: 1.5em;
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.2em;
|
||||||
|
margin-top: 0;
|
||||||
|
color: var(--pink);
|
||||||
|
}
|
||||||
|
article {
|
||||||
|
padding: 1em 0.25em;
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--white-75);
|
||||||
|
border-bottom: 1px solid var(--gray);
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: 1.2em;
|
||||||
|
a {
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.timestamp {
|
||||||
|
margin-top: 0;
|
||||||
|
font-size: 0.75em;
|
||||||
|
color: var(--white-50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -116,9 +116,9 @@ export async function fetchData(url: string, options?: FetchOptions) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGithubRelease() {
|
export async function fetchExternalData(url: string) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(GITHUB_RELEASE_URL);
|
const response = await fetch(url);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const message = `An error has occured: ${response.status}`;
|
const message = `An error has occured: ${response.status}`;
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
@@ -131,6 +131,10 @@ export async function getGithubRelease() {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getGithubRelease() {
|
||||||
|
return fetchExternalData(GITHUB_RELEASE_URL);
|
||||||
|
}
|
||||||
|
|
||||||
// Stolen from https://gist.github.com/prenagha/98bbb03e27163bc2f5e4
|
// Stolen from https://gist.github.com/prenagha/98bbb03e27163bc2f5e4
|
||||||
const VPAT = /^\d+(\.\d+){0,2}$/;
|
const VPAT = /^\d+(\.\d+){0,2}$/;
|
||||||
function upToDate(local, remote) {
|
function upToDate(local, remote) {
|
||||||
|
|||||||
Reference in New Issue
Block a user