From 92f04875e7f83eae6137afe343cd18f8ef9380c9 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 7 Apr 2023 01:13:56 +0100 Subject: [PATCH] feat: the showcase is changed to sort by blog update time and only show characters that have blog updates in the last 15 days --- data/showcase.json | 8 ++++---- src/models/site.model.ts | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/data/showcase.json b/data/showcase.json index af3829a5..ad32c585 100644 --- a/data/showcase.json +++ b/data/showcase.json @@ -7,8 +7,8 @@ 51197, 32085, 1407, 51154, 51104, 40675, 4381, 43051, 50622, 51056, 33483, 19, 50877, 33420, 50094, 49213, 33276, 50351, 42993, 50216, 50132, 50143, 43754, 32168, 500, 47399, 33538, 48951, 33471, 33396, 37223, 33458, 39133, 20004, - 43625, 42787, 43258, 33462, 47109, 46939, 45701, 33233, 37346, 40671, 33870, - 33421, 51552, 51585, 48937, 51379, 51460, 51084, 51509, 51478, 51639, 48910, - 51139, 39329, 51683, 51077, 51374, 49120, 47356, 17096, 50708, 51430, 51935, - 51756, 6558, 49392, 52186, 52055, 52282, 52270, 5825, 51351, 52233 + 43625, 42787, 43258, 33462, 47109, 46939, 45701, 33233, 37346, 40671, 51552, + 51585, 48937, 51379, 51460, 51084, 51509, 51478, 51639, 48910, 51139, 39329, + 51683, 51077, 51374, 49120, 47356, 17096, 50708, 51430, 51935, 51756, 6558, + 49392, 52186, 52055, 52282, 52270, 5825, 51351, 52233 ] diff --git a/src/models/site.model.ts b/src/models/site.model.ts index 31d4824d..d7dee29e 100644 --- a/src/models/site.model.ts +++ b/src/models/site.model.ts @@ -8,6 +8,7 @@ import { createClient, cacheExchange, fetchExchange } from "@urql/core" import { Indexer } from "crossbell.js" import { CharacterOperatorPermission } from "crossbell.js" import type { useContract } from "@crossbell/contract" +import dayjs from "dayjs" type Contract = ReturnType @@ -135,22 +136,23 @@ export const getSites = async (input: number[]) => { url: "https://indexer.crossbell.io/v1/graphql", exchanges: [cacheExchange, fetchExchange], }) + const oneMonthAgo = dayjs().subtract(15, "day").toISOString() const result = await client .query( ` query getCharacters($identities: [Int!], $limit: Int) { characters( where: { characterId: { in: $identities } }, orderBy: [{ updatedAt: desc }], take: $limit ) { handle - updatedAt characterId - notes { - updatedAt - } metadata { uri content } } + notes( where: { characterId: { in: $identities }, createdAt: { gt: "${oneMonthAgo}" }, metadata: { is: { content: { path: "sources", array_contains: "xlog" } } } }, orderBy: [{ updatedAt: desc }] ) { + characterId + createdAt + } }`, { identities: input, @@ -171,18 +173,32 @@ export const getSites = async (input: number[]) => { site.metadata?.content?.attributes?.find( (a: any) => a.trait_type === "xlog_custom_domain", )?.value || "" - - site.updatedAt = [...site.notes, site] - .map((i) => i.updatedAt) - .sort() - .pop() }) - result.data?.characters?.sort((a: any, b: any) => { - return b.updatedAt > a.updatedAt ? 1 : -1 + const createdAts: { + [key: string]: string + } = {} + result.data?.notes.forEach((note: any) => { + if (!createdAts[note.characterId + ""]) { + createdAts[note.characterId + ""] = note.createdAt + } }) + const list = Object.keys(createdAts) + .map((characterId: string) => { + const character = result.data?.characters.find( + (c: any) => c.characterId === characterId, + ) - return result.data?.characters + return { + ...character, + createdAt: createdAts[characterId], + } + }) + .sort((a: any, b: any) => { + return b.createdAt > a.createdAt ? 1 : -1 + }) + + return list } export const getSubscription = async (