From f3b7fc11b676dfda4cd134e76ed49977e1cd6a11 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Thu, 9 Dec 2021 23:11:07 -0800 Subject: [PATCH] List your markets on account page --- web/pages/account.tsx | 127 ++++++++++------------------------ web/pages/contract/index.tsx | 128 +++++++++++++++++------------------ 2 files changed, 96 insertions(+), 159 deletions(-) diff --git a/web/pages/account.tsx b/web/pages/account.tsx index 9ea3f578..cfcee79a 100644 --- a/web/pages/account.tsx +++ b/web/pages/account.tsx @@ -2,112 +2,53 @@ import { useRouter } from 'next/router' import { firebaseLogout } from '../lib/firebase/users' import { Header } from '../components/header' import { useUser } from '../hooks/use-user' +import { useState, useEffect } from 'react' +import { Contract, listContracts } from '../lib/firebase/contracts' +import { ContractList } from './contract' export default function Account() { const user = useUser() const router = useRouter() + const [contracts, setContracts] = useState([]) + useEffect(() => { + if (user?.id) { + listContracts(user?.id).then(setContracts) + } + }, [user?.id]) return (
-
-
-
- -
-
-

{user?.name}

-

{user?.email}

-

${user?.balanceUsd} USD

-
- + {/*
*/} +
+
+
+
+ +
+
+

{user?.name}

+

{user?.email}

+

${user?.balanceUsd} USD

+
+ +
- {/* Lorem ipsum table. TODO: fill in user's bets and markets */} -

- {user?.username}'s Bets +

+ Your markets

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameJobcompanylocationLast LoginFavorite Color
1Cy GandertonQuality Control SpecialistLittel, Schaden and VandervortCanada12/16/2020Blue
2Hart HagertyDesktop Support TechnicianZemlak, Daniel and LeannonUnited States12/5/2020Purple
3Brice SwyreTax AccountantCarroll GroupChina8/15/2020Red
4Marjy FerenczOffice Assistant IRowe-SchoenRussia3/25/2021Crimson
5Yancy TearCommunity Outreach SpecialistWyman-LednerBrazil5/22/2020Indigo
6Irma VasilikEditorWiza, Bins and EmardVenezuela12/8/2020Purple
-
+
) diff --git a/web/pages/contract/index.tsx b/web/pages/contract/index.tsx index 9be4bc55..7df43346 100644 --- a/web/pages/contract/index.tsx +++ b/web/pages/contract/index.tsx @@ -1,4 +1,4 @@ -import { FieldValue, serverTimestamp } from '@firebase/firestore' +import Link from 'next/link' import { useEffect, useState } from 'react' import { Header } from '../../components/header' import { useUser } from '../../hooks/use-user' @@ -13,67 +13,67 @@ function ContractCard(props: { contract: Contract }) { const { contract } = props return (
  • - -
  • ) } +export function ContractList(props: { contracts: Contract[] }) { + const { contracts } = props + return ( +
    +
      + {contracts.map((contract) => ( + + ))} +
    +
    + ) +} + // Allow user to create a new contract export default function NewContract() { const creator = useUser() const [contract, setContract] = useState({ - // creatorId: creator?.id || '', // TODO: Set create time to Firestore timestamp createdTime: Date.now(), lastUpdatedTime: Date.now(), @@ -103,14 +103,11 @@ export default function NewContract() { return (
    -
    -
    -
    -

    - Create a new contract -

    -
    - +
    +

    + Create a new prediction market +

    +
    {/* Create a Tailwind form that takes in all the fields needed for a new contract */} {/* When the form is submitted, create a new contract in the database */}
    @@ -152,6 +149,7 @@ export default function NewContract() { >
    + {/* TODO: Save seeds */}
    @@ -190,13 +188,11 @@ export default function NewContract() {
    {/* Show a separate card for each contract */} -
    -
      - {contracts.map((contract) => ( - - ))} -
    -
    +

    + Your markets +

    + +
    )