diff --git a/src/models/site.model.ts b/src/models/site.model.ts index fb62734a..7892285f 100644 --- a/src/models/site.model.ts +++ b/src/models/site.model.ts @@ -7,18 +7,10 @@ import type { Profiles as UniProfiles } from "unidata.js" import { createClient } from "@urql/core" import axios from "axios" import { indexer } from "@crossbell/indexer" -import type { LinkEntity, NoteEntity, Contract } from "crossbell.js" +import type { Contract } from "crossbell.js" import { CharacterOperatorPermission } from "crossbell.js" import { GeneralAccount } from "@crossbell/connect-kit" -export const checkSubdomain = async ({ - subdomain, - updatingSiteId, -}: { - subdomain: string - updatingSiteId?: string -}) => {} - const expandSite = (site: Profile) => { site.navigation = JSON.parse( site.metadata?.raw?.attributes?.find( @@ -247,6 +239,7 @@ export const getSiteSubscriptions = async ( data: { siteId: string cursor?: string + limit?: number }, customUnidata?: Unidata, ) => { @@ -256,6 +249,7 @@ export const getSiteSubscriptions = async ( platform: "Crossbell", reversed: true, cursor: data.cursor, + limit: data.limit, }) links?.list.map(async (item: any) => { @@ -540,3 +534,35 @@ export async function getNFTs(address: string, customUnidata?: Unidata) { }) return assets } + +export async function getStat({ characterId }: { characterId: string }) { + if (characterId) { + const [stat, site, subscriptions, comments, notes] = await Promise.all([ + ( + await fetch( + `https://indexer.crossbell.io/v1/stat/characters/${characterId}`, + ) + ).json(), + indexer.getCharacter(characterId), + indexer.getBacklinksOfCharacter(characterId, { + limit: 0, + }), + indexer.getNotes({ + limit: 0, + toCharacterId: characterId, + }), + indexer.getNotes({ + characterId, + sources: "xlog", + limit: 0, + }), + ]) + return { + viewsCount: stat.viewNoteCount, + createdAt: site?.createdAt, + subscriptionCount: subscriptions?.count, + commentsCount: comments?.count, + notesCount: notes?.count, + } + } +} diff --git a/src/pages/dashboard/[subdomain]/index.tsx b/src/pages/dashboard/[subdomain]/index.tsx index 706ce46e..e0eb2afb 100644 --- a/src/pages/dashboard/[subdomain]/index.tsx +++ b/src/pages/dashboard/[subdomain]/index.tsx @@ -6,21 +6,62 @@ import Image from "next/image" import { DISCORD_LINK, TWITTER_LINK, GITHUB_LINK, APP_NAME } from "~/lib/env" import { getSiteLink } from "~/lib/helpers" import type { ReactElement } from "react" +import { useGetSite, useGetStat } from "~/queries/site" +import dayjs from "~/lib/date" export default function SubdomainIndex() { const router = useRouter() const subdomain = router.query.subdomain as string + const site = useGetSite(subdomain) + const characterId = site.data?.metadata?.proof + const stat = useGetStat({ + characterId, + }) + const statMap = [ + { + name: "Total Posts", + value: stat.data?.notesCount, + }, + { + name: "Total Comments", + value: stat.data?.commentsCount, + }, + { + name: "Total Subscribers", + value: stat.data?.subscriptionCount, + }, + { + name: "Total Views", + value: stat.data?.viewsCount, + }, + { + name: "Site Duration", + value: dayjs().diff(dayjs(stat.data?.createdAt), "day") + " days", + }, + ] + return ( -
+
logo
+

Site Stat

+
+ {statMap.map((item) => ( +
+ {item.name} + + {item.value} + +
+ ))} +

Hello there,

-

- This page is quite empty for now, but we will polish it very soon! - Maybe some useful analytics! -

+

Welcome to use {APP_NAME}!

Here{`'`}re some useful links to get started:

  • @@ -53,10 +94,7 @@ export default function SubdomainIndex() { via RSS Reader
-

- You are not alone, join the community to meet friends or give xLog - some advice: -

+

Join the community to meet friends or build {APP_NAME} together:

  • diff --git a/src/queries/site.ts b/src/queries/site.ts index 788f8379..35b07ab5 100644 --- a/src/queries/site.ts +++ b/src/queries/site.ts @@ -285,3 +285,16 @@ export const useGetNFTs = (address: string) => { ).json() }) } + +export const useGetStat = ( + data: Partial[0]>, +) => { + return useQuery(["getStat", data.characterId], async () => { + if (!data.characterId) { + return null + } + return siteModel.getStat({ + characterId: data.characterId, + }) + }) +}