sanifae/src/lib/components/PostList.svelte

32 lines
1.1 KiB
Svelte
Raw Normal View History

2023-02-12 01:53:13 -05:00
<script>
import Post from '$lib/components/Post.svelte';
2023-02-12 12:06:19 -05:00
import Button from '$lib/components/Button.svelte';
import {setLocation} from '$lib/util.js';
2023-02-12 01:53:13 -05:00
export let data;
</script>
2023-02-12 12:06:19 -05:00
<p>
<Button clickFunc={() => { window.location.search = setLocation(window.location,'sort','rating')}}>Sort by rating</Button>
<Button clickFunc={() => { window.location.search = setLocation(window.location,'sort','time')}}>Sort by time</Button>
</p>
2023-02-12 01:53:13 -05:00
{#if data && data.postJson && data.postJson.data}
{#each data.postJson.data as post}
<Post
success={post.success}
username={post.username}
content={post.content}
upvotes={post.upvotes}
downvotes={post.downvotes}
id={post.id}
isAuthor={post.isAuthor}
2023-02-12 12:06:19 -05:00
time={post.time}
2023-02-12 01:53:13 -05:00
></Post>
{/each}
{/if}
<p>
2023-02-12 12:06:19 -05:00
<Button clickFunc={() => { window.location.search = setLocation(window.location,'page',((data.id)-1)) }}>Previous page</Button>
<Button clickFunc={() => { window.location.search = setLocation(window.location,'page',((data.id)+1)) }}>Next page</Button>
2023-02-12 01:53:13 -05:00
</p>