From c115b5cca7e2cccc4f040d8f13df48e530d70efc Mon Sep 17 00:00:00 2001 From: ingawei <46611122+ingawei@users.noreply.github.com> Date: Tue, 4 Oct 2022 17:36:03 -0500 Subject: [PATCH] Inga/multiple colors (#994) * making FR bars smoller --- web/components/answers/answers-panel.tsx | 95 +++++++++++++---------- web/components/button.tsx | 3 + web/components/charts/contract/choice.tsx | 16 ++-- web/components/yes-no-selector.tsx | 2 +- web/tailwind.config.js | 1 + 5 files changed, 72 insertions(+), 45 deletions(-) diff --git a/web/components/answers/answers-panel.tsx b/web/components/answers/answers-panel.tsx index a1cef4c3..08b1373f 100644 --- a/web/components/answers/answers-panel.tsx +++ b/web/components/answers/answers-panel.tsx @@ -20,11 +20,11 @@ import { AnswerBetPanel } from 'web/components/answers/answer-bet-panel' import { Row } from 'web/components/layout/row' import { Avatar } from 'web/components/avatar' import { Linkify } from 'web/components/linkify' -import { BuyButton } from 'web/components/yes-no-selector' -import { UserLink } from 'web/components/user-link' import { Button } from 'web/components/button' import { useAdmin } from 'web/hooks/use-admin' import { needsAdminToResolve } from 'web/pages/[username]/[contractSlug]' +import { CATEGORY_COLORS } from '../charts/contract/choice' +import { useChartAnswers } from '../charts/contract/choice' export function AnswersPanel(props: { contract: FreeResponseContract | MultipleChoiceContract @@ -38,6 +38,7 @@ export function AnswersPanel(props: { const answers = (useAnswers(contract.id) ?? contract.answers).filter( (a) => a.number != 0 || contract.outcomeType === 'MULTIPLE_CHOICE' ) + const hasZeroBetAnswers = answers.some((answer) => totalBets[answer.id] < 1) const [winningAnswers, losingAnswers] = partition( @@ -104,6 +105,10 @@ export function AnswersPanel(props: { ? 'checkbox' : undefined + const colorSortedAnswer = useChartAnswers(contract).map( + (value, _index) => value.text + ) + return ( {(resolveOption || resolution) && @@ -128,7 +133,12 @@ export function AnswersPanel(props: { )} > {answerItems.map((item) => ( - + ))} {hasZeroBetAnswers && !showAllAnswers && ( + )} + + +
+ ) } diff --git a/web/components/button.tsx b/web/components/button.tsx index 90e087c8..57c0bb4b 100644 --- a/web/components/button.tsx +++ b/web/components/button.tsx @@ -10,6 +10,7 @@ export type ColorType = | 'indigo' | 'yellow' | 'gray' + | 'gray-outline' | 'gradient' | 'gray-white' | 'highlight-blue' @@ -63,6 +64,8 @@ export function Button(props: { 'disabled:bg-greyscale-2 bg-indigo-500 text-white hover:bg-indigo-600', color === 'gray' && 'bg-greyscale-1 text-greyscale-6 hover:bg-greyscale-2 disabled:opacity-50', + color === 'gray-outline' && + 'border-greyscale-4 text-greyscale-4 hover:bg-greyscale-4 border-2 hover:text-white disabled:opacity-50', color === 'gradient' && 'disabled:bg-greyscale-2 border-none bg-gradient-to-r from-indigo-500 to-blue-500 text-white hover:from-indigo-700 hover:to-blue-700', color === 'gray-white' && diff --git a/web/components/charts/contract/choice.tsx b/web/components/charts/contract/choice.tsx index a6e46a5d..470bba3e 100644 --- a/web/components/charts/contract/choice.tsx +++ b/web/components/charts/contract/choice.tsx @@ -20,7 +20,7 @@ import { Row } from 'web/components/layout/row' import { Avatar } from 'web/components/avatar' // thanks to https://observablehq.com/@jonhelfman/optimal-orders-for-choosing-categorical-colors -const CATEGORY_COLORS = [ +export const CATEGORY_COLORS = [ '#00b8dd', '#eecafe', '#874c62', @@ -144,6 +144,15 @@ const Legend = (props: { className?: string; items: LegendItem[] }) => { ) } +export function useChartAnswers( + contract: FreeResponseContract | MultipleChoiceContract +) { + return useMemo( + () => getTrackedAnswers(contract, CATEGORY_COLORS.length), + [contract] + ) +} + export const ChoiceContractChart = (props: { contract: FreeResponseContract | MultipleChoiceContract bets: Bet[] @@ -153,10 +162,7 @@ export const ChoiceContractChart = (props: { }) => { const { contract, bets, width, height, onMouseOver } = props const [start, end] = getDateRange(contract) - const answers = useMemo( - () => getTrackedAnswers(contract, CATEGORY_COLORS.length), - [contract] - ) + const answers = useChartAnswers(contract) const betPoints = useMemo(() => getBetPoints(answers, bets), [answers, bets]) const data = useMemo( () => [ diff --git a/web/components/yes-no-selector.tsx b/web/components/yes-no-selector.tsx index 10a58a42..69bf47f0 100644 --- a/web/components/yes-no-selector.tsx +++ b/web/components/yes-no-selector.tsx @@ -244,7 +244,7 @@ function Button(props: { type="button" className={clsx( 'inline-flex flex-1 items-center justify-center rounded-md border border-transparent px-8 py-3 font-medium shadow-sm', - color === 'green' && 'bg-teal-500 bg-teal-600 text-white', + color === 'green' && 'bg-teal-500 text-white hover:bg-teal-600', color === 'red' && 'bg-red-400 text-white hover:bg-red-500', color === 'yellow' && 'bg-yellow-400 text-white hover:bg-yellow-500', color === 'blue' && 'bg-blue-400 text-white hover:bg-blue-500', diff --git a/web/tailwind.config.js b/web/tailwind.config.js index ef7220ec..0390038f 100644 --- a/web/tailwind.config.js +++ b/web/tailwind.config.js @@ -18,6 +18,7 @@ module.exports = { colors: { 'red-25': '#FDF7F6', 'greyscale-1': '#FBFBFF', + 'greyscale-1.5': '#F4F4FB', 'greyscale-2': '#E7E7F4', 'greyscale-3': '#D8D8EB', 'greyscale-4': '#B1B1C7',