get hacker news example working

pull/1890/head
Rich Harris 7 years ago
parent d67accba98
commit c22b663b2a

@ -1,11 +1,10 @@
<script>
import { onMount } from 'svelte';
import List from './List.html';
import Item from './Item.html';
export let item;
export let page;
let item;
let page;
onMount(() => {
hashchange();
@ -29,16 +28,6 @@
}
</script>
<svelte:window on:hashchange={hashchange}/>
<main>
{#if item}
<Item {item}/>
{:elseif page}
<List {page}/>
{/if}
</main>
<style>
main {
position: relative;
@ -57,4 +46,14 @@
main :global(a) {
color: rgb(0,0,150);
}
</style>
</style>
<svelte:window on:hashchange={hashchange}/>
<main>
{#if item}
<Item {item}/>
{:elseif page}
<List {page}/>
{/if}
</main>

@ -1,15 +1,3 @@
<article>
<p class="meta">{comment.user} {comment.time_ago}</p>
{@html comment.content}
<div class="replies">
{#each comment.comments as child}
<svelte:self comment={child}/>
{/each}
</div>
</article>
<style>
article {
border-top: 1px solid #eee;
@ -25,4 +13,16 @@
.replies {
padding: 0 0 0 1em;
}
</style>
</style>
<article>
<p class="meta">{comment.user} {comment.time_ago}</p>
{@html comment.content}
<div class="replies">
{#each comment.comments as child}
<svelte:self comment={child}/>
{/each}
</div>
</article>

@ -9,6 +9,22 @@
}
</script>
<style>
article {
margin: 0 0 1em 0;
}
a {
display: block;
margin: 0 0 1em 0;
}
h1 {
font-size: 1.4em;
margin: 0;
}
</style>
<a href="#/top/1" on:click={back}>&laquo; back</a>
<article>
@ -24,20 +40,4 @@
{#each item.comments as comment}
<Comment {comment}/>
{/each}
</div>
<style>
article {
margin: 0 0 1em 0;
}
a {
display: block;
margin: 0 0 1em 0;
}
h1 {
font-size: 1.4em;
margin: 0;
}
</style>
</div>

@ -21,16 +21,6 @@
});
</script>
{#if items}
{#each items as item, i}
<Summary {item} {i} {offset}/>
{/each}
<a href="#/top/{page + 1}">page {page + 1}</a>
{:else}
<p class="loading">loading...</p>
{/if}
<style>
a {
padding: 2em;
@ -46,4 +36,14 @@
from { opacity: 0; }
to { opacity: 1; }
}
</style>
</style>
{#if items}
{#each items as item, i}
<Summary {item} {i} {offset}/>
{/each}
<a href="#/top/{page + 1}">page {page + 1}</a>
{:else}
<p class="loading">loading...</p>
{/if}

@ -9,12 +9,6 @@
}
</script>
<article>
<span>{i + offset + 1}</span>
<h2><a target="_blank" href={item.url}>{item.title}</a></h2>
<p class="meta"><a href="#/item/{item.id}">{comment_text()}</a> by {item.user} {item.time_ago}</p>
</article>
<style>
article {
position: relative;
@ -35,4 +29,10 @@
a {
color: #333;
}
</style>
</style>
<article>
<span>{i + offset + 1}</span>
<h2><a target="_blank" href={item.url}>{item.title}</a></h2>
<p class="meta"><a href="#/item/{item.id}">{comment_text()}</a> by {item.user} {item.time_ago}</p>
</article>

@ -99,10 +99,10 @@
event.preventDefault();
if (el.href.startsWith(top.location.href)) {
const hash = el.href.replace(top.location.href, '');
if (hash[0] === '#') {
iframe.contentWindow.location.hash = hash;
if (el.href.startsWith(top.location.origin)) {
const url = new URL(el.href);
if (url.hash[0] === '#') {
iframe.contentWindow.location.hash = url.hash;
return;
}
}

Loading…
Cancel
Save