forked from tanner/qotnews
Add site logos, keep displaying news on error
This commit is contained in:
parent
0053147226
commit
c7734eb2bc
BIN
webclient/public/logos/hackernews.png
Normal file
BIN
webclient/public/logos/hackernews.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 538 B |
BIN
webclient/public/logos/reddit.png
Normal file
BIN
webclient/public/logos/reddit.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
BIN
webclient/public/logos/tildes.png
Normal file
BIN
webclient/public/logos/tildes.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 500 B |
|
@ -2,7 +2,7 @@ import React from 'react';
|
|||
import { Link } from 'react-router-dom';
|
||||
import { sourceLink, infoLine, ToggleDot } from './utils.js';
|
||||
|
||||
const apiUrl = 'http://news-api.dns.t0.vc/';
|
||||
const apiUrl = 'https://news-api.t0.vc/';
|
||||
|
||||
class Article extends React.Component {
|
||||
constructor(props) {
|
||||
|
@ -39,32 +39,27 @@ class Article extends React.Component {
|
|||
|
||||
return (
|
||||
<div className='article-container'>
|
||||
{error ?
|
||||
<p>Something went wrong.</p>
|
||||
:
|
||||
<div>
|
||||
{story ?
|
||||
<div className='article'>
|
||||
<h1>{story.title}</h1>
|
||||
{error && <p>Connection error?</p>}
|
||||
{story ?
|
||||
<div className='article'>
|
||||
<h1>{story.title}</h1>
|
||||
|
||||
<div className='info'>
|
||||
Source: {sourceLink(story)}
|
||||
</div>
|
||||
<div className='info'>
|
||||
Source: {sourceLink(story)}
|
||||
</div>
|
||||
|
||||
{infoLine(story)}
|
||||
{infoLine(story)}
|
||||
|
||||
{story.text ?
|
||||
<div className='story-text' dangerouslySetInnerHTML={{ __html: story.text }} />
|
||||
:
|
||||
<p>Problem getting article :(</p>
|
||||
}
|
||||
</div>
|
||||
{story.text ?
|
||||
<div className='story-text' dangerouslySetInnerHTML={{ __html: story.text }} />
|
||||
:
|
||||
<p>loading...</p>
|
||||
<p>Problem getting article :(</p>
|
||||
}
|
||||
<ToggleDot id={id} article={false} />
|
||||
</div>
|
||||
:
|
||||
<p>loading...</p>
|
||||
}
|
||||
<ToggleDot id={id} article={false} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Link } from 'react-router-dom';
|
|||
import moment from 'moment';
|
||||
import { sourceLink, infoLine, ToggleDot } from './utils.js';
|
||||
|
||||
const apiUrl = 'http://news-api.dns.t0.vc/';
|
||||
const apiUrl = 'https://news-api.t0.vc/';
|
||||
|
||||
class Article extends React.Component {
|
||||
constructor(props) {
|
||||
|
@ -58,30 +58,25 @@ class Article extends React.Component {
|
|||
|
||||
return (
|
||||
<div className='container'>
|
||||
{error ?
|
||||
<p>Something went wrong.</p>
|
||||
:
|
||||
<div>
|
||||
{story ?
|
||||
<div className='article'>
|
||||
<h1>{story.title}</h1>
|
||||
{error && <p>Connection error?</p>}
|
||||
{story ?
|
||||
<div className='article'>
|
||||
<h1>{story.title}</h1>
|
||||
|
||||
<div className='info'>
|
||||
<Link to={'/' + story.id + '/a'}>View article</Link>
|
||||
</div>
|
||||
<div className='info'>
|
||||
<Link to={'/' + story.id + '/a'}>View article</Link>
|
||||
</div>
|
||||
|
||||
{infoLine(story)}
|
||||
{infoLine(story)}
|
||||
|
||||
<div className='comments'>
|
||||
{story.comments.map(c => this.displayComment(story, c, 0))}
|
||||
</div>
|
||||
</div>
|
||||
:
|
||||
<p>loading...</p>
|
||||
}
|
||||
<ToggleDot id={id} article={true} />
|
||||
<div className='comments'>
|
||||
{story.comments.map(c => this.displayComment(story, c, 0))}
|
||||
</div>
|
||||
</div>
|
||||
:
|
||||
<p>loading...</p>
|
||||
}
|
||||
<ToggleDot id={id} article={true} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { sourceLink, infoLine } from './utils.js';
|
||||
import { siteLogo, sourceLink, infoLine } from './utils.js';
|
||||
import { clearStorage } from './utils.js';
|
||||
|
||||
const apiUrl = 'http://news-api.dns.t0.vc/';
|
||||
const apiUrl = 'https://news-api.t0.vc/';
|
||||
|
||||
class Feed extends React.Component {
|
||||
constructor(props) {
|
||||
|
@ -14,7 +14,7 @@ class Feed extends React.Component {
|
|||
error: false,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
componentDidMount() {
|
||||
fetch(apiUrl)
|
||||
.then(res => res.json())
|
||||
|
@ -23,7 +23,7 @@ class Feed extends React.Component {
|
|||
this.setState({ stories: result.stories });
|
||||
clearStorage();
|
||||
localStorage.setItem('stories', JSON.stringify(result.stories));
|
||||
result.stories.slice(0, 25).forEach(x => {
|
||||
result.stories.filter(x => x.score >= 20).slice(0, 25).forEach(x => {
|
||||
fetch(apiUrl + x.id)
|
||||
.then(res => res.json())
|
||||
.then(result => {
|
||||
|
@ -45,34 +45,29 @@ class Feed extends React.Component {
|
|||
|
||||
return (
|
||||
<div className='container'>
|
||||
{error ?
|
||||
<p>Something went wrong.</p>
|
||||
:
|
||||
{error && <p>Connection error?</p>}
|
||||
{stories ?
|
||||
<div>
|
||||
{stories ?
|
||||
<div>
|
||||
{stories.map((x, i) =>
|
||||
<div className='item'>
|
||||
<div className='num'>
|
||||
{i+1}.
|
||||
</div>
|
||||
{stories.map((x, i) =>
|
||||
<div className='item'>
|
||||
<div className='num'>
|
||||
{i+1}.
|
||||
</div>
|
||||
|
||||
<div className='title'>
|
||||
<Link className='link' to={'/' + x.id + '/a'}>{x.title}</Link>
|
||||
<div className='title'>
|
||||
<Link className='link' to={'/' + x.id + '/a'}>{siteLogo[x.source]} {x.title}</Link>
|
||||
|
||||
<span className='source'>
|
||||
​({sourceLink(x)})
|
||||
</span>
|
||||
</div>
|
||||
<span className='source'>
|
||||
​({sourceLink(x)})
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{infoLine(x)}
|
||||
</div>
|
||||
)}
|
||||
{infoLine(x)}
|
||||
</div>
|
||||
:
|
||||
<p>loading...</p>
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
:
|
||||
<p>loading...</p>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
color: #828282;
|
||||
}
|
||||
|
||||
.dark .item .source-logo {
|
||||
filter: grayscale(1);
|
||||
}
|
||||
|
||||
.dark .item a {
|
||||
color: #828282;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,11 @@ a {
|
|||
margin-bottom: 0.6rem;
|
||||
}
|
||||
|
||||
.item .source-logo {
|
||||
width: 0.9rem;
|
||||
height: 0.9rem;
|
||||
}
|
||||
|
||||
.item a {
|
||||
color: #828282;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,12 @@ export const sourceLink = (story) => {
|
|||
return (<a className='source' href={url}>{host}</a>);
|
||||
};
|
||||
|
||||
export const siteLogo = {
|
||||
hackernews: <img className='source-logo' src='logos/hackernews.png' />,
|
||||
tildes: <img className='source-logo' src='logos/tildes.png' />,
|
||||
reddit: <img className='source-logo' src='logos/reddit.png' />,
|
||||
};
|
||||
|
||||
export const infoLine = (story) =>
|
||||
<div className='info'>
|
||||
{story.score} points
|
||||
|
|
Loading…
Reference in New Issue
Block a user