diff --git a/src/comp/page/posts/postlist.svelte b/src/comp/page/posts/postlist.svelte
index 803efa7..b76eabe 100644
--- a/src/comp/page/posts/postlist.svelte
+++ b/src/comp/page/posts/postlist.svelte
@@ -2,9 +2,10 @@
import { goto, replaceState } from '$app/navigation';
import { page } from '$app/stores';
import { getNamedId } from '$lib/util';
- import { onMount } from 'svelte';
+ import { onMount, tick } from 'svelte';
import Post from '../post/post.svelte';
import PostCard from './postcard.svelte';
+ import { parsePost } from '$lib/serialize/parse';
/**
* @type {number}
@@ -29,7 +30,7 @@
/**
* @type {import('$types/base').Post | null}
*/
- export let glancePost = null;
+ let glancePost = null;
function getDefaultedUrl(/** @type {URL} */ url) {
const u = new URL(url);
@@ -38,40 +39,44 @@
return u;
}
- const newUrl = getDefaultedUrl($page.url)
+ /**
+ * @type {URL | undefined}
+ */
+ let newUrl = undefined;
- onMount(() => {
+ onMount(async () => {
+ await tick();
+ newUrl = getDefaultedUrl($page.url);
replaceState(newUrl, {});
});
/** @type {boolean[]} */
$: hidden = Array(posts.length).fill(false);
- function previewPost(/** @type {CustomEvent<>} */ e) {
+ async function previewPost(/** @type {CustomEvent<>} */ e) {
+ if (!newUrl) return;
+
/** @type {import("$types/base").Post} */
- const post = e.detail.post;
+ glancePost = e.detail.post;
posts.forEach((p, index) => {
- hidden[index] = p == post;
+ hidden[index] = p == glancePost;
});
- newUrl.searchParams.set('glance', String(post.id));
- goto(newUrl, {
- replaceState: true,
- noScroll: true
- });
+ const request = await fetch(`/api/post?id=${e.detail.post.id}&metrics=true`);
+ const response = await request.json();
+ glancePost = parsePost(response['post']);
+ console.log(glancePost);
}
function dismiss(/** @type {MouseEvent | TouchEvent} */ e) {
+ if (!newUrl) return;
+
+ glancePost = null;
+
e.stopPropagation();
hidden = Array(posts.length).fill(false);
-
- newUrl.searchParams.delete('glance');
- goto(newUrl, {
- replaceState: true,
- noScroll: true
- });
}
function expand(/** @type {MouseEvent | TouchEvent} */ e) {
@@ -144,9 +149,9 @@
diff --git a/src/routes/(app)/posts/+page.server.js b/src/routes/(app)/posts/+page.server.js
index 93a582d..7a6c888 100644
--- a/src/routes/(app)/posts/+page.server.js
+++ b/src/routes/(app)/posts/+page.server.js
@@ -16,13 +16,8 @@ export async function load({ url }) {
offset: pageSize * page,
});
- const glance = parseIntNull(url.searchParams.get('glance'));
-
- const glancePost = glance ? await getPost(glance, { withMetrics: true }) : null;
-
return {
posts: result,
- glancePost: glancePost,
itemsCount: pageSize,
pageIndex: page,
totalResultCount: count,
diff --git a/src/routes/(app)/posts/+page.svelte b/src/routes/(app)/posts/+page.svelte
index 6e496b5..56bca75 100644
--- a/src/routes/(app)/posts/+page.svelte
+++ b/src/routes/(app)/posts/+page.svelte
@@ -1,12 +1,11 @@