feat: add Likes and Achievements stat

This commit is contained in:
DIYgod 2023-07-25 19:19:35 +01:00
parent 15a0bfb839
commit 798846dbbb
No known key found for this signature in database
6 changed files with 79 additions and 43 deletions

View File

@ -39,45 +39,59 @@ export default function SubdomainIndex() {
const statMap = [
{
icon: "icon-[mingcute--news-line]",
name: "Published posts",
value: stat.data?.notesCount,
name: "Creation",
value: stat.data?.notesCount ?? "-",
url: `/dashboard/${subdomain}/posts`,
},
{
icon: "icon-[mingcute--comment-line]",
name: "Received comments",
value: stat.data?.commentsCount,
name: "Comments",
value: stat.data?.commentsCount ?? "-",
url: `/dashboard/${subdomain}/comments`,
},
{
icon: "icon-[mingcute--heart-line]",
name: "Received tips",
name: "Tips1",
value: `${
tips.data?.pages?.[0]?.list
?.map((i) => +i.amount)
.reduce((acr, cur) => acr + cur, 0) ?? 0
.reduce((acr, cur) => acr + cur, 0) ?? "-"
} MIRA`,
url: `/dashboard/${subdomain}/tokens`,
},
{
icon: "icon-[mingcute--user-follow-line]",
name: "Followers",
value: stat.data?.subscriptionCount,
icon: "icon-[mingcute--thumb-up-2-line]",
name: "Likes",
value: stat.data?.likesCount ?? "-",
url: getSiteLink({
subdomain,
}),
},
{
icon: "icon-[mingcute--user-follow-line]",
name: "Followers",
value: stat.data?.subscriptionCount ?? "-",
url: getSiteLink({
subdomain,
}),
},
{
icon: "icon-[mingcute--trophy-line]",
name: "Achievements",
value: stat.data?.achievements ?? "-",
url: `/dashboard/${subdomain}/achievements`,
},
{
icon: "icon-[mingcute--eye-line]",
name: "Viewed",
value: stat.data?.viewsCount,
value: stat.data?.viewsCount ?? "-",
url: getSiteLink({
subdomain,
}),
},
{
icon: "icon-[mingcute--history-line]",
name: "Site Duration",
name: "Become xLogger for",
value:
date.dayjs().diff(date.dayjs(stat.data?.createdAt), "day") +
" " +

View File

@ -1,4 +1,5 @@
{
"Tips1": "Tips",
"link post-vs-page": "https://wordpress.com/zh-cn/support/post-vs-page/",
"delete_confirmation_post": "Are you sure you want to DELETE this post?",
"delete_confirmation_page": "Are you sure you want to DELETE this page?",

View File

@ -6,11 +6,6 @@
"Unread notifications": "未読の通知",
"Settings": "設定",
"Site Stats": "サイトの統計情報",
"Total Posts": "記事数",
"Total Comments": "コメント数",
"Total Followers": "フォロワー数",
"Total Views": "閲覧数",
"Site Duration": "サイトの運営期間",
"days": "日",
"Deleted!": "削除されました!",
"Fail to Deleted.": "削除できませんでした。",

View File

@ -8,12 +8,11 @@
"Events": "活動",
"New Events": "新活動",
"Site Stats": "網站統計",
"Published posts": "文章",
"Received comments": "留言",
"Likes": "讚",
"Tips1": "打賞",
"Followers": "粉絲",
"Viewed": "瀏覽量",
"Received tips": "Donate",
"Site Duration": "Blog 誕生",
"Become xLogger for": "成為 xLogger",
"days": "天",
"Deleted!": "刪掉了哦!",
"Fail to Deleted.": "删除失败",

View File

@ -8,12 +8,11 @@
"Events": "活动",
"New Events": "新活动",
"Site Stats": "站点统计",
"Published posts": "发布的文章",
"Received comments": "收到的评论",
"Likes": "点赞",
"Tips1": "打赏",
"Followers": "关注者",
"Viewed": "浏览量",
"Received tips": "收到的打赏",
"Site Duration": "站点运行时间",
"Become xLogger for": "成为 xLogger",
"days": "天",
"Deleted!": "已删除!",
"Fail to Deleted.": "删除失败",

View File

@ -199,25 +199,49 @@ export async function removeOperator(
export async function getStat({ characterId }: { characterId: number }) {
if (characterId) {
const [stat, site, subscriptions, comments, notes] = await Promise.all([
(
await fetch(
`https://indexer.crossbell.io/v1/stat/characters/${characterId}`,
)
).json(),
indexer.character.get(characterId),
indexer.link.getBacklinksOfCharacter(characterId, { limit: 0 }),
indexer.note.getMany({
limit: 0,
toCharacterId: characterId,
}),
indexer.note.getMany({
characterId,
sources: "xlog",
tags: ["post"],
limit: 0,
}),
])
const [stat, site, subscriptions, comments, notes, likes, achievement] =
await Promise.all([
(
await fetch(
`https://indexer.crossbell.io/v1/stat/characters/${characterId}`,
)
).json(),
indexer.character.get(characterId),
indexer.link.getBacklinksOfCharacter(characterId, {
limit: 0,
linkType: "follow",
}),
indexer.note.getMany({
limit: 0,
toCharacterId: characterId,
}),
indexer.note.getMany({
characterId,
sources: "xlog",
limit: 0,
}),
await client
.query(
gql`
query getLinklistCount($characterId: Int!) {
linkCount(
where: {
linkType: { equals: "like" }
toCharacterId: { equals: $characterId }
}
)
}
`,
{
characterId,
},
)
.toPromise(),
await indexer.achievement.getMany(characterId, {
status: ["MINTED"],
}),
])
return {
viewsCount: stat.viewNoteCount,
createdAt: site?.createdAt,
@ -225,6 +249,10 @@ export async function getStat({ characterId }: { characterId: number }) {
subscriptionCount: subscriptions?.count,
commentsCount: comments?.count,
notesCount: notes?.count,
likesCount: likes?.data?.linkCount,
achievements: achievement?.list.reduce((acc, cur) => {
return acc + cur.groups.length
}, 0),
}
}
}