feat: reduce requests for reactions
This commit is contained in:
parent
c48f1b420f
commit
66187a8c3b
|
|
@ -45,6 +45,7 @@ export const Reactions: React.FC<{
|
|||
|
||||
const likes = useGetLikes({
|
||||
pageId: pageId,
|
||||
includeCharacter: size !== "sm",
|
||||
})
|
||||
const isLike = useCheckLike({
|
||||
address,
|
||||
|
|
@ -53,6 +54,7 @@ export const Reactions: React.FC<{
|
|||
|
||||
const mints = useGetMints({
|
||||
pageId: pageId,
|
||||
includeCharacter: size !== "sm",
|
||||
})
|
||||
const isMint = useCheckMint({
|
||||
address,
|
||||
|
|
|
|||
|
|
@ -445,9 +445,11 @@ export async function unlikePage(
|
|||
export async function getLikes({
|
||||
pageId,
|
||||
cursor,
|
||||
includeCharacter,
|
||||
}: {
|
||||
pageId: string
|
||||
cursor?: string
|
||||
includeCharacter?: boolean
|
||||
}) {
|
||||
const res = await indexer.getBacklinksOfNote(
|
||||
pageId.split("-")[0],
|
||||
|
|
@ -457,30 +459,32 @@ export async function getLikes({
|
|||
cursor,
|
||||
},
|
||||
)
|
||||
await Promise.all(
|
||||
res.list?.map(async (item) => {
|
||||
if (
|
||||
!item.fromCharacter?.metadata?.content &&
|
||||
item.fromCharacter?.metadata?.uri
|
||||
) {
|
||||
try {
|
||||
item.fromCharacter.metadata.content = (
|
||||
await axios.get(toGateway(item.fromCharacter?.metadata?.uri), {
|
||||
...(typeof window === "undefined" && {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
|
||||
},
|
||||
}),
|
||||
})
|
||||
).data
|
||||
} catch (error) {
|
||||
console.warn(error)
|
||||
if (includeCharacter) {
|
||||
await Promise.all(
|
||||
res.list?.map(async (item) => {
|
||||
if (
|
||||
!item.fromCharacter?.metadata?.content &&
|
||||
item.fromCharacter?.metadata?.uri
|
||||
) {
|
||||
try {
|
||||
item.fromCharacter.metadata.content = (
|
||||
await axios.get(toGateway(item.fromCharacter?.metadata?.uri), {
|
||||
...(typeof window === "undefined" && {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
|
||||
},
|
||||
}),
|
||||
})
|
||||
).data
|
||||
} catch (error) {
|
||||
console.warn(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
;(<any>item).character = item.fromCharacter
|
||||
}),
|
||||
)
|
||||
;(<any>item).character = item.fromCharacter
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
|
@ -520,9 +524,11 @@ export async function mintPage(
|
|||
export async function getMints({
|
||||
pageId,
|
||||
cursor,
|
||||
includeCharacter,
|
||||
}: {
|
||||
pageId: string
|
||||
cursor?: string
|
||||
includeCharacter?: boolean
|
||||
}) {
|
||||
const data = await indexer.getMintedNotesOfNote(
|
||||
pageId.split("-")[0],
|
||||
|
|
@ -532,28 +538,33 @@ export async function getMints({
|
|||
},
|
||||
)
|
||||
|
||||
await Promise.all(
|
||||
data.list.map(async (item: any) => {
|
||||
const owner = item.owner
|
||||
item.character = await indexer.getPrimaryCharacter(owner)
|
||||
if (!item.character?.metadata?.content && item.character?.metadata?.uri) {
|
||||
try {
|
||||
item.character.metadata.content = (
|
||||
await axios.get(toGateway(item.character?.metadata?.uri), {
|
||||
...(typeof window === "undefined" && {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
|
||||
},
|
||||
}),
|
||||
})
|
||||
).data
|
||||
} catch (error) {
|
||||
console.warn(error)
|
||||
if (includeCharacter) {
|
||||
await Promise.all(
|
||||
data.list.map(async (item: any) => {
|
||||
const owner = item.owner
|
||||
item.character = await indexer.getPrimaryCharacter(owner)
|
||||
if (
|
||||
!item.character?.metadata?.content &&
|
||||
item.character?.metadata?.uri
|
||||
) {
|
||||
try {
|
||||
item.character.metadata.content = (
|
||||
await axios.get(toGateway(item.character?.metadata?.uri), {
|
||||
...(typeof window === "undefined" && {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
|
||||
},
|
||||
}),
|
||||
})
|
||||
).data
|
||||
} catch (error) {
|
||||
console.warn(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,19 +22,26 @@ export const useGetPage = (input: Parameters<typeof pageModel.getPage>[0]) => {
|
|||
})
|
||||
}
|
||||
|
||||
export const useGetLikes = (input: { pageId?: string }) => {
|
||||
return useQuery(["getLikes", input.pageId], async () => {
|
||||
if (!input.pageId) {
|
||||
return {
|
||||
count: 0,
|
||||
list: [],
|
||||
cursor: undefined,
|
||||
export const useGetLikes = (input: {
|
||||
pageId?: string
|
||||
includeCharacter?: boolean
|
||||
}) => {
|
||||
return useQuery(
|
||||
["getLikes", input.pageId, input.includeCharacter],
|
||||
async () => {
|
||||
if (!input.pageId) {
|
||||
return {
|
||||
count: 0,
|
||||
list: [],
|
||||
cursor: undefined,
|
||||
}
|
||||
}
|
||||
}
|
||||
return pageModel.getLikes({
|
||||
pageId: input.pageId,
|
||||
})
|
||||
})
|
||||
return pageModel.getLikes({
|
||||
pageId: input.pageId,
|
||||
includeCharacter: input.includeCharacter,
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export const useCheckLike = (input: { address?: string; pageId?: string }) => {
|
||||
|
|
@ -52,19 +59,26 @@ export const useCheckLike = (input: { address?: string; pageId?: string }) => {
|
|||
})
|
||||
}
|
||||
|
||||
export const useGetMints = (input: { pageId?: string }) => {
|
||||
return useQuery(["getMints", input.pageId], async () => {
|
||||
if (!input.pageId) {
|
||||
return {
|
||||
count: 0,
|
||||
list: [],
|
||||
cursor: undefined,
|
||||
export const useGetMints = (input: {
|
||||
pageId?: string
|
||||
includeCharacter?: boolean
|
||||
}) => {
|
||||
return useQuery(
|
||||
["getMints", input.pageId, input.includeCharacter],
|
||||
async () => {
|
||||
if (!input.pageId) {
|
||||
return {
|
||||
count: 0,
|
||||
list: [],
|
||||
cursor: undefined,
|
||||
}
|
||||
}
|
||||
}
|
||||
return pageModel.getMints({
|
||||
pageId: input.pageId,
|
||||
})
|
||||
})
|
||||
return pageModel.getMints({
|
||||
pageId: input.pageId,
|
||||
includeCharacter: input.includeCharacter,
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export const useCheckMint = (input: { address?: string; pageId?: string }) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue