diff --git a/firestore.rules b/firestore.rules
index 7d24cf66..894367a6 100644
--- a/firestore.rules
+++ b/firestore.rules
@@ -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;
}
diff --git a/functions/src/backup-db.ts b/functions/src/backup-db.ts
index db2df27d..cc5c531d 100644
--- a/functions/src/backup-db.ts
+++ b/functions/src/backup-db.ts
@@ -1,5 +1,20 @@
-// Export script from https://firebase.google.com/docs/firestore/solutions/schedule-export
-// To import the data into dev Firestore: https://firebase.google.com/docs/firestore/manage-data/move-data
+// This code is copied from https://firebase.google.com/docs/firestore/solutions/schedule-export
+//
+// To deploy after any changes:
+// `yarn deploy`
+//
+// To manually run a backup: Click "Run Now" on the backupDb script
+// https://console.cloud.google.com/cloudscheduler?project=mantic-markets
+//
+// Backups are here:
+// https://console.cloud.google.com/storage/browser/manifold-firestore-backup
+//
+// To import the data into dev Firestore (from https://firebase.google.com/docs/firestore/manage-data/move-data):
+// 0. Open up a cloud shell from manticmarkets@gmail.com: https://console.cloud.google.com/home/dashboard?cloudshell=true
+// 1. `gcloud config set project dev-mantic-markets`
+// 2. Get the backup timestamp e.g. `2022-01-25T21:19:20_6605`
+// 3. `gcloud firestore import gs://manifold-firestore-backup/2022-01-25T21:19:20_6605 --async`
+// 4. (Optional) `gcloud firestore operations list` to check progress
import * as functions from 'firebase-functions'
import * as firestore from '@google-cloud/firestore'
@@ -20,12 +35,15 @@ export const backupDb = functions.pubsub
// Leave collectionIds empty to export all collections
// or set to a list of collection IDs to export,
// collectionIds: ['users', 'posts']
+ // NOTE: Subcollections are not backed up by default
collectionIds: [
'contracts',
'folds',
'private-users',
'stripe-transactions',
'users',
+ 'bets',
+ 'comments',
],
})
.then((responses) => {
diff --git a/functions/src/create-fold.ts b/functions/src/create-fold.ts
index a653fa93..368a6b03 100644
--- a/functions/src/create-fold.ts
+++ b/functions/src/create-fold.ts
@@ -23,11 +23,16 @@ export const createFold = functions.runWith({ minInstances: 1 }).https.onCall(
const creator = await getUser(userId)
if (!creator) return { status: 'error', message: 'User not found' }
- const { name, about, tags } = data
+ let { name, about, tags } = data
if (!name || typeof name !== 'string')
return { status: 'error', message: 'Name must be a non-empty string' }
+ if (!about || typeof about !== 'string')
+ return { status: 'error', message: 'About must be a non-empty string' }
+
+ about = about.slice(0, 140)
+
if (!_.isArray(tags))
return { status: 'error', message: 'Tags must be an array of strings' }
diff --git a/web/components/contract-feed.tsx b/web/components/contract-feed.tsx
index 10580695..ae518cce 100644
--- a/web/components/contract-feed.tsx
+++ b/web/components/contract-feed.tsx
@@ -41,6 +41,7 @@ import { outcome } from '../../common/contract'
import { fromNow } from '../lib/util/time'
import BetRow from './bet-row'
import clsx from 'clsx'
+import { parseTags } from '../../common/util/parse'
export function AvatarWithIcon(props: { username: string; avatarUrl: string }) {
const { username, avatarUrl } = props
@@ -173,7 +174,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())
}
diff --git a/web/components/create-fold-button.tsx b/web/components/create-fold-button.tsx
new file mode 100644
index 00000000..ac9913c5
--- /dev/null
+++ b/web/components/create-fold-button.tsx
@@ -0,0 +1,137 @@
+import clsx from 'clsx'
+import { useRouter } from 'next/router'
+import { useState } from 'react'
+import { parseWordsAsTags } from '../../common/util/parse'
+import { createFold } from '../lib/firebase/api-call'
+import { foldPath } from '../lib/firebase/folds'
+import { toCamelCase } from '../lib/util/format'
+import { ConfirmationButton } from './confirmation-button'
+import { Col } from './layout/col'
+import { Spacer } from './layout/spacer'
+import { TagsList } from './tags-list'
+import { Title } from './title'
+
+export function CreateFoldButton() {
+ const [name, setName] = useState('')
+ const [about, setAbout] = useState('')
+ const [otherTags, setOtherTags] = useState('')
+ const [isSubmitting, setIsSubmitting] = useState(false)
+
+ const router = useRouter()
+
+ const tags = parseWordsAsTags(toCamelCase(name) + ' ' + otherTags)
+
+ const updateName = (newName: string) => {
+ setName(newName)
+ }
+
+ const onSubmit = async () => {
+ setIsSubmitting(true)
+
+ const result = await createFold({
+ name,
+ tags,
+ about,
+ }).then((r) => r.data || {})
+
+ if (result.fold) {
+ await router.push(foldPath(result.fold)).catch((e) => {
+ console.log(e)
+ setIsSubmitting(false)
+ })
+ } else {
+ console.log(result.status, result.message)
+ setIsSubmitting(false)
+ }
+ }
+
+ return (
+