From bcc5e5e48c5f4a45d67e09a19e71d96c3622b255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andri=20=C3=93skarsson?= Date: Thu, 16 Jan 2025 20:52:30 +0100 Subject: [PATCH] maybe follow feed is better now --- .../react/bluesky/feed-post-list.tsx | 1 + .../components/react/bluesky/post-view.tsx | 1 + .../web/src/components/react/tag-controls.tsx | 123 +-- .../src/pages/admin/feed/[rkey]/index.astro | 3 +- apps/web/src/pages/admin/index.astro | 166 ++-- .../db/drizzle/0036_flashy_star_brand.sql | 5 + .../db/drizzle/meta/0036_snapshot.json | 729 ++++++++++++++++++ .../atproto/db/drizzle/meta/_journal.json | 7 + .../atproto/domain/get-moderation-queue.ts | 57 +- packages/atproto/domain/get-post-tags.ts | 1 + .../atproto/domain/get-tech-following-feed.ts | 3 +- packages/atproto/domain/post/post.table.ts | 3 + .../atproto/domain/store-post-with-record.ts | 9 +- packages/atproto/feeds/feed-result.ts | 7 + packages/atproto/feeds/index.ts | 37 +- .../atproto/feeds/queries/following-all.ts | 17 - .../atproto/feeds/queries/following-posts.ts | 2 +- .../feeds/queries/following-reposts.ts | 2 +- packages/atproto/feeds/queries/following.ts | 65 +- .../atproto/feeds/queries/sq-following.ts | 11 + packages/atproto/feeds/queries/sq-reposts.ts | 22 + packages/atproto/feeds/queries/sq-scores.ts | 18 + packages/atproto/update-feed.ts | 4 +- 23 files changed, 1084 insertions(+), 209 deletions(-) create mode 100644 packages/atproto/db/drizzle/0036_flashy_star_brand.sql create mode 100644 packages/atproto/db/drizzle/meta/0036_snapshot.json create mode 100644 packages/atproto/feeds/feed-result.ts delete mode 100644 packages/atproto/feeds/queries/following-all.ts create mode 100644 packages/atproto/feeds/queries/sq-following.ts create mode 100644 packages/atproto/feeds/queries/sq-reposts.ts create mode 100644 packages/atproto/feeds/queries/sq-scores.ts diff --git a/apps/web/src/components/react/bluesky/feed-post-list.tsx b/apps/web/src/components/react/bluesky/feed-post-list.tsx index f5642ac..243b774 100644 --- a/apps/web/src/components/react/bluesky/feed-post-list.tsx +++ b/apps/web/src/components/react/bluesky/feed-post-list.tsx @@ -17,6 +17,7 @@ export function BskyFeedPostList({ uri={p.post} mayClassify={mayClassify} reason={p.reason} + feedContext={p.feedContext} /> ))} diff --git a/apps/web/src/components/react/bluesky/post-view.tsx b/apps/web/src/components/react/bluesky/post-view.tsx index 4ea821a..474514b 100644 --- a/apps/web/src/components/react/bluesky/post-view.tsx +++ b/apps/web/src/components/react/bluesky/post-view.tsx @@ -127,6 +127,7 @@ export function PostView({ Repost )} + {feedContext &&
{feedContext}
} >["data"], + undefined +>[number] & { + avgScore?: number; +}; + export function TagControls({ postUri }: { postUri: string }) { - const [tags, setTags] = useState< - Exclude< - Awaited>["data"], - undefined - > - >([]); + const [tags, setTags] = useState>([]); useEffect(() => { actions.getTagsForPost({ postUri }).then((tags) => { if (tags.error) return []; - setTags(tags.data); + setTags( + tags.data.map((tag) => { + return { + ...tag, + avgScore: + tag.scores.length > 0 + ? tag.scores.reduce((acc, curr) => { + return acc + curr.score; + }, 0) / tag.scores.length + : 0, + }; + }) + ); }); }, []); @@ -58,55 +72,54 @@ export function TagControls({ postUri }: { postUri: string }) { // TODO: Show that it's tagged now } - const avgScore = useMemo(() => { - const totalScores = tags.reduce((acc, tag) => { - const sum = tag.scores.reduce((sum, score) => sum + score.score, 0); - if (sum === 0) return acc; - return acc + sum / tag.scores.length; - }, 0); - - return Math.floor(totalScores / tags.length); - }, [tags]); - return ( - +
{tags && - tags.map((tag) => ( - - - {`#${tag.tag}`}{" "} - = 80 && "text-green-700", - avgScore < 80 && "text-orange-700", - avgScore <= 50 && "text-red-700" - )} - > - {avgScore}% - - + tags + .filter((tag) => tag.avgScore !== undefined) + .map((tag) => ( +
+
+ + {`#${tag.tag}`}{" "} + = 80 && "text-green-700", + tag.avgScore! < 80 && "text-orange-700", + tag.avgScore! <= 50 && "text-red-700" + )} + > + {tag.avgScore}% + + - - - - - {tag.scores.map((cl) => ( - - {cl.score} % - - ))} - - ))} - + + + + +
+ + {tag.scores.map((cl) => ( + + {cl.score} % + + ))} + +
+ ))} +
); } diff --git a/apps/web/src/pages/admin/feed/[rkey]/index.astro b/apps/web/src/pages/admin/feed/[rkey]/index.astro index 1c8991a..e48d570 100644 --- a/apps/web/src/pages/admin/feed/[rkey]/index.astro +++ b/apps/web/src/pages/admin/feed/[rkey]/index.astro @@ -1,5 +1,5 @@ --- -import { DEFAULT_FEED_ACTOR, feeds, getPublicPosts } from "@andrioid/atproto"; +import { DEFAULT_FEED_ACTOR, feeds } from "@andrioid/atproto"; import Layout from "~astro/layout.astro"; import PageLayout from "~astro/page-layout.astro"; import { BskyFeedPostList } from "~react/bluesky/feed-post-list"; @@ -15,7 +15,6 @@ const res = await feed.handler({ actorDid: DEFAULT_FEED_ACTOR, }); const postUris = res.feed.map((p) => p.post); -const posts = await getPublicPosts(postUris); const mayClassify = Astro.locals.mayClassify; --- diff --git a/apps/web/src/pages/admin/index.astro b/apps/web/src/pages/admin/index.astro index 5727be8..b48e7e9 100644 --- a/apps/web/src/pages/admin/index.astro +++ b/apps/web/src/pages/admin/index.astro @@ -1,11 +1,15 @@ --- -import { getAdminStats, getModerationPosts } from "@andrioid/atproto"; +import { DEFAULT_FEED_ACTOR, feeds, getAdminStats } from "@andrioid/atproto"; +import { undefined } from "astro:schema"; import Layout from "~astro/layout.astro"; import PageLayout from "~astro/page-layout.astro"; -import { BskyPostList } from "~react/bluesky/post-list"; +import { BskyFeedPostList } from "~react/bluesky/feed-post-list"; const at = Astro.locals.at; const url = new URL(Astro.request.url); -const query = url.searchParams.get("query"); +const query = + url.searchParams.get("query") !== null + ? (url.searchParams.get("query") as string) + : ""; const minscore = url.searchParams.get("minscore") !== null ? Number(url.searchParams.get("minscore")) @@ -14,79 +18,37 @@ const maxscore = url.searchParams.get("maxscore") !== null ? Number(url.searchParams.get("maxscore")) : undefined; -const page = url.searchParams.get("page") - ? Number(url.searchParams.get("page")) +const offset = url.searchParams.get("offset") + ? Number(url.searchParams.get("offset")) : 1; +const limit = 30; +const rkey = url.searchParams.get("rkey") ?? "tech-mod"; const dat = await getAdminStats(at); -const posts = await getModerationPosts(at, { - query: query ?? undefined, - minScore: minscore, - maxScore: maxscore, - page: page, +const feed = feeds.find((f) => f.rkey === rkey); +if (!feed) { + throw new Error("No handler found for selected feed"); +} + +const feedRes = await feed.handler({ + ctx: Astro.locals.at, + actorDid: DEFAULT_FEED_ACTOR, + cursor: offset.toString(), + search: query, }); + +const posts = feedRes.feed; + const nurl = new URL(url); -const nextPageNumber = page + 1; -nurl.searchParams.set("page", `${nextPageNumber}`); +const nextOffset = `${offset + limit - 1}`; +const prevOffset = `${offset ? offset - limit : 0}`; +nurl.searchParams.set("offset", `${nextOffset}`); const nextPage = nurl.toString(); const scoreOptions = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]; --- -
-
-
- - - - - - - - - - - -
-
-
{ dat.map((d) => ( @@ -97,13 +59,75 @@ const scoreOptions = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]; )) }
- p.postId)} - mayClassify={true} - > +
+
+
+ +
+
+
+ + + + + + - + + + + +
+
+
+
+
Loading
-
+