From 47e3fb1c189b2e10c80943d713615cb59ebac66e Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 3 Jul 2023 23:02:32 +0100 Subject: [PATCH] feat: page loading fiction --- src/components/home/HomeFeed.tsx | 3 ++ src/models/home.model.ts | 58 ++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/components/home/HomeFeed.tsx b/src/components/home/HomeFeed.tsx index 3e358c84..150c4c63 100644 --- a/src/components/home/HomeFeed.tsx +++ b/src/components/home/HomeFeed.tsx @@ -236,6 +236,9 @@ export const HomeFeed = ({ topicIncludeKeywords: params.topic ? topics.find((t) => t.name === params.topic)?.includeKeywords : undefined, + topicIncludeTags: params.topic + ? topics.find((t) => t.name === params.topic)?.includeTags + : undefined, }) const hasFiltering = type === "latest" diff --git a/src/models/home.model.ts b/src/models/home.model.ts index 9553b047..065a82cc 100644 --- a/src/models/home.model.ts +++ b/src/models/home.model.ts @@ -29,6 +29,7 @@ export async function getFeed({ tag, useHTML, topicIncludeKeywords, + topicIncludeTags, }: { type?: FeedType cursor?: string @@ -41,6 +42,7 @@ export async function getFeed({ tag?: string useHTML?: boolean topicIncludeKeywords?: string[] + topicIncludeTags?: string[] }) { if (type === "search" && !searchKeyword) { type = "latest" @@ -143,9 +145,11 @@ export async function getFeed({ return { list, - cursor: `${list[list.length - 1]?.characterId}_${ - list[list.length - 1]?.noteId - }`, + cursor: list?.length + ? `${list[list.length - 1]?.characterId}_${ + list[list.length - 1]?.noteId + }` + : undefined, count: list?.length || 0, } } @@ -187,7 +191,7 @@ export async function getFeed({ } } case "topic": { - if (!topicIncludeKeywords && !noteIds) { + if (!topicIncludeKeywords && !topicIncludeTags && !noteIds) { return { list: [], cursor: "", @@ -215,7 +219,18 @@ export async function getFeed({ ] }, orderBy: [{ createdAt: desc }], - take: 1000, + take: ${limit}, + ${ + cursor + ? ` + cursor: { + note_characterId_noteId_unique: { + characterId: ${cursor.split("_")[0]}, + noteId: ${cursor.split("_")[1]} + }, + },` + : "" + } ) { characterId noteId @@ -249,18 +264,25 @@ export async function getFeed({ return { list: list, - cursor: "", + cursor: list?.length + ? `${list[list.length - 1]?.characterId}_${ + list[list.length - 1]?.noteId + }` + : undefined, count: list?.length || 0, } - } - - if (topicIncludeKeywords) { - const includeString = topicIncludeKeywords - .map( + } else { + const includeString = [ + ...(topicIncludeKeywords?.map( (topicIncludeKeyword) => - `{ content: { path: "title", string_contains: "${topicIncludeKeyword}" } }, { content: { path: "content", string_contains: "${topicIncludeKeyword}" } },`, - ) - .join("\n") + `{ content: { path: "title", string_contains: "${topicIncludeKeyword}" } }, { content: { path: "content", string_contains: "${topicIncludeKeyword}" } }`, + ) || []), + ...(topicIncludeTags?.map( + (topicIncludeTag) => + `{ content: { path: "tags", array_contains: "${topicIncludeTag}" } },`, + ) || []), + ].join("\n") + const result = await client .query( ` @@ -335,9 +357,11 @@ export async function getFeed({ return { list: list, - cursor: `${list[list.length - 1]?.characterId}_${ - list[list.length - 1]?.noteId - }`, + cursor: list?.length + ? `${list[list.length - 1]?.characterId}_${ + list[list.length - 1]?.noteId + }` + : undefined, count: list?.length || 0, } }