From 33c8fe2bc0fafc6502ad43708d097f86b4d180da Mon Sep 17 00:00:00 2001 From: jahooma Date: Wed, 26 Jan 2022 17:45:05 -0600 Subject: [PATCH] Append tags from market page --- firestore.rules | 2 +- web/components/contract-card.tsx | 7 ----- web/components/contract-overview.tsx | 8 +++-- web/components/tags-input.tsx | 45 ++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 web/components/tags-input.tsx diff --git a/firestore.rules b/firestore.rules index d96546d9..18572047 100644 --- a/firestore.rules +++ b/firestore.rules @@ -21,7 +21,7 @@ service cloud.firestore { match /contracts/{contractId} { allow read; - allow update: if resource.data.creatorId == request.auth.uid && request.resource.data.diff(resource.data).affectedKeys() + allow update: if request.resource.data.diff(resource.data).affectedKeys() .hasOnly(['description', 'tags', 'lowercaseTags']); allow delete: if resource.data.creatorId == request.auth.uid; } diff --git a/web/components/contract-card.tsx b/web/components/contract-card.tsx index 9ac088a0..c1390cac 100644 --- a/web/components/contract-card.tsx +++ b/web/components/contract-card.tsx @@ -194,13 +194,6 @@ export function ContractDetails(props: { contract: Contract }) {
{formatMoney(truePool)} pool
- - {tags.length > 0 && ( - <> -
- - - )} ) } diff --git a/web/components/contract-overview.tsx b/web/components/contract-overview.tsx index 4c82594d..1a089617 100644 --- a/web/components/contract-overview.tsx +++ b/web/components/contract-overview.tsx @@ -17,6 +17,7 @@ import { ContractFeed } from './contract-feed' import { TweetButton } from './tweet-button' import { Bet } from '../../common/bet' import { Comment } from '../../common/comment' +import { TagsInput } from './tags-input' export const ContractOverview = (props: { contract: Contract @@ -58,7 +59,6 @@ export const ContractOverview = (props: { /> - @@ -68,7 +68,6 @@ export const ContractOverview = (props: { probPercent={probPercent} large /> - @@ -76,6 +75,11 @@ export const ContractOverview = (props: { + + + + + {/* Show a delete button for contracts without any trading */} diff --git a/web/components/tags-input.tsx b/web/components/tags-input.tsx new file mode 100644 index 00000000..5da8283b --- /dev/null +++ b/web/components/tags-input.tsx @@ -0,0 +1,45 @@ +import { useState } from 'react' +import { parseWordsAsTags } from '../../common/util/parse' +import { Contract, updateContract } from '../lib/firebase/contracts' +import { Row } from './layout/row' +import { TagsList } from './tags-list' + +export function TagsInput(props: { contract: Contract }) { + const { contract } = props + const { tags } = contract + + const [tagText, setTagText] = useState('') + const newTags = parseWordsAsTags(`${tags.join(' ')} ${tagText}`) + + const [isSubmitting, setIsSubmitting] = useState(false) + + const updateTags = () => { + setIsSubmitting(true) + updateContract(contract.id, { + tags: newTags, + lowercaseTags: newTags.map((tag) => tag.toLowerCase()), + }) + setIsSubmitting(false) + setTagText('') + } + + return ( + + `#${tag}`)} /> + + + setTagText(e.target.value || '')} + /> + + + + ) +}