get hacker news example working

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

@ -1,11 +1,10 @@
<script> <script>
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import List from './List.html'; import List from './List.html';
import Item from './Item.html'; import Item from './Item.html';
export let item; let item;
export let page; let page;
onMount(() => { onMount(() => {
hashchange(); hashchange();
@ -29,16 +28,6 @@
} }
</script> </script>
<svelte:window on:hashchange={hashchange}/>
<main>
{#if item}
<Item {item}/>
{:elseif page}
<List {page}/>
{/if}
</main>
<style> <style>
main { main {
position: relative; position: relative;
@ -58,3 +47,13 @@
color: rgb(0,0,150); 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> <style>
article { article {
border-top: 1px solid #eee; border-top: 1px solid #eee;
@ -26,3 +14,15 @@
padding: 0 0 0 1em; 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> </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> <a href="#/top/1" on:click={back}>&laquo; back</a>
<article> <article>
@ -25,19 +41,3 @@
<Comment {comment}/> <Comment {comment}/>
{/each} {/each}
</div> </div>
<style>
article {
margin: 0 0 1em 0;
}
a {
display: block;
margin: 0 0 1em 0;
}
h1 {
font-size: 1.4em;
margin: 0;
}
</style>

@ -21,16 +21,6 @@
}); });
</script> </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> <style>
a { a {
padding: 2em; padding: 2em;
@ -47,3 +37,13 @@
to { opacity: 1; } 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> </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> <style>
article { article {
position: relative; position: relative;
@ -36,3 +30,9 @@
color: #333; 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(); event.preventDefault();
if (el.href.startsWith(top.location.href)) { if (el.href.startsWith(top.location.origin)) {
const hash = el.href.replace(top.location.href, ''); const url = new URL(el.href);
if (hash[0] === '#') { if (url.hash[0] === '#') {
iframe.contentWindow.location.hash = hash; iframe.contentWindow.location.hash = url.hash;
return; return;
} }
} }

Loading…
Cancel
Save