From 6f41ab8efd4536b527f9c84dbf89c96f838f97f6 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Wed, 5 Oct 2022 10:38:19 -0400 Subject: [PATCH 1/2] Keep unlisted state on duplicate --- .../contract/contract-info-dialog.tsx | 2 +- ...utton.tsx => duplicate-contract-button.tsx} | 1 + web/pages/create.tsx | 18 ++++++++---------- 3 files changed, 10 insertions(+), 11 deletions(-) rename web/components/{copy-contract-button.tsx => duplicate-contract-button.tsx} (98%) diff --git a/web/components/contract/contract-info-dialog.tsx b/web/components/contract/contract-info-dialog.tsx index bc1384b3..6cb0c7ed 100644 --- a/web/components/contract/contract-info-dialog.tsx +++ b/web/components/contract/contract-info-dialog.tsx @@ -17,7 +17,7 @@ import { SiteLink } from '../site-link' import { firestoreConsolePath } from 'common/envs/constants' import { deleteField } from 'firebase/firestore' import ShortToggle from '../widgets/short-toggle' -import { DuplicateContractButton } from '../copy-contract-button' +import { DuplicateContractButton } from '../duplicate-contract-button' import { Row } from '../layout/row' import { BETTORS, User } from 'common/user' import { Button } from '../button' diff --git a/web/components/copy-contract-button.tsx b/web/components/duplicate-contract-button.tsx similarity index 98% rename from web/components/copy-contract-button.tsx rename to web/components/duplicate-contract-button.tsx index 07e519e1..c02a2a9c 100644 --- a/web/components/copy-contract-button.tsx +++ b/web/components/duplicate-contract-button.tsx @@ -40,6 +40,7 @@ function duplicateContractHref(contract: Contract) { closeTime, description: descriptionString, outcomeType: contract.outcomeType, + visibility: contract.visibility, } as Record if (contract.outcomeType === 'PSEUDO_NUMERIC') { diff --git a/web/pages/create.tsx b/web/pages/create.tsx index e7c2a1b8..e23ebf75 100644 --- a/web/pages/create.tsx +++ b/web/pages/create.tsx @@ -38,6 +38,7 @@ import { ExternalLinkIcon } from '@heroicons/react/outline' import { SiteLink } from 'web/components/site-link' import { Button } from 'web/components/button' import { AddFundsModal } from 'web/components/add-funds-modal' +import ShortToggle from 'web/components/widgets/short-toggle' export const getServerSideProps = redirectIfLoggedOut('/', async (_, creds) => { return { props: { auth: await getUserAndPrivateUser(creds.uid) } } @@ -50,6 +51,7 @@ type NewQuestionParams = { description: string closeTime: string outcomeType: string + visibility: string // Params for PSEUDO_NUMERIC outcomeType min?: string max?: string @@ -136,7 +138,9 @@ export function NewContract(props: { const [maxString, setMaxString] = useState(params?.max ?? '') const [isLogScale, setIsLogScale] = useState(!!params?.isLogScale) const [initialValueString, setInitialValueString] = useState(initValue) - + const [visibility, setVisibility] = useState( + (params?.visibility as visibility) ?? 'public' + ) // for multiple choice, init to 3 empty answers const [answers, setAnswers] = useState(['', '', '']) @@ -168,7 +172,6 @@ export function NewContract(props: { undefined ) const [showGroupSelector, setShowGroupSelector] = useState(true) - const [visibility, setVisibility] = useState('public') const [fundsModalOpen, setFundsModalOpen] = useState(false) @@ -414,14 +417,9 @@ export function NewContract(props: { Display this market on homepage - - setVisibility(e.target.checked ? 'public' : 'unlisted') - } + setVisibility(on ? 'public' : 'unlisted')} /> From 730abf584a715800705b92ce38c2860977eaf6a1 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Wed, 5 Oct 2022 10:54:04 -0400 Subject: [PATCH 2/2] Revert "Warn whenever rich text editor has unsaved changes" This reverts commit 419219c7030824abf57de1b86f7c43537a65493a. --- web/components/editor.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/web/components/editor.tsx b/web/components/editor.tsx index 5b075039..27e8ac45 100644 --- a/web/components/editor.tsx +++ b/web/components/editor.tsx @@ -42,7 +42,6 @@ import ItalicIcon from 'web/lib/icons/italic-icon' import LinkIcon from 'web/lib/icons/link-icon' import { getUrl } from 'common/util/parse' import { TiptapSpoiler } from 'common/util/tiptap-spoiler' -import { useWarnUnsavedChanges } from 'web/hooks/use-warn-unsaved-changes' const DisplayImage = Image.configure({ HTMLAttributes: { @@ -151,9 +150,6 @@ export function useTextEditor(props: { editor?.setEditable(!disabled) }, [editor, disabled]) - const isEditorFilled = editor != null && !editor.isEmpty - useWarnUnsavedChanges(isEditorFilled) - return { editor, upload } }