forked from tanner/qotnews
add svelte app.
This commit is contained in:
60
webapp/src/components/Comment.svelte
Normal file
60
webapp/src/components/Comment.svelte
Normal file
@@ -0,0 +1,60 @@
|
||||
<script>
|
||||
import fromUnixTime from "date-fns/fromUnixTime";
|
||||
import formatDistanceToNow from "date-fns/formatDistanceToNow";
|
||||
export let story;
|
||||
export let comment;
|
||||
export let showComments = true;
|
||||
export let dateString = formatDistanceToNow(fromUnixTime(comment.date), {
|
||||
addSuffix: true,
|
||||
});
|
||||
const author = comment.author.replace(" ", "");
|
||||
export let id = `${author}-${comment.date}`;
|
||||
|
||||
export function toggleComments() {
|
||||
showComments = !showComments;
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.comment-author {
|
||||
}
|
||||
.comment-text {
|
||||
padding: 0 0.5rem;
|
||||
color: #333;
|
||||
}
|
||||
.comment-children {
|
||||
margin-left: 1rem;
|
||||
padding-left: 1rem;
|
||||
border-left: solid 1px #000;
|
||||
}
|
||||
.link-button {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0 0.1rem;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="comment" id="comment-{id}">
|
||||
<div class="comment-author">
|
||||
{comment.author}
|
||||
|
|
||||
<a href="{story.id}#comment-{id}">{dateString}</a>
|
||||
{#if comment.comments.length}
|
||||
<button
|
||||
class="link-button"
|
||||
on:click={toggleComments}>[{showComments ? '-' : '+'}]</button>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="comment-text">
|
||||
{@html comment.text}
|
||||
</div>
|
||||
{#if showComments && comment.comments.length}
|
||||
<div class="comment-children">
|
||||
{#each comment.comments as child}
|
||||
<svelte:self {story} comment={child} />
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
59
webapp/src/components/Nav.svelte
Normal file
59
webapp/src/components/Nav.svelte
Normal file
@@ -0,0 +1,59 @@
|
||||
<script>
|
||||
export let segment;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
nav {
|
||||
border-bottom: 1px solid rgba(255, 62, 0, 0.1);
|
||||
font-weight: 300;
|
||||
padding: 0 1em;
|
||||
}
|
||||
|
||||
ul {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* clearfix */
|
||||
ul::after {
|
||||
content: "";
|
||||
display: block;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
li {
|
||||
display: block;
|
||||
float: left;
|
||||
}
|
||||
|
||||
[aria-current] {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
[aria-current]::after {
|
||||
position: absolute;
|
||||
content: "";
|
||||
width: calc(100% - 1em);
|
||||
height: 2px;
|
||||
background-color: rgb(255, 62, 0);
|
||||
display: block;
|
||||
bottom: -1px;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
padding: 1em 0.5em;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
|
||||
<nav>
|
||||
<ul>
|
||||
<li>
|
||||
<a
|
||||
aria-current={segment === undefined ? 'page' : undefined}
|
||||
href=".">News</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
28
webapp/src/components/StoryInfo.svelte
Normal file
28
webapp/src/components/StoryInfo.svelte
Normal file
@@ -0,0 +1,28 @@
|
||||
<script>
|
||||
import fromUnixTime from "date-fns/fromUnixTime";
|
||||
import formatDistanceToNow from "date-fns/formatDistanceToNow";
|
||||
export let story;
|
||||
|
||||
export let dateString = formatDistanceToNow(fromUnixTime(story.date), {
|
||||
addSuffix: true,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
|
||||
<time
|
||||
datetime={fromUnixTime(story.date).toISOString()}
|
||||
title={fromUnixTime(story.date)}>{dateString}</time>
|
||||
{#if story.author && story.author_link}
|
||||
by
|
||||
<a href={story.author_link}>{story.author}</a>
|
||||
{:else if story.author}by {story.author}{/if}
|
||||
on
|
||||
{story.source}
|
||||
{#if story.score}• {story.score} points{/if}
|
||||
{#if story.num_comments}
|
||||
•
|
||||
<a rel="prefetch" href="/{story.id}#comments">{story.num_comments}
|
||||
comments</a>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user