Adjust market modal styles (#875)
* Refactor add market modals into one component * Adjust style: stickier search, scroll auto
This commit is contained in:
parent
df3d7b591d
commit
74335f2b01
|
@ -200,7 +200,7 @@ export function ContractSearch(props: {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="h-full">
|
<Col>
|
||||||
<ContractSearchControls
|
<ContractSearchControls
|
||||||
className={headerClassName}
|
className={headerClassName}
|
||||||
defaultSort={defaultSort}
|
defaultSort={defaultSort}
|
||||||
|
|
102
web/components/contract-select-modal.tsx
Normal file
102
web/components/contract-select-modal.tsx
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
import { Contract } from 'common/contract'
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { Button } from './button'
|
||||||
|
import { ContractSearch } from './contract-search'
|
||||||
|
import { Col } from './layout/col'
|
||||||
|
import { Modal } from './layout/modal'
|
||||||
|
import { Row } from './layout/row'
|
||||||
|
import { LoadingIndicator } from './loading-indicator'
|
||||||
|
|
||||||
|
export function SelectMarketsModal(props: {
|
||||||
|
title: string
|
||||||
|
description?: React.ReactNode
|
||||||
|
open: boolean
|
||||||
|
setOpen: (open: boolean) => void
|
||||||
|
submitLabel: (length: number) => string
|
||||||
|
onSubmit: (contracts: Contract[]) => void | Promise<void>
|
||||||
|
contractSearchOptions?: Partial<Parameters<typeof ContractSearch>[0]>
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
open,
|
||||||
|
setOpen,
|
||||||
|
submitLabel,
|
||||||
|
onSubmit,
|
||||||
|
contractSearchOptions,
|
||||||
|
} = props
|
||||||
|
|
||||||
|
const [contracts, setContracts] = useState<Contract[]>([])
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
async function addContract(contract: Contract) {
|
||||||
|
if (contracts.map((c) => c.id).includes(contract.id)) {
|
||||||
|
setContracts(contracts.filter((c) => c.id !== contract.id))
|
||||||
|
} else setContracts([...contracts, contract])
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onFinish() {
|
||||||
|
setLoading(true)
|
||||||
|
await onSubmit(contracts)
|
||||||
|
setLoading(false)
|
||||||
|
setOpen(false)
|
||||||
|
setContracts([])
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal open={open} setOpen={setOpen} className={'sm:p-0'} size={'lg'}>
|
||||||
|
<Col className="h-[85vh] w-full gap-4 rounded-md bg-white">
|
||||||
|
<div className="p-8 pb-0">
|
||||||
|
<Row>
|
||||||
|
<div className={'text-xl text-indigo-700'}>{title}</div>
|
||||||
|
|
||||||
|
{!loading && (
|
||||||
|
<Row className="grow justify-end gap-4">
|
||||||
|
{contracts.length > 0 && (
|
||||||
|
<Button onClick={onFinish} color="indigo">
|
||||||
|
{submitLabel(contracts.length)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
if (contracts.length > 0) {
|
||||||
|
setContracts([])
|
||||||
|
} else {
|
||||||
|
setOpen(false)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
color="gray"
|
||||||
|
>
|
||||||
|
{contracts.length > 0 ? 'Reset' : 'Cancel'}
|
||||||
|
</Button>
|
||||||
|
</Row>
|
||||||
|
)}
|
||||||
|
</Row>
|
||||||
|
{description}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{loading && (
|
||||||
|
<div className="w-full justify-center">
|
||||||
|
<LoadingIndicator />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="overflow-y-auto sm:px-8">
|
||||||
|
<ContractSearch
|
||||||
|
hideOrderSelector
|
||||||
|
onContractClick={addContract}
|
||||||
|
cardHideOptions={{ hideGroupLink: true, hideQuickBet: true }}
|
||||||
|
highlightOptions={{
|
||||||
|
contractIds: contracts.map((c) => c.id),
|
||||||
|
highlightClassName:
|
||||||
|
'!bg-indigo-100 outline outline-2 outline-indigo-300',
|
||||||
|
}}
|
||||||
|
additionalFilter={{}} /* hide pills */
|
||||||
|
headerClassName="bg-white"
|
||||||
|
{...contractSearchOptions}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Col>
|
||||||
|
</Modal>
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,12 +1,6 @@
|
||||||
import { Editor } from '@tiptap/react'
|
import { Editor } from '@tiptap/react'
|
||||||
import { Contract } from 'common/contract'
|
import { Contract } from 'common/contract'
|
||||||
import { useState } from 'react'
|
import { SelectMarketsModal } from '../contract-select-modal'
|
||||||
import { Button } from '../button'
|
|
||||||
import { ContractSearch } from '../contract-search'
|
|
||||||
import { Col } from '../layout/col'
|
|
||||||
import { Modal } from '../layout/modal'
|
|
||||||
import { Row } from '../layout/row'
|
|
||||||
import { LoadingIndicator } from '../loading-indicator'
|
|
||||||
import { embedContractCode, embedContractGridCode } from '../share-embed-button'
|
import { embedContractCode, embedContractGridCode } from '../share-embed-button'
|
||||||
import { insertContent } from './utils'
|
import { insertContent } from './utils'
|
||||||
|
|
||||||
|
@ -17,83 +11,23 @@ export function MarketModal(props: {
|
||||||
}) {
|
}) {
|
||||||
const { editor, open, setOpen } = props
|
const { editor, open, setOpen } = props
|
||||||
|
|
||||||
const [contracts, setContracts] = useState<Contract[]>([])
|
function onSubmit(contracts: Contract[]) {
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
|
|
||||||
async function addContract(contract: Contract) {
|
|
||||||
if (contracts.map((c) => c.id).includes(contract.id)) {
|
|
||||||
setContracts(contracts.filter((c) => c.id !== contract.id))
|
|
||||||
} else setContracts([...contracts, contract])
|
|
||||||
}
|
|
||||||
|
|
||||||
async function doneAddingContracts() {
|
|
||||||
setLoading(true)
|
|
||||||
if (contracts.length == 1) {
|
if (contracts.length == 1) {
|
||||||
insertContent(editor, embedContractCode(contracts[0]))
|
insertContent(editor, embedContractCode(contracts[0]))
|
||||||
} else if (contracts.length > 1) {
|
} else if (contracts.length > 1) {
|
||||||
insertContent(editor, embedContractGridCode(contracts))
|
insertContent(editor, embedContractGridCode(contracts))
|
||||||
}
|
}
|
||||||
setLoading(false)
|
|
||||||
setOpen(false)
|
|
||||||
setContracts([])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={open} setOpen={setOpen} className={'sm:p-0'} size={'lg'}>
|
<SelectMarketsModal
|
||||||
<Col className="h-[85vh] w-full gap-4 rounded-md bg-white">
|
title="Embed markets"
|
||||||
<Row className="p-8 pb-0">
|
open={open}
|
||||||
<div className={'text-xl text-indigo-700'}>Embed a market</div>
|
setOpen={setOpen}
|
||||||
|
submitLabel={(len) =>
|
||||||
{!loading && (
|
len == 1 ? 'Embed 1 question' : `Embed grid of ${len} questions`
|
||||||
<Row className="grow justify-end gap-4">
|
}
|
||||||
{contracts.length == 1 && (
|
onSubmit={onSubmit}
|
||||||
<Button onClick={doneAddingContracts} color={'indigo'}>
|
/>
|
||||||
Embed 1 question
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{contracts.length > 1 && (
|
|
||||||
<Button onClick={doneAddingContracts} color={'indigo'}>
|
|
||||||
Embed grid of {contracts.length} question
|
|
||||||
{contracts.length > 1 && 's'}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
if (contracts.length > 0) {
|
|
||||||
setContracts([])
|
|
||||||
} else {
|
|
||||||
setOpen(false)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
color="gray"
|
|
||||||
>
|
|
||||||
{contracts.length > 0 ? 'Reset' : 'Cancel'}
|
|
||||||
</Button>
|
|
||||||
</Row>
|
|
||||||
)}
|
|
||||||
</Row>
|
|
||||||
|
|
||||||
{loading && (
|
|
||||||
<div className="w-full justify-center">
|
|
||||||
<LoadingIndicator />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="overflow-y-scroll sm:px-8">
|
|
||||||
<ContractSearch
|
|
||||||
hideOrderSelector
|
|
||||||
onContractClick={addContract}
|
|
||||||
cardHideOptions={{ hideGroupLink: true, hideQuickBet: true }}
|
|
||||||
highlightOptions={{
|
|
||||||
contractIds: contracts.map((c) => c.id),
|
|
||||||
highlightClassName:
|
|
||||||
'!bg-indigo-100 outline outline-2 outline-indigo-300',
|
|
||||||
}}
|
|
||||||
additionalFilter={{}} /* hide pills */
|
|
||||||
headerClassName="bg-white"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Col>
|
|
||||||
</Modal>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,6 @@ import { SEO } from 'web/components/SEO'
|
||||||
import { Linkify } from 'web/components/linkify'
|
import { Linkify } from 'web/components/linkify'
|
||||||
import { fromPropz, usePropz } from 'web/hooks/use-propz'
|
import { fromPropz, usePropz } from 'web/hooks/use-propz'
|
||||||
import { Tabs } from 'web/components/layout/tabs'
|
import { Tabs } from 'web/components/layout/tabs'
|
||||||
import { LoadingIndicator } from 'web/components/loading-indicator'
|
|
||||||
import { Modal } from 'web/components/layout/modal'
|
|
||||||
import { ChoicesToggleGroup } from 'web/components/choices-toggle-group'
|
import { ChoicesToggleGroup } from 'web/components/choices-toggle-group'
|
||||||
import { ContractSearch } from 'web/components/contract-search'
|
import { ContractSearch } from 'web/components/contract-search'
|
||||||
import { JoinOrLeaveGroupButton } from 'web/components/groups/groups-button'
|
import { JoinOrLeaveGroupButton } from 'web/components/groups/groups-button'
|
||||||
|
@ -51,6 +49,7 @@ import { Spacer } from 'web/components/layout/spacer'
|
||||||
import { usePost } from 'web/hooks/use-post'
|
import { usePost } from 'web/hooks/use-post'
|
||||||
import { useAdmin } from 'web/hooks/use-admin'
|
import { useAdmin } from 'web/hooks/use-admin'
|
||||||
import { track } from '@amplitude/analytics-browser'
|
import { track } from '@amplitude/analytics-browser'
|
||||||
|
import { SelectMarketsModal } from 'web/components/contract-select-modal'
|
||||||
|
|
||||||
export const getStaticProps = fromPropz(getStaticPropz)
|
export const getStaticProps = fromPropz(getStaticPropz)
|
||||||
export async function getStaticPropz(props: { params: { slugs: string[] } }) {
|
export async function getStaticPropz(props: { params: { slugs: string[] } }) {
|
||||||
|
@ -401,27 +400,12 @@ function GroupLeaderboard(props: {
|
||||||
function AddContractButton(props: { group: Group; user: User }) {
|
function AddContractButton(props: { group: Group; user: User }) {
|
||||||
const { group, user } = props
|
const { group, user } = props
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [contracts, setContracts] = useState<Contract[]>([])
|
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
const groupContractIds = useGroupContractIds(group.id)
|
const groupContractIds = useGroupContractIds(group.id)
|
||||||
|
|
||||||
async function addContractToCurrentGroup(contract: Contract) {
|
async function onSubmit(contracts: Contract[]) {
|
||||||
if (contracts.map((c) => c.id).includes(contract.id)) {
|
await Promise.all(
|
||||||
setContracts(contracts.filter((c) => c.id !== contract.id))
|
contracts.map((contract) => addContractToGroup(group, contract, user.id))
|
||||||
} else setContracts([...contracts, contract])
|
)
|
||||||
}
|
|
||||||
|
|
||||||
async function doneAddingContracts() {
|
|
||||||
Promise.all(
|
|
||||||
contracts.map(async (contract) => {
|
|
||||||
setLoading(true)
|
|
||||||
await addContractToGroup(group, contract, user.id)
|
|
||||||
})
|
|
||||||
).then(() => {
|
|
||||||
setLoading(false)
|
|
||||||
setOpen(false)
|
|
||||||
setContracts([])
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -437,71 +421,27 @@ function AddContractButton(props: { group: Group; user: User }) {
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Modal
|
<SelectMarketsModal
|
||||||
open={open}
|
open={open}
|
||||||
setOpen={setOpen}
|
setOpen={setOpen}
|
||||||
className={'max-w-4xl sm:p-0'}
|
title="Add markets"
|
||||||
size={'xl'}
|
description={
|
||||||
>
|
<div className={'text-md my-4 text-gray-600'}>
|
||||||
<Col
|
Add pre-existing markets to this group, or{' '}
|
||||||
className={'min-h-screen w-full max-w-4xl gap-4 rounded-md bg-white'}
|
<Link href={`/create?groupId=${group.id}`}>
|
||||||
>
|
<span className="cursor-pointer font-semibold underline">
|
||||||
<Col className="p-8 pb-0">
|
create a new one
|
||||||
<div className={'text-xl text-indigo-700'}>Add markets</div>
|
</span>
|
||||||
|
</Link>
|
||||||
<div className={'text-md my-4 text-gray-600'}>
|
.
|
||||||
Add pre-existing markets to this group, or{' '}
|
|
||||||
<Link href={`/create?groupId=${group.id}`}>
|
|
||||||
<span className="cursor-pointer font-semibold underline">
|
|
||||||
create a new one
|
|
||||||
</span>
|
|
||||||
</Link>
|
|
||||||
.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{contracts.length > 0 && (
|
|
||||||
<Col className={'w-full '}>
|
|
||||||
{!loading ? (
|
|
||||||
<Row className={'justify-end gap-4'}>
|
|
||||||
<Button onClick={doneAddingContracts} color={'indigo'}>
|
|
||||||
Add {contracts.length} question
|
|
||||||
{contracts.length > 1 && 's'}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
setContracts([])
|
|
||||||
}}
|
|
||||||
color={'gray'}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
</Row>
|
|
||||||
) : (
|
|
||||||
<Row className={'justify-center'}>
|
|
||||||
<LoadingIndicator />
|
|
||||||
</Row>
|
|
||||||
)}
|
|
||||||
</Col>
|
|
||||||
)}
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<div className={'overflow-y-scroll sm:px-8'}>
|
|
||||||
<ContractSearch
|
|
||||||
user={user}
|
|
||||||
hideOrderSelector={true}
|
|
||||||
onContractClick={addContractToCurrentGroup}
|
|
||||||
cardHideOptions={{ hideGroupLink: true, hideQuickBet: true }}
|
|
||||||
additionalFilter={{
|
|
||||||
excludeContractIds: groupContractIds,
|
|
||||||
}}
|
|
||||||
highlightOptions={{
|
|
||||||
contractIds: contracts.map((c) => c.id),
|
|
||||||
highlightClassName: '!bg-indigo-100 border-indigo-100 border-2',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
}
|
||||||
</Modal>
|
submitLabel={(len) => `Add ${len} question${len !== 1 ? 's' : ''}`}
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
contractSearchOptions={{
|
||||||
|
additionalFilter: { excludeContractIds: groupContractIds },
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user