added files
This commit is contained in:
parent
7db3497bbe
commit
ad7827f2f1
54
functions/src/scripts/contest/scrape-ea.ts
Normal file
54
functions/src/scripts/contest/scrape-ea.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Run with `npx ts-node src/scripts/contest/scrape-ea.ts`
|
||||
import * as fs from 'fs'
|
||||
import * as puppeteer from 'puppeteer'
|
||||
import { CONTEST_DATA } from 'common/contest'
|
||||
|
||||
export function scrapeEA(contestLink: string, fileName: string) {
|
||||
;(async () => {
|
||||
const browser = await puppeteer.launch({ headless: true })
|
||||
const page = await browser.newPage()
|
||||
await page.goto(contestLink)
|
||||
|
||||
let loadMoreButton = await page.$('.LoadMore-root')
|
||||
|
||||
while (loadMoreButton) {
|
||||
await loadMoreButton.click()
|
||||
await page.waitForNetworkIdle()
|
||||
loadMoreButton = await page.$('.LoadMore-root')
|
||||
}
|
||||
|
||||
/* Run javascript inside the page */
|
||||
const data = await page.evaluate(() => {
|
||||
const list = []
|
||||
const items = document.querySelectorAll('.PostsItem2-root')
|
||||
|
||||
for (const item of items) {
|
||||
let link =
|
||||
'https://forum.effectivealtruism.org' +
|
||||
item?.querySelector('a')?.getAttribute('href')
|
||||
|
||||
list.push({
|
||||
title: item?.querySelector('a>span>span')?.innerHTML,
|
||||
author: item?.querySelector('a.UsersNameDisplay-userName')?.innerHTML,
|
||||
link: link,
|
||||
})
|
||||
}
|
||||
|
||||
return list
|
||||
})
|
||||
|
||||
fs.writeFileSync(
|
||||
'../web/lib/util/contests/' + fileName + '.json',
|
||||
JSON.stringify(data, null, 2)
|
||||
)
|
||||
|
||||
console.log(data)
|
||||
await browser.close()
|
||||
})()
|
||||
}
|
||||
|
||||
// runs using data from CONTEST_DATA
|
||||
scrapeEA(
|
||||
CONTEST_DATA['cause-exploration-prize'].submissionLink,
|
||||
CONTEST_DATA['cause-exploration-prize'].fileName
|
||||
)
|
157
web/lib/util/contests/causeExploration.json
Normal file
157
web/lib/util/contests/causeExploration.json
Normal file
|
@ -0,0 +1,157 @@
|
|||
[
|
||||
{
|
||||
"title": "New cause area: Violence against women and girls",
|
||||
"author": "Akhil",
|
||||
"link": "https://forum.effectivealtruism.org/posts/majcwf7i8pW8eMJ3v/new-cause-area-violence-against-women-and-girls"
|
||||
},
|
||||
{
|
||||
"title": "Open Philanthropy's Cause Exploration Prizes: $120k for written work on global health and wellbeing",
|
||||
"author": "ChrisSmith",
|
||||
"link": "https://forum.effectivealtruism.org/posts/iqcph4DbcP4PZGyDB/open-philanthropy-s-cause-exploration-prizes-usd120k-for"
|
||||
},
|
||||
{
|
||||
"title": "New cause area: training health workers to prevent newborn deaths",
|
||||
"author": "Marshall",
|
||||
"link": "https://forum.effectivealtruism.org/posts/B7wohgDDdwPoQAatt/new-cause-area-training-health-workers-to-prevent-newborn"
|
||||
},
|
||||
{
|
||||
"title": "The Case for Making Professional Degrees Undergraduate Degrees",
|
||||
"author": "ColdButtonIssues",
|
||||
"link": "https://forum.effectivealtruism.org/posts/fEMpAcNycbXpp6Ext/the-case-for-making-professional-degrees-undergraduate"
|
||||
},
|
||||
{
|
||||
"title": "Global Health & Development - Beyond the Streetlight",
|
||||
"author": "Richard Sedlmayr",
|
||||
"link": "https://forum.effectivealtruism.org/posts/DXKWHAkihdb6nkKyG/global-health-and-development-beyond-the-streetlight-1"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes submission: bivalve aquaculture",
|
||||
"author": "Brian Lui",
|
||||
"link": "https://forum.effectivealtruism.org/posts/7keuWWMoYY6dMnqys/cause-exploration-prizes-submission-bivalve-aquaculture"
|
||||
},
|
||||
{
|
||||
"title": "Potential new cause area: Obesity",
|
||||
"author": "Akhil",
|
||||
"link": "https://forum.effectivealtruism.org/posts/jhsXxPnKbwzLwrKFq/potential-new-cause-area-obesity"
|
||||
},
|
||||
{
|
||||
"title": "Energy Access in Sub-Saharan Africa: Open Philanthropy Cause Exploration Prize Submission",
|
||||
"author": "Tomer_Goloboy",
|
||||
"link": "https://forum.effectivealtruism.org/posts/ZPjMemurtzeumwcdw/energy-access-in-sub-saharan-africa-open-philanthropy-cause"
|
||||
},
|
||||
{
|
||||
"title": "Sleep: Open Philanthropy Cause Exploration Prize",
|
||||
"author": "SuhanKacholia",
|
||||
"link": "https://forum.effectivealtruism.org/posts/qnDBN3nAXgwyTnrAC/sleep-open-philanthropy-cause-exploration-prize"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Could New Technology Help Solve the Glasses Problem?",
|
||||
"author": "Open Philanthropy",
|
||||
"link": "https://forum.effectivealtruism.org/posts/a3vbQCgxTeYNvQBfc/cause-exploration-prizes-could-new-technology-help-solve-the"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Expanding access to infertility services in Low- and Middle-Income Countries (LMICs)",
|
||||
"author": "Soleine Scotney",
|
||||
"link": "https://forum.effectivealtruism.org/posts/WAnJw5bhuQwhJiLTm/cause-exploration-prizes-expanding-access-to-infertility"
|
||||
},
|
||||
{
|
||||
"title": "New Cause Area: Demographic Collapse",
|
||||
"author": "Malcolm Collins",
|
||||
"link": "https://forum.effectivealtruism.org/posts/vFfoqL74kmZbydKjp/new-cause-area-demographic-collapse"
|
||||
},
|
||||
{
|
||||
"title": "Cause area: climate adaptation in low-income countries",
|
||||
"author": "karthik-t",
|
||||
"link": "https://forum.effectivealtruism.org/posts/nE827LwrRk5ep3Xao/cause-area-climate-adaptation-in-low-income-countries"
|
||||
},
|
||||
{
|
||||
"title": "Open Climate Data as a possible cause area, Open Philanthropy",
|
||||
"author": "Ben Yeoh",
|
||||
"link": "https://forum.effectivealtruism.org/posts/s9HPpvMHgS5QYEM4C/open-climate-data-as-a-possible-cause-area-open-philanthropy"
|
||||
},
|
||||
{
|
||||
"title": "One Million Missing Children",
|
||||
"author": "ColdButtonIssues",
|
||||
"link": "https://forum.effectivealtruism.org/posts/H5LDwwmdBYBDNXTq4/one-million-missing-children"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Reducing Suffering and Long Term Risk in Common Law Nations via Strategic Case Law Funding",
|
||||
"author": "Open Philanthropy",
|
||||
"link": "https://forum.effectivealtruism.org/posts/C6urjnDeKjHGwf2M3/cause-exploration-prizes-reducing-suffering-and-long-term"
|
||||
},
|
||||
{
|
||||
"title": "NEW GLOBAL POOLS: IMPACT FUNDS ",
|
||||
"author": "TPogge",
|
||||
"link": "https://forum.effectivealtruism.org/posts/J8fwT9cZd6x5eED3e/new-global-pools-impact-funds"
|
||||
},
|
||||
{
|
||||
"title": "Saving lives near the precipice: we're doing it wrong?",
|
||||
"author": "Samin",
|
||||
"link": "https://forum.effectivealtruism.org/posts/hz2Q8GgZ28YKLazGb/saving-lives-near-the-precipice-we-re-doing-it-wrong"
|
||||
},
|
||||
{
|
||||
"title": "A platform for on-demand vaccination",
|
||||
"author": "George3d6",
|
||||
"link": "https://forum.effectivealtruism.org/posts/rS2zWRDxw5vZwdQAC/a-platform-for-on-demand-vaccination"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Time-restricted eating (IF) for individual and community health in LMICs ",
|
||||
"author": "Open Philanthropy",
|
||||
"link": "https://forum.effectivealtruism.org/posts/RuwCxvJ3xEwQfZevN/cause-exploration-prizes-time-restricted-eating-if-for"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Misinformation Gone Viral: Education As Pandemic Prevention",
|
||||
"author": "Open Philanthropy",
|
||||
"link": "https://forum.effectivealtruism.org/posts/Whi5ADu79uJrTpqEt/cause-exploration-prizes-misinformation-gone-viral-education"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Publishing Comprehensive Books Which Make the Case for Effective Corporate Animal Welfare Campaigns via a Writing Contest for Potential Authors",
|
||||
"author": "Engin Arıkan",
|
||||
"link": "https://forum.effectivealtruism.org/posts/9sraY9qrwuiKXJjhG/cause-exploration-prizes-publishing-comprehensive-books"
|
||||
},
|
||||
{
|
||||
"title": "Maritime capability and post-catastrophe resilience.",
|
||||
"author": "Tom Gardiner",
|
||||
"link": "https://forum.effectivealtruism.org/posts/nKDBhWFj3vwwFKwGC/maritime-capability-and-post-catastrophe-resilience-1"
|
||||
},
|
||||
{
|
||||
"title": "Shareholder activism",
|
||||
"author": "sbehmer",
|
||||
"link": "https://forum.effectivealtruism.org/posts/fqf4vgCWebTszvHm9/shareholder-activism"
|
||||
},
|
||||
{
|
||||
"title": "Water, sanitation and hygiene (“WASH”) interventions as a cause area",
|
||||
"author": "helmetedhornbill",
|
||||
"link": "https://forum.effectivealtruism.org/posts/WAbjLFkpSoA7FDvTD/water-sanitation-and-hygiene-wash-interventions-as-a-cause"
|
||||
},
|
||||
{
|
||||
"title": "Doing good is a privilege. This needs to change if we want to do good long-term. ",
|
||||
"author": "SofiaBalderson",
|
||||
"link": "https://forum.effectivealtruism.org/posts/gicYG5ymk4pPzrKAd/doing-good-is-a-privilege-this-needs-to-change-if-we-want-to"
|
||||
},
|
||||
{
|
||||
"title": "Deadline extension (to August 11) for Open Philanthropy's Cause Exploration Prizes",
|
||||
"author": "ChrisSmith",
|
||||
"link": "https://forum.effectivealtruism.org/posts/WdMbmLfb7DMMYHvKf/deadline-extension-to-august-11-for-open-philanthropy-s"
|
||||
},
|
||||
{
|
||||
"title": "Cause: Reducing Judicial Delay in India",
|
||||
"author": "Vastav Ratra",
|
||||
"link": "https://forum.effectivealtruism.org/posts/JcYyLfbnbhANCJdbv/cause-reducing-judicial-delay-in-india"
|
||||
},
|
||||
{
|
||||
"title": "Open Philanthropy Should Fund Further Cause Exploration",
|
||||
"author": "brb243",
|
||||
"link": "https://forum.effectivealtruism.org/posts/tvMjgDWptF5MNJtAo/open-philanthropy-should-fund-further-cause-exploration"
|
||||
},
|
||||
{
|
||||
"title": "Why Genetic Rescue",
|
||||
"author": "David Lang",
|
||||
"link": "https://forum.effectivealtruism.org/posts/ebBPcDxtSckRAoJfo/why-genetic-rescue"
|
||||
},
|
||||
{
|
||||
"title": "Promoting climate considerations within existing high priority areas of work",
|
||||
"author": "helmetedhornbill",
|
||||
"link": "https://forum.effectivealtruism.org/posts/pmfyGEa4NozDm2fng/promoting-climate-considerations-within-existing-high"
|
||||
}
|
||||
]
|
157
web/lib/util/contests/ea.json
Normal file
157
web/lib/util/contests/ea.json
Normal file
|
@ -0,0 +1,157 @@
|
|||
[
|
||||
{
|
||||
"title": "New cause area: Violence against women and girls",
|
||||
"author": "Akhil",
|
||||
"link": "https://forum.effectivealtruism.org/posts/majcwf7i8pW8eMJ3v/new-cause-area-violence-against-women-and-girls"
|
||||
},
|
||||
{
|
||||
"title": "Open Philanthropy's Cause Exploration Prizes: $120k for written work on global health and wellbeing",
|
||||
"author": "ChrisSmith",
|
||||
"link": "https://forum.effectivealtruism.org/posts/iqcph4DbcP4PZGyDB/open-philanthropy-s-cause-exploration-prizes-usd120k-for"
|
||||
},
|
||||
{
|
||||
"title": "New cause area: training health workers to prevent newborn deaths",
|
||||
"author": "Marshall",
|
||||
"link": "https://forum.effectivealtruism.org/posts/B7wohgDDdwPoQAatt/new-cause-area-training-health-workers-to-prevent-newborn"
|
||||
},
|
||||
{
|
||||
"title": "The Case for Making Professional Degrees Undergraduate Degrees",
|
||||
"author": "ColdButtonIssues",
|
||||
"link": "https://forum.effectivealtruism.org/posts/fEMpAcNycbXpp6Ext/the-case-for-making-professional-degrees-undergraduate"
|
||||
},
|
||||
{
|
||||
"title": "Global Health & Development - Beyond the Streetlight",
|
||||
"author": "Richard Sedlmayr",
|
||||
"link": "https://forum.effectivealtruism.org/posts/DXKWHAkihdb6nkKyG/global-health-and-development-beyond-the-streetlight-1"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes submission: bivalve aquaculture",
|
||||
"author": "Brian Lui",
|
||||
"link": "https://forum.effectivealtruism.org/posts/7keuWWMoYY6dMnqys/cause-exploration-prizes-submission-bivalve-aquaculture"
|
||||
},
|
||||
{
|
||||
"title": "Potential new cause area: Obesity",
|
||||
"author": "Akhil",
|
||||
"link": "https://forum.effectivealtruism.org/posts/jhsXxPnKbwzLwrKFq/potential-new-cause-area-obesity"
|
||||
},
|
||||
{
|
||||
"title": "Energy Access in Sub-Saharan Africa: Open Philanthropy Cause Exploration Prize Submission",
|
||||
"author": "Tomer_Goloboy",
|
||||
"link": "https://forum.effectivealtruism.org/posts/ZPjMemurtzeumwcdw/energy-access-in-sub-saharan-africa-open-philanthropy-cause"
|
||||
},
|
||||
{
|
||||
"title": "Sleep: Open Philanthropy Cause Exploration Prize",
|
||||
"author": "SuhanKacholia",
|
||||
"link": "https://forum.effectivealtruism.org/posts/qnDBN3nAXgwyTnrAC/sleep-open-philanthropy-cause-exploration-prize"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Could New Technology Help Solve the Glasses Problem?",
|
||||
"author": "Open Philanthropy",
|
||||
"link": "https://forum.effectivealtruism.org/posts/a3vbQCgxTeYNvQBfc/cause-exploration-prizes-could-new-technology-help-solve-the"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Expanding access to infertility services in Low- and Middle-Income Countries (LMICs)",
|
||||
"author": "Soleine Scotney",
|
||||
"link": "https://forum.effectivealtruism.org/posts/WAnJw5bhuQwhJiLTm/cause-exploration-prizes-expanding-access-to-infertility"
|
||||
},
|
||||
{
|
||||
"title": "New Cause Area: Demographic Collapse",
|
||||
"author": "Malcolm Collins",
|
||||
"link": "https://forum.effectivealtruism.org/posts/vFfoqL74kmZbydKjp/new-cause-area-demographic-collapse"
|
||||
},
|
||||
{
|
||||
"title": "Cause area: climate adaptation in low-income countries",
|
||||
"author": "karthik-t",
|
||||
"link": "https://forum.effectivealtruism.org/posts/nE827LwrRk5ep3Xao/cause-area-climate-adaptation-in-low-income-countries"
|
||||
},
|
||||
{
|
||||
"title": "Open Climate Data as a possible cause area, Open Philanthropy",
|
||||
"author": "Ben Yeoh",
|
||||
"link": "https://forum.effectivealtruism.org/posts/s9HPpvMHgS5QYEM4C/open-climate-data-as-a-possible-cause-area-open-philanthropy"
|
||||
},
|
||||
{
|
||||
"title": "One Million Missing Children",
|
||||
"author": "ColdButtonIssues",
|
||||
"link": "https://forum.effectivealtruism.org/posts/H5LDwwmdBYBDNXTq4/one-million-missing-children"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Reducing Suffering and Long Term Risk in Common Law Nations via Strategic Case Law Funding",
|
||||
"author": "Open Philanthropy",
|
||||
"link": "https://forum.effectivealtruism.org/posts/C6urjnDeKjHGwf2M3/cause-exploration-prizes-reducing-suffering-and-long-term"
|
||||
},
|
||||
{
|
||||
"title": "NEW GLOBAL POOLS: IMPACT FUNDS ",
|
||||
"author": "TPogge",
|
||||
"link": "https://forum.effectivealtruism.org/posts/J8fwT9cZd6x5eED3e/new-global-pools-impact-funds"
|
||||
},
|
||||
{
|
||||
"title": "Saving lives near the precipice: we're doing it wrong?",
|
||||
"author": "Samin",
|
||||
"link": "https://forum.effectivealtruism.org/posts/hz2Q8GgZ28YKLazGb/saving-lives-near-the-precipice-we-re-doing-it-wrong"
|
||||
},
|
||||
{
|
||||
"title": "A platform for on-demand vaccination",
|
||||
"author": "George3d6",
|
||||
"link": "https://forum.effectivealtruism.org/posts/rS2zWRDxw5vZwdQAC/a-platform-for-on-demand-vaccination"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Time-restricted eating (IF) for individual and community health in LMICs ",
|
||||
"author": "Open Philanthropy",
|
||||
"link": "https://forum.effectivealtruism.org/posts/RuwCxvJ3xEwQfZevN/cause-exploration-prizes-time-restricted-eating-if-for"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Misinformation Gone Viral: Education As Pandemic Prevention",
|
||||
"author": "Open Philanthropy",
|
||||
"link": "https://forum.effectivealtruism.org/posts/Whi5ADu79uJrTpqEt/cause-exploration-prizes-misinformation-gone-viral-education"
|
||||
},
|
||||
{
|
||||
"title": "Cause Exploration Prizes: Publishing Comprehensive Books Which Make the Case for Effective Corporate Animal Welfare Campaigns via a Writing Contest for Potential Authors",
|
||||
"author": "Engin Arıkan",
|
||||
"link": "https://forum.effectivealtruism.org/posts/9sraY9qrwuiKXJjhG/cause-exploration-prizes-publishing-comprehensive-books"
|
||||
},
|
||||
{
|
||||
"title": "Maritime capability and post-catastrophe resilience.",
|
||||
"author": "Tom Gardiner",
|
||||
"link": "https://forum.effectivealtruism.org/posts/nKDBhWFj3vwwFKwGC/maritime-capability-and-post-catastrophe-resilience-1"
|
||||
},
|
||||
{
|
||||
"title": "Shareholder activism",
|
||||
"author": "sbehmer",
|
||||
"link": "https://forum.effectivealtruism.org/posts/fqf4vgCWebTszvHm9/shareholder-activism"
|
||||
},
|
||||
{
|
||||
"title": "Water, sanitation and hygiene (“WASH”) interventions as a cause area",
|
||||
"author": "helmetedhornbill",
|
||||
"link": "https://forum.effectivealtruism.org/posts/WAbjLFkpSoA7FDvTD/water-sanitation-and-hygiene-wash-interventions-as-a-cause"
|
||||
},
|
||||
{
|
||||
"title": "Doing good is a privilege. This needs to change if we want to do good long-term. ",
|
||||
"author": "SofiaBalderson",
|
||||
"link": "https://forum.effectivealtruism.org/posts/gicYG5ymk4pPzrKAd/doing-good-is-a-privilege-this-needs-to-change-if-we-want-to"
|
||||
},
|
||||
{
|
||||
"title": "Deadline extension (to August 11) for Open Philanthropy's Cause Exploration Prizes",
|
||||
"author": "ChrisSmith",
|
||||
"link": "https://forum.effectivealtruism.org/posts/WdMbmLfb7DMMYHvKf/deadline-extension-to-august-11-for-open-philanthropy-s"
|
||||
},
|
||||
{
|
||||
"title": "Cause: Reducing Judicial Delay in India",
|
||||
"author": "Vastav Ratra",
|
||||
"link": "https://forum.effectivealtruism.org/posts/JcYyLfbnbhANCJdbv/cause-reducing-judicial-delay-in-india"
|
||||
},
|
||||
{
|
||||
"title": "Open Philanthropy Should Fund Further Cause Exploration",
|
||||
"author": "brb243",
|
||||
"link": "https://forum.effectivealtruism.org/posts/tvMjgDWptF5MNJtAo/open-philanthropy-should-fund-further-cause-exploration"
|
||||
},
|
||||
{
|
||||
"title": "Why Genetic Rescue",
|
||||
"author": "David Lang",
|
||||
"link": "https://forum.effectivealtruism.org/posts/ebBPcDxtSckRAoJfo/why-genetic-rescue"
|
||||
},
|
||||
{
|
||||
"title": "Promoting climate considerations within existing high priority areas of work",
|
||||
"author": "helmetedhornbill",
|
||||
"link": "https://forum.effectivealtruism.org/posts/pmfyGEa4NozDm2fng/promoting-climate-considerations-within-existing-high"
|
||||
}
|
||||
]
|
293
web/pages/contest/[contestSlug]/[submissionSlug].tsx
Normal file
293
web/pages/contest/[contestSlug]/[submissionSlug].tsx
Normal file
|
@ -0,0 +1,293 @@
|
|||
import React, { useEffect, useState } from 'react'
|
||||
import { ArrowLeftIcon } from '@heroicons/react/outline'
|
||||
|
||||
import { useContractWithPreload } from 'web/hooks/use-contract'
|
||||
import { ContractOverview } from 'web/components/contract/contract-overview'
|
||||
import { BetPanel } from 'web/components/bet-panel'
|
||||
import { Col } from 'web/components/layout/col'
|
||||
import { useUser } from 'web/hooks/use-user'
|
||||
import { ResolutionPanel } from 'web/components/resolution-panel'
|
||||
import { Spacer } from 'web/components/layout/spacer'
|
||||
import {
|
||||
Contract,
|
||||
getContractFromSlug,
|
||||
tradingAllowed,
|
||||
getBinaryProbPercent,
|
||||
getContractFromId,
|
||||
} from 'web/lib/firebase/contracts'
|
||||
import { SEO } from 'web/components/SEO'
|
||||
import { Page } from 'web/components/page'
|
||||
import { Bet, listAllBets } from 'web/lib/firebase/bets'
|
||||
import { Comment, listAllComments } from 'web/lib/firebase/comments'
|
||||
import Custom404 from '../../404'
|
||||
import { AnswersPanel } from 'web/components/answers/answers-panel'
|
||||
import { fromPropz, usePropz } from 'web/hooks/use-propz'
|
||||
import { ContractTabs } from 'web/components/contract/contract-tabs'
|
||||
import { contractTextDetails } from 'web/components/contract/contract-details'
|
||||
import { useWindowSize } from 'web/hooks/use-window-size'
|
||||
import Confetti from 'react-confetti'
|
||||
import { NumericBetPanel } from '../../../components/numeric-bet-panel'
|
||||
import { NumericResolutionPanel } from '../../../components/numeric-resolution-panel'
|
||||
import { useIsIframe } from 'web/hooks/use-is-iframe'
|
||||
import ContractEmbedPage from '../../embed/[username]/[contractSlug]'
|
||||
import { useBets } from 'web/hooks/use-bets'
|
||||
import { CPMMBinaryContract } from 'common/contract'
|
||||
import { AlertBox } from 'web/components/alert-box'
|
||||
import { useTracking } from 'web/hooks/use-tracking'
|
||||
import { useTipTxns } from 'web/hooks/use-tip-txns'
|
||||
import { useLiquidity } from 'web/hooks/use-liquidity'
|
||||
import { richTextToString } from 'common/util/parse'
|
||||
import { useSaveReferral } from 'web/hooks/use-save-referral'
|
||||
import {
|
||||
ContractLeaderboard,
|
||||
ContractTopTrades,
|
||||
} from 'web/components/contract/contract-leaderboard'
|
||||
|
||||
export const getStaticProps = fromPropz(getStaticPropz)
|
||||
export async function getStaticPropz(props: {
|
||||
params: { contestSlug: string; submissionSlug: string }
|
||||
}) {
|
||||
const { contestSlug, submissionSlug } = props.params
|
||||
console.log(contestSlug)
|
||||
const submission = (await getContractFromSlug(submissionSlug)) || null
|
||||
const submissionId = submission?.id
|
||||
|
||||
const [bets, comments] = await Promise.all([
|
||||
submissionId ? listAllBets(submissionId) : [],
|
||||
submissionId ? listAllComments(submissionId) : [],
|
||||
])
|
||||
|
||||
return {
|
||||
props: {
|
||||
submission,
|
||||
contestSlug,
|
||||
// Limit the data sent to the client. Client will still load all bets and comments directly.
|
||||
bets: bets.slice(0, 5000),
|
||||
comments: comments.slice(0, 1000),
|
||||
slug: submissionSlug,
|
||||
},
|
||||
|
||||
revalidate: 60, // regenerate after a minute
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStaticPaths() {
|
||||
return { paths: [], fallback: 'blocking' }
|
||||
}
|
||||
|
||||
export default function ContractPage(props: {
|
||||
submission: Contract | null
|
||||
contestSlug: string
|
||||
bets: Bet[]
|
||||
comments: Comment[]
|
||||
slug: string
|
||||
backToHome?: () => void
|
||||
}) {
|
||||
props = usePropz(props, getStaticPropz) ?? {
|
||||
submission: null,
|
||||
contestSlug: '',
|
||||
bets: [],
|
||||
comments: [],
|
||||
slug: '',
|
||||
}
|
||||
|
||||
// const inIframe = useIsIframe()
|
||||
// if (inIframe) {
|
||||
// return <ContractEmbedPage {...props} />
|
||||
// }
|
||||
|
||||
const { submission } = props
|
||||
|
||||
if (!submission) {
|
||||
return <Custom404 />
|
||||
}
|
||||
|
||||
return <SubmissionPageContent {...{ ...props, submission }} />
|
||||
}
|
||||
|
||||
export function SubmissionPageContent(
|
||||
props: Parameters<typeof ContractPage>[0] & { submission: Contract }
|
||||
) {
|
||||
const { backToHome, comments } = props
|
||||
|
||||
const contract = useContractWithPreload(props.submission) ?? props.submission
|
||||
|
||||
useTracking('view market', {
|
||||
slug: contract.slug,
|
||||
contractId: contract.id,
|
||||
creatorId: contract.creatorId,
|
||||
})
|
||||
|
||||
const bets = useBets(contract.id) ?? props.bets
|
||||
const liquidityProvisions =
|
||||
useLiquidity(contract.id)?.filter((l) => !l.isAnte && l.amount > 0) ?? []
|
||||
// Sort for now to see if bug is fixed.
|
||||
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
|
||||
|
||||
const tips = useTipTxns({ contractId: contract.id })
|
||||
|
||||
const user = useUser()
|
||||
|
||||
const { width, height } = useWindowSize()
|
||||
|
||||
const [showConfetti, setShowConfetti] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const shouldSeeConfetti = !!(
|
||||
user &&
|
||||
contract.creatorId === user.id &&
|
||||
Date.now() - contract.createdTime < 10 * 1000
|
||||
)
|
||||
setShowConfetti(shouldSeeConfetti)
|
||||
}, [contract, user])
|
||||
|
||||
const { creatorId, isResolved, question, outcomeType } = contract
|
||||
|
||||
const isCreator = user?.id === creatorId
|
||||
const isBinary = outcomeType === 'BINARY'
|
||||
const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC'
|
||||
const isNumeric = outcomeType === 'NUMERIC'
|
||||
const allowTrade = tradingAllowed(contract)
|
||||
const allowResolve = !isResolved && isCreator && !!user
|
||||
const hasSidePanel =
|
||||
(isBinary || isNumeric || isPseudoNumeric) && (allowTrade || allowResolve)
|
||||
|
||||
const ogCardProps = getOpenGraphProps(contract)
|
||||
|
||||
useSaveReferral(user, {
|
||||
defaultReferrer: contract.creatorUsername,
|
||||
contractId: contract.id,
|
||||
})
|
||||
|
||||
const rightSidebar = hasSidePanel ? (
|
||||
<Col className="gap-4">
|
||||
{allowTrade &&
|
||||
(isNumeric ? (
|
||||
<NumericBetPanel className="hidden xl:flex" contract={contract} />
|
||||
) : (
|
||||
<BetPanel
|
||||
className="hidden xl:flex"
|
||||
contract={contract as CPMMBinaryContract}
|
||||
/>
|
||||
))}
|
||||
{allowResolve &&
|
||||
(isNumeric || isPseudoNumeric ? (
|
||||
<NumericResolutionPanel creator={user} contract={contract} />
|
||||
) : (
|
||||
<ResolutionPanel creator={user} contract={contract} />
|
||||
))}
|
||||
</Col>
|
||||
) : null
|
||||
|
||||
return (
|
||||
<Page rightSidebar={rightSidebar}>
|
||||
{showConfetti && (
|
||||
<Confetti
|
||||
width={width ? width : 500}
|
||||
height={height ? height : 500}
|
||||
recycle={false}
|
||||
numberOfPieces={300}
|
||||
/>
|
||||
)}
|
||||
|
||||
{ogCardProps && (
|
||||
<SEO
|
||||
title={question}
|
||||
description={ogCardProps.description}
|
||||
url={`/${props.contestSlug}/${props.slug}`}
|
||||
ogCardProps={ogCardProps}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Col className="w-full justify-between rounded border-0 border-gray-100 bg-white py-6 pl-1 pr-2 sm:px-2 md:px-6 md:py-8">
|
||||
{backToHome && (
|
||||
<button
|
||||
className="btn btn-sm mb-4 items-center gap-2 self-start border-0 border-gray-700 bg-white normal-case text-gray-700 hover:bg-white hover:text-gray-700 lg:hidden"
|
||||
onClick={backToHome}
|
||||
>
|
||||
<ArrowLeftIcon className="h-5 w-5 text-gray-700" />
|
||||
Back
|
||||
</button>
|
||||
)}
|
||||
|
||||
<ContractOverview contract={contract} bets={bets} />
|
||||
|
||||
{isNumeric && (
|
||||
<AlertBox
|
||||
title="Warning"
|
||||
text="Distributional numeric markets were introduced as an experimental feature and are now deprecated."
|
||||
/>
|
||||
)}
|
||||
{/*
|
||||
{(outcomeType === 'FREE_RESPONSE' ||
|
||||
outcomeType === 'MULTIPLE_CHOICE') && (
|
||||
<>
|
||||
<Spacer h={4} />
|
||||
<AnswersPanel contract={contract} />
|
||||
<Spacer h={4} />
|
||||
</>
|
||||
)} */}
|
||||
|
||||
{isNumeric && allowTrade && (
|
||||
<NumericBetPanel className="xl:hidden" contract={contract} />
|
||||
)}
|
||||
|
||||
{isResolved && (
|
||||
<>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2">
|
||||
<ContractLeaderboard contract={contract} bets={bets} />
|
||||
<ContractTopTrades
|
||||
contract={contract}
|
||||
bets={bets}
|
||||
comments={comments}
|
||||
tips={tips}
|
||||
/>
|
||||
</div>
|
||||
<Spacer h={12} />
|
||||
</>
|
||||
)}
|
||||
|
||||
<ContractTabs
|
||||
contract={contract}
|
||||
user={user}
|
||||
liquidityProvisions={liquidityProvisions}
|
||||
bets={bets}
|
||||
tips={tips}
|
||||
comments={comments}
|
||||
/>
|
||||
</Col>
|
||||
</Page>
|
||||
)
|
||||
}
|
||||
|
||||
const getOpenGraphProps = (contract: Contract) => {
|
||||
const {
|
||||
resolution,
|
||||
question,
|
||||
creatorName,
|
||||
creatorUsername,
|
||||
outcomeType,
|
||||
creatorAvatarUrl,
|
||||
description: desc,
|
||||
} = contract
|
||||
const probPercent =
|
||||
outcomeType === 'BINARY' ? getBinaryProbPercent(contract) : undefined
|
||||
|
||||
const stringDesc = typeof desc === 'string' ? desc : richTextToString(desc)
|
||||
|
||||
const description = resolution
|
||||
? `Resolved ${resolution}. ${stringDesc}`
|
||||
: probPercent
|
||||
? `${probPercent} chance. ${stringDesc}`
|
||||
: stringDesc
|
||||
|
||||
return {
|
||||
question,
|
||||
probability: probPercent,
|
||||
metadata: contractTextDetails(contract),
|
||||
creatorName,
|
||||
creatorUsername,
|
||||
creatorAvatarUrl,
|
||||
description,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user