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>
59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
import { Contract } from 'common/contract'
|
|
import { DashboardLinkItem, DashboardQuestionItem } from 'common/dashboard'
|
|
import { fetchLinkPreviews } from 'common/link-preview'
|
|
import { getContracts } from 'common/supabase/contracts'
|
|
import { removeUndefinedProps } from 'common/util/object'
|
|
import { capitalize, omit } from 'lodash'
|
|
import { DashboardEndpoints } from 'web/components/dashboard/dashboard-page'
|
|
import { api } from 'web/lib/api/api'
|
|
import { db } from 'web/lib/supabase/db'
|
|
import { NewsDashboardPageProps } from 'web/public/data/elections-data'
|
|
|
|
export const getDashboardProps = async (
|
|
slug: string,
|
|
endpointProps?: { slug: DashboardEndpoints; topSlug: string }
|
|
): Promise<NewsDashboardPageProps> => {
|
|
const dashboard = await api('get-dashboard-from-slug', {
|
|
dashboardSlug: slug,
|
|
})
|
|
|
|
const links = dashboard.items
|
|
.filter((item): item is DashboardLinkItem => item.type === 'link')
|
|
.map((item) => item.url)
|
|
|
|
const questionSlugs = dashboard.items
|
|
.filter((item): item is DashboardQuestionItem => item.type === 'question')
|
|
.map((item) => item.slug)
|
|
.slice(0, 20) // preload just the first n questions
|
|
|
|
const previews = await fetchLinkPreviews(links)
|
|
const fullContracts = await getContracts(db, questionSlugs, 'slug')
|
|
const contracts = fullContracts.map((c) =>
|
|
// remove some heavy fields that are not needed for the cards
|
|
removeUndefinedProps(omit(c, 'description', 'coverImageUrl'))
|
|
)
|
|
|
|
const headlines = await api(
|
|
'headlines',
|
|
removeUndefinedProps({ slug: endpointProps?.slug })
|
|
)
|
|
if (endpointProps?.topSlug) {
|
|
const topSlug = endpointProps.topSlug
|
|
headlines.unshift({
|
|
id: topSlug,
|
|
slug: '',
|
|
title: capitalize(topSlug),
|
|
})
|
|
}
|
|
return {
|
|
state: 'success',
|
|
initialDashboard: dashboard,
|
|
headlines,
|
|
previews,
|
|
// Heavy fields (description, coverImageUrl) are stripped above for the
|
|
// cards; the cast keeps the public type as Contract[].
|
|
initialContracts: contracts as Contract[],
|
|
slug,
|
|
}
|
|
}
|