feat: move showcase model to home
This commit is contained in:
parent
9c954e2c0b
commit
dd8993f1b2
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"latest": [53994]
|
||||
"latest": [53994, 54570, 54481]
|
||||
}
|
||||
|
|
@ -3,6 +3,10 @@
|
|||
"name": "xLog",
|
||||
"description": "Let's talk about xLog, whether to praise or criticize it.",
|
||||
"notes": [
|
||||
"54600-5",
|
||||
"50388-12",
|
||||
"51471-1",
|
||||
"47393-8",
|
||||
"53096-11",
|
||||
"53477-2",
|
||||
"52800-154",
|
||||
|
|
@ -119,6 +123,9 @@
|
|||
"name": "ChatGPT",
|
||||
"description": "The world is undergoing a fusion, and we are in the center of it.",
|
||||
"notes": [
|
||||
"17096-10",
|
||||
"49041-41",
|
||||
"54641-5",
|
||||
"51540-12",
|
||||
"52759-5",
|
||||
"54679-2",
|
||||
|
|
@ -400,6 +407,9 @@
|
|||
"name": "Fiction",
|
||||
"description": "Experience a world of imagination through these fiction stories.",
|
||||
"notes": [
|
||||
"54513-16",
|
||||
"54513-15",
|
||||
"54513-14",
|
||||
"54513-13",
|
||||
"53827-13",
|
||||
"54513-8",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { SearchInput } from "~/components/common/SearchInput"
|
|||
import { Image } from "~/components/ui/Image"
|
||||
import { UniLink } from "~/components/ui/UniLink"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { useGetShowcase } from "~/queries/site"
|
||||
import { useGetShowcase } from "~/queries/home"
|
||||
|
||||
import topics from "../../../data/topics.json"
|
||||
import { FollowAllButton } from "../common/FollowAllButton"
|
||||
|
|
|
|||
|
|
@ -266,3 +266,107 @@ export async function getFeed({
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const getShowcase = async () => {
|
||||
const client = createClient({
|
||||
url: "https://indexer.crossbell.io/v1/graphql",
|
||||
exchanges: [cacheExchange, fetchExchange],
|
||||
})
|
||||
const oneMonthAgo = dayjs().subtract(10, "day").toISOString()
|
||||
|
||||
const listResponse = await client
|
||||
.query(
|
||||
`
|
||||
query getCharacters($filter: [Int!]) {
|
||||
characters(
|
||||
where: {
|
||||
characterId: {
|
||||
notIn: $filter
|
||||
}
|
||||
notes: {
|
||||
some: {
|
||||
stat: { viewDetailCount: { gte: 100 } }
|
||||
metadata: {
|
||||
content: { path: "sources", array_contains: "xlog" }
|
||||
AND: { content: { path: "tags", array_contains: "post" } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
characterId
|
||||
}
|
||||
}`,
|
||||
{
|
||||
filter: filter.latest,
|
||||
},
|
||||
)
|
||||
.toPromise()
|
||||
const characterList = listResponse.data?.characters.map((c: any) =>
|
||||
parseInt(c.characterId),
|
||||
)
|
||||
|
||||
const result = await client
|
||||
.query(
|
||||
`
|
||||
query getCharacters($identities: [Int!]) {
|
||||
characters( where: { characterId: { in: $identities } }, orderBy: [{ updatedAt: desc }] ) {
|
||||
handle
|
||||
characterId
|
||||
metadata {
|
||||
uri
|
||||
content
|
||||
}
|
||||
}
|
||||
notes( where: { characterId: { in: $identities }, createdAt: { gt: "${oneMonthAgo}" }, metadata: { content: { path: "sources", array_contains: "xlog" } } }, orderBy: [{ updatedAt: desc }] ) {
|
||||
characterId
|
||||
createdAt
|
||||
}
|
||||
}`,
|
||||
{
|
||||
identities: characterList,
|
||||
},
|
||||
)
|
||||
.toPromise()
|
||||
|
||||
result.data?.characters?.forEach((site: any) => {
|
||||
if (site.metadata.content) {
|
||||
site.metadata.content.name = site.metadata?.content?.name || site.handle
|
||||
} else {
|
||||
site.metadata.content = {
|
||||
name: site.handle,
|
||||
}
|
||||
}
|
||||
|
||||
site.custom_domain =
|
||||
site.metadata?.content?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_custom_domain",
|
||||
)?.value || ""
|
||||
})
|
||||
|
||||
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 {
|
||||
...character,
|
||||
createdAt: createdAts[characterId],
|
||||
}
|
||||
})
|
||||
.sort((a: any, b: any) => {
|
||||
return b.createdAt > a.createdAt ? 1 : -1
|
||||
})
|
||||
.slice(0, 100)
|
||||
|
||||
return list
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { CharacterOperatorPermission, Indexer } from "crossbell.js"
|
||||
import dayjs from "dayjs"
|
||||
import { nanoid } from "nanoid"
|
||||
import type Unidata from "unidata.js"
|
||||
import type { Profiles as UniProfiles } from "unidata.js"
|
||||
|
|
@ -91,94 +90,6 @@ export const getSite = async (input: string, customUnidata?: Unidata) => {
|
|||
return site
|
||||
}
|
||||
|
||||
export const getShowcase = async () => {
|
||||
const client = createClient({
|
||||
url: "https://indexer.crossbell.io/v1/graphql",
|
||||
exchanges: [cacheExchange, fetchExchange],
|
||||
})
|
||||
const oneMonthAgo = dayjs().subtract(10, "day").toISOString()
|
||||
|
||||
const listResponse = await client
|
||||
.query(
|
||||
`
|
||||
query getCharacters {
|
||||
characters( where: { notes: { some: { stat: { viewDetailCount: { gte: 100 } }, metadata: { content: { path: "sources", array_contains: "xlog" }, AND: { content: { path: "tags", array_contains: "post" } } } } } } ) {
|
||||
characterId
|
||||
}
|
||||
}
|
||||
`,
|
||||
{},
|
||||
)
|
||||
.toPromise()
|
||||
const characterList = listResponse.data?.characters.map((c: any) =>
|
||||
parseInt(c.characterId),
|
||||
)
|
||||
|
||||
const result = await client
|
||||
.query(
|
||||
`
|
||||
query getCharacters($identities: [Int!]) {
|
||||
characters( where: { characterId: { in: $identities } }, orderBy: [{ updatedAt: desc }] ) {
|
||||
handle
|
||||
characterId
|
||||
metadata {
|
||||
uri
|
||||
content
|
||||
}
|
||||
}
|
||||
notes( where: { characterId: { in: $identities }, createdAt: { gt: "${oneMonthAgo}" }, metadata: { content: { path: "sources", array_contains: "xlog" } } }, orderBy: [{ updatedAt: desc }] ) {
|
||||
characterId
|
||||
createdAt
|
||||
}
|
||||
}`,
|
||||
{
|
||||
identities: characterList,
|
||||
},
|
||||
)
|
||||
.toPromise()
|
||||
|
||||
result.data?.characters?.forEach((site: any) => {
|
||||
if (site.metadata.content) {
|
||||
site.metadata.content.name = site.metadata?.content?.name || site.handle
|
||||
} else {
|
||||
site.metadata.content = {
|
||||
name: site.handle,
|
||||
}
|
||||
}
|
||||
|
||||
site.custom_domain =
|
||||
site.metadata?.content?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_custom_domain",
|
||||
)?.value || ""
|
||||
})
|
||||
|
||||
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 {
|
||||
...character,
|
||||
createdAt: createdAts[characterId],
|
||||
}
|
||||
})
|
||||
.sort((a: any, b: any) => {
|
||||
return b.createdAt > a.createdAt ? 1 : -1
|
||||
})
|
||||
.slice(0, 100)
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
export const getSubscriptionsFromList = async (
|
||||
list: number[],
|
||||
fromCharacterId: number,
|
||||
|
|
|
|||
|
|
@ -11,12 +11,11 @@ import { MainSidebar } from "~/components/main/MainSidebar"
|
|||
import { Tabs } from "~/components/ui/Tabs"
|
||||
import { languageDetector } from "~/lib/language-detector"
|
||||
import type { FeedType } from "~/models/home.model"
|
||||
import { prefetchGetFeed } from "~/queries/home.server"
|
||||
import { prefetchGetSites } from "~/queries/site.server"
|
||||
import { prefetchGetFeed, prefetchGetShowcase } from "~/queries/home.server"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const queryClient = new QueryClient()
|
||||
await prefetchGetSites(queryClient)
|
||||
await prefetchGetShowcase(queryClient)
|
||||
await prefetchGetFeed(
|
||||
{
|
||||
type: "latest",
|
||||
|
|
|
|||
|
|
@ -14,13 +14,9 @@ import { CSB_SCAN, DISCORD_LINK, GITHUB_LINK, TWITTER_LINK } from "~/lib/env"
|
|||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { serverSidePropsHandler } from "~/lib/server-side-props"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { useGetShowcase } from "~/queries/home"
|
||||
import { useGetPagesBySite } from "~/queries/page"
|
||||
import {
|
||||
useGetShowcase,
|
||||
useGetSite,
|
||||
useGetStat,
|
||||
useGetTips,
|
||||
} from "~/queries/site"
|
||||
import { useGetSite, useGetStat, useGetTips } from "~/queries/site"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
|
||||
async (ctx) => {
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ import { UniLink } from "~/components/ui/UniLink"
|
|||
import { CSB_SCAN, GITHUB_LINK } from "~/lib/env"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { languageDetector } from "~/lib/language-detector"
|
||||
import { useGetShowcase } from "~/queries/site"
|
||||
import { prefetchGetSites } from "~/queries/site.server"
|
||||
import { useGetShowcase } from "~/queries/home"
|
||||
import { prefetchGetShowcase } from "~/queries/home.server"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const queryClient = new QueryClient()
|
||||
await prefetchGetSites(queryClient)
|
||||
await prefetchGetShowcase(queryClient)
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ import { MainFeed } from "~/components/main/MainFeed"
|
|||
import { MainLayout } from "~/components/main/MainLayout"
|
||||
import { MainSidebar } from "~/components/main/MainSidebar"
|
||||
import { languageDetector } from "~/lib/language-detector"
|
||||
import { prefetchGetSites } from "~/queries/site.server"
|
||||
import { prefetchGetShowcase } from "~/queries/home.server"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const queryClient = new QueryClient()
|
||||
await prefetchGetSites(queryClient)
|
||||
await prefetchGetShowcase(queryClient)
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ import { MainFeed } from "~/components/main/MainFeed"
|
|||
import { MainLayout } from "~/components/main/MainLayout"
|
||||
import { MainSidebar } from "~/components/main/MainSidebar"
|
||||
import { languageDetector } from "~/lib/language-detector"
|
||||
import { prefetchGetSites } from "~/queries/site.server"
|
||||
import { prefetchGetShowcase } from "~/queries/home.server"
|
||||
|
||||
import topics from "../../../data/topics.json"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const queryClient = new QueryClient()
|
||||
await prefetchGetSites(queryClient)
|
||||
await prefetchGetShowcase(queryClient)
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
|
|
|||
|
|
@ -28,3 +28,13 @@ export const prefetchGetFeed = async (
|
|||
getNextPageParam: (lastPage) => lastPage?.cursor || undefined,
|
||||
})
|
||||
}
|
||||
|
||||
export const prefetchGetShowcase = async (queryClient: QueryClient) => {
|
||||
const key = ["getShowcase"]
|
||||
await queryClient.fetchQuery(key, async () => {
|
||||
return cacheGet({
|
||||
key,
|
||||
getValueFun: () => homeModel.getShowcase(),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { useInfiniteQuery } from "@tanstack/react-query"
|
||||
import { useInfiniteQuery, useQuery } from "@tanstack/react-query"
|
||||
|
||||
import * as homeModel from "~/models/home.model"
|
||||
|
||||
|
|
@ -23,3 +23,9 @@ export const useGetFeed = (data?: {
|
|||
refetchOnWindowFocus: false,
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetShowcase = () => {
|
||||
return useQuery(["getShowcase"], async () => {
|
||||
return homeModel.getShowcase()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,16 +70,6 @@ export const prefetchGetSiteToSubscriptions = async (
|
|||
})
|
||||
}
|
||||
|
||||
export const prefetchGetSites = async (queryClient: QueryClient) => {
|
||||
const key = ["getShowcase"]
|
||||
await queryClient.fetchQuery(key, async () => {
|
||||
return cacheGet({
|
||||
key,
|
||||
getValueFun: () => siteModel.getShowcase(),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchGetComments = async (
|
||||
data: Parameters<typeof siteModel.getCommentsBySite>[0],
|
||||
queryClient: QueryClient,
|
||||
|
|
|
|||
|
|
@ -41,12 +41,6 @@ export const useGetSite = (input?: string) => {
|
|||
})
|
||||
}
|
||||
|
||||
export const useGetShowcase = () => {
|
||||
return useQuery(["getShowcase"], async () => {
|
||||
return siteModel.getShowcase()
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetSubscription = (siteId: string | undefined) => {
|
||||
const account = useAccountState((s) => s.computed.account)
|
||||
const handle =
|
||||
|
|
|
|||
Loading…
Reference in New Issue