fix hacker news example

pull/2421/head
Richard Harris 7 years ago
parent df75e0c6d9
commit efa4ff1a44

@ -6,10 +6,6 @@
let item;
let page;
onMount(() => {
hashchange();
});
async function hashchange() {
// the poor man's router!
const path = window.location.hash.slice(1);
@ -26,6 +22,8 @@
window.location.hash = '/top/1';
}
}
onMount(hashchange);
</script>
<style>
@ -52,7 +50,7 @@
<main>
{#if item}
<Item {item}/>
<Item {item} returnTo="#/top/{page}"/>
{:else if page}
<List {page}/>
{/if}

@ -1,3 +1,7 @@
<script>
export let comment;
</script>
<style>
article {
border-top: 1px solid #eee;

@ -1,12 +1,8 @@
<script>
import Comment from "./Comment.html";
import Comment from "./Comment.svelte";
export let item;
function back(event) {
event.preventDefault();
window.history.back();
}
export let returnTo;
</script>
<style>
@ -25,7 +21,7 @@
}
</style>
<a href="#/top/1" on:click={back}>&laquo; back</a>
<a href={returnTo}>&laquo; back</a>
<article>
<a href="{item.url}">

@ -1,24 +1,21 @@
<script>
import { beforeUpdate } from "svelte";
import Summary from "./Summary.html";
import Summary from "./Summary.svelte";
const PAGE_SIZE = 20;
export let items;
export let offset;
export let page;
let previous_page;
let items;
let offset;
beforeUpdate(async () => {
if (page !== previous_page) {
previous_page = page;
items = await fetch(`https://node-hnapi.herokuapp.com/news?page=${page}`).then(r => r.json())
$: fetch(`https://node-hnapi.herokuapp.com/news?page=${page}`)
.then(r => r.json())
.then(data => {
items = data;
offset = PAGE_SIZE * (page - 1);
window.scrollTo(0, 0);
}
});
});
</script>
<style>

Loading…
Cancel
Save