From 5beda1ded724f7ad1a8d95ea022cf4930ca33b21 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Sun, 12 Jun 2022 20:55:48 -0700 Subject: [PATCH] Revert "Turn on no unused variables linting, kill dead code (#484)" This reverts commit 515928a69a660d5c795ebbb8a1675205304086b1. --- web/.eslintrc.js | 9 +- web/components/answers/answers-panel.tsx | 2 +- web/components/bets-list.tsx | 8 +- web/components/charity/charity-card.tsx | 2 +- web/components/choices-toggle-group.tsx | 3 +- web/components/confirmation-button.tsx | 4 +- web/components/contract/quick-bet.tsx | 8 +- web/components/feed-create.tsx | 99 ++++++++++++++++++- .../feed/feed-answer-comment-group.tsx | 2 +- web/components/feed/feed-items.tsx | 28 ++++++ web/components/folds/create-fold-button.tsx | 1 + web/components/liquidity-panel.tsx | 8 +- web/components/nav/profile-menu.tsx | 3 +- web/components/nav/sidebar.tsx | 5 + web/components/numeric-bet-panel.tsx | 1 + web/components/page.tsx | 3 +- web/hooks/use-fold.ts | 37 +++++++ web/lib/firebase/notifications.ts | 2 +- web/pages/activity.tsx | 2 +- web/pages/api/v0/market/[id].ts | 1 - web/pages/api/v0/slug/[slug].ts | 1 - web/pages/create.tsx | 6 +- web/pages/fold/[...slugs]/index.tsx | 11 +++ web/pages/home.tsx | 2 +- web/pages/index.tsx | 2 +- web/pages/landing-page.tsx | 24 ++++- web/pages/leaderboards.tsx | 4 +- web/pages/make-predictions.tsx | 10 ++ web/pages/notifications.tsx | 6 +- web/pages/stats.tsx | 1 + 30 files changed, 252 insertions(+), 43 deletions(-) diff --git a/web/.eslintrc.js b/web/.eslintrc.js index 2f3ac31a..6c34b521 100644 --- a/web/.eslintrc.js +++ b/web/.eslintrc.js @@ -8,15 +8,8 @@ module.exports = { ], rules: { '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-unused-vars': 'off', '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-unused-vars': [ - 'error', - { - argsIgnorePattern: '^_', - varsIgnorePattern: '^_', - caughtErrorsIgnorePattern: '^_', - }, - ], '@next/next/no-img-element': 'off', '@next/next/no-typos': 'off', 'lodash/import-scope': [2, 'member'], diff --git a/web/components/answers/answers-panel.tsx b/web/components/answers/answers-panel.tsx index eb992fe4..c711abe8 100644 --- a/web/components/answers/answers-panel.tsx +++ b/web/components/answers/answers-panel.tsx @@ -116,7 +116,7 @@ export function AnswersPanel(props: { contract: FreeResponseContract }) { {!resolveOption && (
- {answerItems.map((item) => ( + {answerItems.map((item, activityItemIdx) => (
diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index d227ac88..a4e90c35 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -138,8 +138,9 @@ export function BetsList(props: { user: User; hideBetsBefore?: number }) { return !hasSoldAll }) - const unsettled = contracts.filter( - (c) => !c.isResolved && contractsMetrics[c.id].invested !== 0 + const [settled, unsettled] = partition( + contracts, + (c) => c.isResolved || contractsMetrics[c.id].invested === 0 ) const currentInvested = sumBy( @@ -260,7 +261,7 @@ function ContractBets(props: { const isBinary = outcomeType === 'BINARY' - const { payout, profit, profitPercent } = getContractBetMetrics( + const { payout, profit, profitPercent, invested } = getContractBetMetrics( contract, bets ) @@ -656,6 +657,7 @@ function SellButton(props: { contract: Contract; bet: Bet }) { return ( txn.amount) diff --git a/web/components/choices-toggle-group.tsx b/web/components/choices-toggle-group.tsx index 61c4e4fd..f974d72f 100644 --- a/web/components/choices-toggle-group.tsx +++ b/web/components/choices-toggle-group.tsx @@ -24,12 +24,13 @@ export function ChoicesToggleGroup(props: { null} > {Object.keys(choicesMap).map((choiceKey) => ( setChoice(choicesMap[choiceKey])} className={({ active }) => clsx( active ? 'ring-2 ring-indigo-500 ring-offset-2' : '', diff --git a/web/components/confirmation-button.tsx b/web/components/confirmation-button.tsx index 57a7bafe..e895467a 100644 --- a/web/components/confirmation-button.tsx +++ b/web/components/confirmation-button.tsx @@ -5,6 +5,7 @@ import { Modal } from './layout/modal' import { Row } from './layout/row' export function ConfirmationButton(props: { + id: string openModalBtn: { label: string icon?: JSX.Element @@ -21,7 +22,7 @@ export function ConfirmationButton(props: { onSubmit: () => void children: ReactNode }) { - const { openModalBtn, cancelBtn, submitBtn, onSubmit, children } = props + const { id, openModalBtn, cancelBtn, submitBtn, onSubmit, children } = props const [open, setOpen] = useState(false) @@ -66,6 +67,7 @@ export function ResolveConfirmationButton(props: { props return ( @@ -257,7 +257,7 @@ function QuickOutcomeView(props: { // If there's a preview prob, display that instead of the current prob const override = previewProb === undefined ? undefined : formatPercent(previewProb) - const textColor = `text-${getColor(contract)}` + const textColor = `text-${getColor(contract, previewProb)}` let display: string | undefined switch (outcomeType) { @@ -306,7 +306,7 @@ function getNumericScale(contract: NumericContract) { return (ev - min) / (max - min) } -export function getColor(contract: Contract) { +export function getColor(contract: Contract, previewProb?: number) { // TODO: Try injecting a gradient here // return 'primary' const { resolution } = contract diff --git a/web/components/feed-create.tsx b/web/components/feed-create.tsx index 0a9b77e3..98b56d69 100644 --- a/web/components/feed-create.tsx +++ b/web/components/feed-create.tsx @@ -1,10 +1,16 @@ -import { SparklesIcon } from '@heroicons/react/solid' +import { sample } from 'lodash' +import { SparklesIcon, XIcon } from '@heroicons/react/solid' +import { Avatar } from './avatar' +import { useEffect, useRef, useState } from 'react' import { Spacer } from './layout/spacer' -import { firebaseLogin } from 'web/lib/firebase/users' +import { NewContract } from '../pages/create' +import { firebaseLogin, User } from 'web/lib/firebase/users' import { ContractsGrid } from './contract/contracts-list' -import { Contract } from 'common/contract' +import { Contract, MAX_QUESTION_LENGTH } from 'common/contract' import { Col } from './layout/col' +import clsx from 'clsx' import { Row } from './layout/row' +import { ENV_CONFIG } from '../../common/envs/constants' import { SiteLink } from './site-link' import { formatMoney } from 'common/util/format' @@ -61,3 +67,90 @@ export function FeedPromo(props: { hotContracts: Contract[] }) { ) } + +export default function FeedCreate(props: { + user?: User + tag?: string + placeholder?: string + className?: string +}) { + const { user, tag, className } = props + const [question, setQuestion] = useState('') + const [isExpanded, setIsExpanded] = useState(false) + const inputRef = useRef() + + // Rotate through a new placeholder each day + // Easter egg idea: click your own name to shuffle the placeholder + // const daysSinceEpoch = Math.floor(Date.now() / 1000 / 60 / 60 / 24) + + // Take care not to produce a different placeholder on the server and client + const [defaultPlaceholder, setDefaultPlaceholder] = useState('') + useEffect(() => { + setDefaultPlaceholder(`e.g. ${sample(ENV_CONFIG.newQuestionPlaceholders)}`) + }, []) + + const placeholder = props.placeholder ?? defaultPlaceholder + + return ( +
{ + !isExpanded && inputRef.current?.focus() + }} + > +
+ + +
+ +

Ask a question...

+ {isExpanded && ( + + )} +
+