adds feed
This commit is contained in:
30
web/src/lib/stores/feed_store.ts
Normal file
30
web/src/lib/stores/feed_store.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { FeedItem } from "$lib/models/feed";
|
||||
import { APIError } from "$lib/util/api_util";
|
||||
import type { ListResult } from "pocketbase";
|
||||
|
||||
let feed: FeedItem[] = []
|
||||
|
||||
|
||||
export async function feed_index(page: number, perPage: number = 10, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||
let r = await f(`/api/v1/feed?` + new URLSearchParams({
|
||||
expand: "author",
|
||||
page: page.toString(),
|
||||
perPage: perPage.toString(),
|
||||
sort: '-created'
|
||||
}), {
|
||||
method: 'GET',
|
||||
})
|
||||
if (!r.ok) {
|
||||
const response = await r.json();
|
||||
throw new APIError(r.status, response.message, response.detail)
|
||||
}
|
||||
|
||||
const fetchedFeed: ListResult<FeedItem> = await r.json()
|
||||
|
||||
const result = page > 1 ? [...feed, ...fetchedFeed.items] : fetchedFeed.items
|
||||
|
||||
feed = result;
|
||||
|
||||
return { ...fetchedFeed, items: result };
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user