From 499fd6fa5b41601f44bff29d11e30add5f81d1f4 Mon Sep 17 00:00:00 2001
From: bloodwiing
Date: Wed, 15 May 2024 18:07:40 +0300
Subject: [PATCH] Refactor: Better PostMetric API and Rendering
---
src/comp/actionbar.svelte | 7 +-
src/comp/iconvalue.svelte | 32 +++++++++
src/comp/page/post.svelte | 84 +++++++++++++++++++++++-
src/comp/postlist.svelte | 36 ++++++-----
src/comp/rating.svelte | 25 ++------
src/lib/server/db/post.js | 38 ++++++++---
src/lib/server/db/postmertics.js | 89 --------------------------
src/routes/(app)/posts/+page.server.js | 19 ++----
src/routes/(app)/posts/+page.svelte | 5 +-
static/icon/chart-bar.svg | 1 +
static/icon/database.svg | 1 +
static/icon/message.svg | 1 +
static/icon/user.svg | 1 +
13 files changed, 185 insertions(+), 154 deletions(-)
create mode 100644 src/comp/iconvalue.svelte
delete mode 100644 src/lib/server/db/postmertics.js
create mode 100644 static/icon/chart-bar.svg
create mode 100644 static/icon/database.svg
create mode 100644 static/icon/message.svg
create mode 100644 static/icon/user.svg
diff --git a/src/comp/actionbar.svelte b/src/comp/actionbar.svelte
index 106e538..b63a90e 100644
--- a/src/comp/actionbar.svelte
+++ b/src/comp/actionbar.svelte
@@ -1,5 +1,6 @@
+
+
+
+
diff --git a/src/comp/page/post.svelte b/src/comp/page/post.svelte
index 6dc8fc9..a6b75e2 100644
--- a/src/comp/page/post.svelte
+++ b/src/comp/page/post.svelte
@@ -3,7 +3,11 @@
import Ago from "$comp/ago.svelte";
import Avatar from "$comp/avatar.svelte";
import CommentList from "$comp/commentlist.svelte";
+ import Iconvalue from "$comp/iconvalue.svelte";
import Mention from "$comp/mention.svelte";
+ import Tablericon from "$comp/tablericon.svelte";
+ import { round10 } from "expected-round";
+ import moment from "moment";
/**
* @type {import("$types/base").Post}
@@ -15,7 +19,17 @@
*/
export let commentTree = null;
- $: isPreview = commentTree == null;
+ /**
+ * @type {boolean}
+ */
+ export let showMetrics = false;
+
+ let showStats = false;
+
+ function togglePostStats(/** @type {MouseEvent | TouchEvent} */ e) {
+ e.stopPropagation();
+ showStats = !showStats;
+ }
- {post.name}
+ {post.name}
@@ -88,7 +136,37 @@
{post.content}
-
+
+ {#if showMetrics && post.metrics}
+ {post.metrics.commentCount}
+ {post.metrics.userCount}
+ {round10(post.metrics.relevancy, -2)}
+ {/if}
+
+
+
+
+ {#if showStats}
+
+
Debug stats
+
+ | ID | {post.id} |
+ | Author | {post.author?.id} |
+ | Created Date | {post.postDate} |
+ | Score | {post.rating.likes - post.rating.dislikes} |
+ {#if post.metrics}
+ | Comment Count | {post.metrics.commentCount} |
+ | User Count | {post.metrics.userCount} |
+ | Latest Activity | {post.metrics.latestActivity} |
+ | Engagement | {post.metrics.engagement} |
+ | Age | {post.metrics.age} |
+ | Relevancy | {round10(post.metrics.relevancy, -5)} |
+ {/if}
+
+
+ {/if}
{#if commentTree}
diff --git a/src/comp/postlist.svelte b/src/comp/postlist.svelte
index 51bacc8..efcbed2 100644
--- a/src/comp/postlist.svelte
+++ b/src/comp/postlist.svelte
@@ -9,8 +9,10 @@
*/
export let posts = [];
- /** @type {import("$types/base").Post | null} */
- $: currentPreview = null;
+ /**
+ * @type {import('$types/base').Post | null}
+ */
+ export let glancePost = null;
/** @type {boolean[]} */
$: hidden = Array(posts.length).fill(false);
@@ -19,33 +21,33 @@
/** @type {import("$types/base").Post} */
const post = e.detail.post;
- currentPreview = post;
-
posts.forEach((p, index) => {
hidden[index] = p == post;
});
- goto(`/posts?glance=${currentPreview.id}`, {
+ goto(`/posts?glance=${post.id}`, {
replaceState: true,
noScroll: true
});
}
- function dismiss() {
- currentPreview = null;
+ function dismiss(/** @type {MouseEvent | TouchEvent} */ e) {
+ e.stopPropagation();
hidden = Array(posts.length).fill(false);
- // goto(`/posts`, {
- // replaceState: true,
- // noScroll: true
- // });
+ goto(`/posts`, {
+ replaceState: true,
+ noScroll: true
+ });
}
- function expand() {
- if (currentPreview == null) return;
+ function expand(/** @type {MouseEvent | TouchEvent} */ e) {
+ if (glancePost == null) return;
+
+ e.stopPropagation();
- goto(`/posts/${getNamedId(currentPreview.id, currentPreview.name)}`, {
+ goto(`/posts/${getNamedId(glancePost.id, glancePost.name)}`, {
replaceState: false
});
}
@@ -109,10 +111,10 @@
{/each}
-