Add basic loading of older posts

This commit is contained in:
2023-04-03 17:24:59 +02:00
parent 2eddb77b74
commit e8e864bdfc
4 changed files with 64 additions and 15 deletions

View File

@ -0,0 +1,11 @@
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
function loadOlderPosts() {
dispatch('loadOlderPosts');
}
</script>
<button on:click={loadOlderPosts}>Load More</button>

View File

@ -172,15 +172,19 @@ export function savePost(post: Post): void {
});
}
export async function getPosts(since: string | null, limit: number) {
export async function getPosts(since: string | null, before: string | null, limit: number) {
let promise = await new Promise<Post[]>((resolve, reject) => {
let filter_query;
let params: any = { $limit: limit };
if (since === null) {
if (since === null && before === null) {
filter_query = '';
} else {
} else if (since !== null) {
filter_query = 'WHERE posts.created_at > $since';
params.$since = since;
} else if (before !== null) {
// Setting both, before and since doesn't make sense, so this case is not explicitly handled
filter_query = 'WHERE posts.created_at < $before';
params.$before = before;
}
const sql = `SELECT posts.id, posts.content, posts.created_at, posts.url,
accounts.id AS account_id, accounts.acct, accounts.username, accounts.display_name,