2019-08-24 05:04:51 +00:00
|
|
|
import React from 'react';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
|
|
|
export const sourceLink = (story) => {
|
|
|
|
const url = story.url || story.link;
|
|
|
|
const urlObj = new URL(url);
|
|
|
|
const host = urlObj.hostname.replace(/^www\./, '');
|
|
|
|
return (<a className='source' href={url}>{host}</a>);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const infoLine = (story) =>
|
|
|
|
<div className='info'>
|
|
|
|
{story.score} points
|
|
|
|
by <a href={story.author_link}>{story.author}</a>
|
|
|
|
​ {moment.unix(story.date).fromNow()}
|
|
|
|
​ on <a href={story.link}>{story.source}</a> | ​
|
|
|
|
<Link className={story.num_comments > 99 ? 'hot' : ''} to={'/' + story.id}>
|
|
|
|
{story.num_comments} comment{story.num_comments !== 1 && 's'}
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
;
|
2019-08-25 01:25:28 +00:00
|
|
|
|
|
|
|
export const clearStorage = () => {
|
|
|
|
const themeSetting = localStorage.getItem('theme');
|
|
|
|
localStorage.clear();
|
|
|
|
localStorage.setItem('theme', themeSetting);
|
|
|
|
};
|