refactor: Refactor UI and API interactions for displaying post metadata and tags.
- Remove unused code and simplify logic in MainFeed.tsx for improved performance and UI - Update interfaces and models for better data management - Refactor API function and cache key names for clarity and consistency - Add a new optional parameter to expandPage function in home.model.ts for score retrieval from API
This commit is contained in:
parent
a80bfd676f
commit
1372439e73
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
### BEGIN GPTCOMMIT HOOK ###
|
||||
gptcommit prepare-commit-msg --commit-msg-file "$1" --commit-source "$2" --commit-sha "$3"
|
||||
### END GPTCOMMIT HOOK ###
|
||||
|
|
@ -9,9 +9,6 @@ import { CharacterFloatCard } from "~/components/common/CharacterFloatCard"
|
|||
import { useAccountState } from "@crossbell/connect-kit"
|
||||
import InfiniteScroll from "react-infinite-scroller"
|
||||
import { ExpandedNote } from "~/lib/types"
|
||||
import { useGetScore } from "~/queries/page"
|
||||
import { toCid } from "~/lib/ipfs-parser"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { useEffect, useState } from "react"
|
||||
import { Switch } from "@headlessui/react"
|
||||
import { setStorage, getStorage } from "~/lib/storage"
|
||||
|
|
@ -26,16 +23,16 @@ const Post = ({
|
|||
const router = useRouter()
|
||||
const { t } = useTranslation(["common", "site"])
|
||||
const date = useDate()
|
||||
const score = useGetScore({
|
||||
cid: toCid(post.metadata.uri || ""),
|
||||
})
|
||||
|
||||
if (
|
||||
post.metadata?.content?.score?.number &&
|
||||
post.metadata.content.score.number <= filtering
|
||||
) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn({
|
||||
hidden: score.data?.score && score.data?.score <= filtering,
|
||||
})}
|
||||
>
|
||||
<div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<CharacterFloatCard siteId={post.character?.handle}>
|
||||
<div className="flex items-center space-x-4 cursor-pointer">
|
||||
|
|
|
|||
|
|
@ -97,6 +97,10 @@ export type ExpandedNote = NoteEntity & {
|
|||
frontMatter?: Record<string, any>
|
||||
slug?: string
|
||||
views?: number
|
||||
score?: {
|
||||
number?: number
|
||||
reason?: string
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
import { ExpandedNote } from "~/lib/types"
|
||||
import { indexer } from "@crossbell/indexer"
|
||||
import { toCid } from "~/lib/ipfs-parser"
|
||||
|
||||
const expandPage = async (page: ExpandedNote, useStat?: boolean) => {
|
||||
const expandPage = async (
|
||||
page: ExpandedNote,
|
||||
useStat?: boolean,
|
||||
useScore?: boolean,
|
||||
) => {
|
||||
if (page.metadata?.content) {
|
||||
if (page.metadata?.content?.content) {
|
||||
const { renderPageContent } = await import("~/markdown")
|
||||
|
|
@ -28,6 +33,19 @@ const expandPage = async (page: ExpandedNote, useStat?: boolean) => {
|
|||
).json()
|
||||
page.metadata.content.views = stat.viewDetailCount
|
||||
}
|
||||
|
||||
if (useScore) {
|
||||
try {
|
||||
const score = (
|
||||
await (
|
||||
await fetch(`/api/score?cid=${toCid(page.metadata?.uri || "")}`)
|
||||
).json()
|
||||
).data
|
||||
page.metadata.content.score = score
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return page
|
||||
|
|
@ -56,7 +74,7 @@ export async function getFeed({
|
|||
|
||||
const list = await Promise.all(
|
||||
result.list.map(async (page: any) => {
|
||||
return expandPage(page, true)
|
||||
return expandPage(page, false, true)
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -640,10 +640,6 @@ export async function getSummary({
|
|||
).data
|
||||
}
|
||||
|
||||
export async function getScore({ cid }: { cid: string }) {
|
||||
return (await (await fetch(`/api/score?cid=${cid}`)).json()).data
|
||||
}
|
||||
|
||||
export async function checkMirror(characterId: string) {
|
||||
const notes = await indexer.getNotes({
|
||||
characterId,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ const getOriginalScore = async (cid: string) => {
|
|||
console.timeEnd(`fetching score ${cid}`)
|
||||
|
||||
return {
|
||||
score: parseInt(response.choices?.[0]?.message?.content?.trim()),
|
||||
number: parseInt(response.choices?.[0]?.message?.content?.trim()),
|
||||
reason: response.choices?.[0]?.message?.content
|
||||
?.trim()
|
||||
.replace(/^\d+([,.\s]*)/, "")
|
||||
|
|
@ -54,7 +54,7 @@ const getOriginalScore = async (cid: string) => {
|
|||
|
||||
export async function getScore(cid: string) {
|
||||
const score = await cacheGet({
|
||||
key: ["summary_score222", cid],
|
||||
key: ["summary_score", cid],
|
||||
getValueFun: async () => {
|
||||
const meta = await prisma.metadata.findFirst({
|
||||
where: {
|
||||
|
|
@ -64,7 +64,7 @@ export async function getScore(cid: string) {
|
|||
if (meta) {
|
||||
if (meta?.ai_score !== null) {
|
||||
return {
|
||||
score: meta.ai_score,
|
||||
number: meta.ai_score,
|
||||
reason: meta.ai_score_reason,
|
||||
}
|
||||
} else {
|
||||
|
|
@ -75,7 +75,7 @@ export async function getScore(cid: string) {
|
|||
uri: `ipfs://${cid}`,
|
||||
},
|
||||
data: {
|
||||
ai_score: score.score,
|
||||
ai_score: score.number,
|
||||
ai_score_reason: score.reason,
|
||||
},
|
||||
})
|
||||
|
|
@ -89,7 +89,7 @@ export async function getScore(cid: string) {
|
|||
await prisma.metadata.create({
|
||||
data: {
|
||||
uri: `ipfs://${cid}`,
|
||||
ai_score: score.score,
|
||||
ai_score: score.number,
|
||||
ai_score_reason: score.reason,
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -256,17 +256,6 @@ export function useGetSummary(input: { cid?: string; lang?: string }) {
|
|||
})
|
||||
}
|
||||
|
||||
export function useGetScore(input: { cid?: string }) {
|
||||
return useQuery(["getScore", input.cid], async () => {
|
||||
if (!input.cid) {
|
||||
return
|
||||
}
|
||||
return pageModel.getScore({
|
||||
cid: input.cid,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function useGetMirrorXyz(input: { address: string }) {
|
||||
return useQuery(["getMirror", input.address], async () => {
|
||||
if (!input.address) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue