Folds query on lowercase tags. Adding to description updates tags & lowercaseTags fields.

This commit is contained in:
jahooma 2022-01-25 17:52:21 -06:00
parent 8b0091f30d
commit 2ea05f8913
4 changed files with 17 additions and 4 deletions

View File

@ -22,7 +22,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()
.hasOnly(['description']);
.hasOnly(['description', 'tags', 'lowercaseTags']);
allow delete: if resource.data.creatorId == request.auth.uid;
}

View File

@ -38,6 +38,7 @@ import { JoinSpans } from './join-spans'
import Textarea from 'react-expanding-textarea'
import { outcome } from '../../common/contract'
import { fromNow } from '../lib/util/time'
import { parseTags } from '../../common/util/parse'
export function AvatarWithIcon(props: { username: string; avatarUrl: string }) {
const { username, avatarUrl } = props
@ -170,7 +171,13 @@ export function ContractDescription(props: {
setEditing(false)
const newDescription = `${contract.description}\n\n${description}`.trim()
await updateContract(contract.id, { description: newDescription })
const tags = parseTags(`${contract.tags.join(' ')} ${newDescription}`)
const lowercaseTags = tags.map((tag) => tag.toLowerCase())
await updateContract(contract.id, {
description: newDescription,
tags,
lowercaseTags,
})
setDescription(editStatement())
}

View File

@ -45,7 +45,14 @@ export async function getFoldContracts(fold: Fold) {
// TODO: if tags.length > 10, execute multiple parallel queries
tags.length > 0
? getValues<Contract>(
query(contractCollection, where('tags', 'array-contains-any', tags))
query(
contractCollection,
where(
'lowercaseTags',
'array-contains-any',
tags.map((tag) => tag.toLowerCase())
)
)
)
: [],

View File

@ -120,7 +120,6 @@ export default function FoldPage(props: {
topTraderScores: number[]
topCreators: User[]
topCreatorScores: number[]
params: { tab: string }
}) {
const {
curator,