predikt/oracle/web/hooks/use-mod-reports.ts
caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

60 lines
1.7 KiB
TypeScript

import { useEffect, useState } from 'react'
import { api } from 'web/lib/api/api'
import { ModReport, ReportStatus } from 'common/src/mod-report'
import { keyBy, mapValues } from 'lodash'
export const useModReports = (statuses: ReportStatus[]) => {
const [reports, setReports] = useState<ModReport[] | undefined>(undefined)
const [reportStatuses, setReportStatuses] = useState<{
[key: number]: ReportStatus
}>({})
const [modNotes, setModNotes] = useState<{
[key: number]: string | undefined
}>({})
const getModReports = async () => {
try {
const response = await api('get-mod-reports', {
statuses,
limit: 50,
offset: 0,
})
if (response && response.status === 'success') {
const newReports = response.reports
const sortedReports = newReports.sort(
(a: ModReport, b: ModReport) =>
new Date(b.created_time).getTime() -
new Date(a.created_time).getTime()
)
setReports(sortedReports)
const reportsById = keyBy(sortedReports, 'report_id')
const initialStatuses = mapValues(reportsById, (r) => r.status)
const initialNotes = mapValues(reportsById, (r) => r.mod_note)
setReportStatuses(initialStatuses)
setModNotes(initialNotes)
} else {
console.error('Failed to fetch reports:', response)
}
} catch (error) {
console.error('Error fetching reports:', error)
}
}
useEffect(() => {
getModReports()
}, [JSON.stringify(statuses)])
return {
reports,
initialLoading: reports === undefined,
reportStatuses,
modNotes,
setReportStatuses,
setModNotes,
}
}