Add about field to Fold

This commit is contained in:
jahooma 2022-01-25 14:16:32 -06:00
parent f571eda0e5
commit a736b5ac1b
6 changed files with 80 additions and 37 deletions

View File

@ -2,6 +2,7 @@ export type Fold = {
id: string
slug: string
name: string
about: string
curatorId: string // User id
createdTime: number

View File

@ -12,6 +12,7 @@ export const createFold = functions.runWith({ minInstances: 1 }).https.onCall(
async (
data: {
name: string
about: string
tags: string[]
},
context
@ -22,7 +23,7 @@ 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, tags } = data
const { name, about, tags } = data
if (!name || typeof name !== 'string')
return { status: 'error', message: 'Name must be a non-empty string' }
@ -35,7 +36,9 @@ export const createFold = functions.runWith({ minInstances: 1 }).https.onCall(
creator.username,
'named',
name,
'on',
'about',
about,
'tags',
tags
)
@ -48,6 +51,7 @@ export const createFold = functions.runWith({ minInstances: 1 }).https.onCall(
curatorId: userId,
slug,
name,
about,
tags,
createdTime: Date.now(),
contractIds: [],

View File

@ -12,7 +12,8 @@ import { TagsList } from './tags-list'
export function EditFoldButton(props: { fold: Fold }) {
const { fold } = props
const [name, setName] = useState(fold?.name ?? '')
const [name, setName] = useState(fold.name)
const [about, setAbout] = useState(fold.about ?? '')
const initialOtherTags =
fold?.tags.filter((tag) => tag !== toCamelCase(name)).join(', ') ?? ''
@ -23,13 +24,16 @@ export function EditFoldButton(props: { fold: Fold }) {
const tags = parseWordsAsTags(toCamelCase(name) + ' ' + otherTags)
const saveDisabled =
!name || (name === fold.name && _.isEqual(tags, fold.tags))
name === fold.name &&
_.isEqual(tags, fold.tags) &&
about === (fold.about ?? '')
const onSubmit = async () => {
setIsSubmitting(true)
await updateFold(fold, {
name,
about,
tags,
})
@ -66,6 +70,23 @@ export function EditFoldButton(props: { fold: Fold }) {
<Spacer h={4} />
<div className="form-control w-full">
<label className="label">
<span className="mb-1">About</span>
</label>
<input
placeholder="Short description (140 characters max)"
className="input input-bordered resize-none"
disabled={isSubmitting}
value={about}
maxLength={140}
onChange={(e) => setAbout(e.target.value || '')}
/>
</div>
<Spacer h={4} />
<div className="form-control w-full">
<label className="label">
<span className="mb-1">Tags</span>

View File

@ -11,7 +11,7 @@ export const cloudFunction = <RequestData, ResponseData>(name: string) =>
export const createContract = cloudFunction('createContract')
export const createFold = cloudFunction<
{ name: string; tags: string[] },
{ name: string; about: string; tags: string[] },
{ status: 'error' | 'success'; message?: string; fold?: Fold }
>('createFold')

View File

@ -242,7 +242,7 @@ export default function FoldPage(props: {
function FoldOverview(props: { fold: Fold; curator: User }) {
const { fold, curator } = props
const { tags } = fold
const { about, tags } = fold
return (
<Col className="max-w-sm">
@ -259,10 +259,12 @@ function FoldOverview(props: { fold: Fold; curator: User }) {
/>
</Row>
<Spacer h={2} />
<div className="text-gray-500">
This is a community for predicting asdf asd fasdf asdf asdf .
</div>
{about && (
<>
<Spacer h={2} />
<div className="text-gray-500">{about}</div>
</>
)}
<Spacer h={2} />

View File

@ -103,6 +103,7 @@ export default function Folds(props: {
function CreateFoldButton() {
const [name, setName] = useState('')
const [about, setAbout] = useState('')
const [otherTags, setOtherTags] = useState('')
const [isSubmitting, setIsSubmitting] = useState(false)
@ -120,6 +121,7 @@ function CreateFoldButton() {
const result = await createFold({
name,
tags,
about,
}).then((r) => r.data || {})
if (result.fold) {
@ -145,7 +147,7 @@ function CreateFoldButton() {
}}
submitBtn={{
label: 'Create',
className: clsx(name ? 'btn-primary' : 'btn-disabled'),
className: clsx(name && about ? 'btn-primary' : 'btn-disabled'),
}}
onSubmit={onSubmit}
>
@ -175,37 +177,50 @@ function CreateFoldButton() {
<Spacer h={4} />
{name && (
<>
<label className="label">
<span className="mb-1">Primary tag</span>
</label>
<TagsList noLink tags={[`#${toCamelCase(name)}`]} />
<div className="form-control w-full">
<label className="label">
<span className="mb-1">About</span>
</label>
<Spacer h={4} />
<input
placeholder="Short description (140 characters max)"
className="input input-bordered resize-none"
disabled={isSubmitting}
value={about}
maxLength={140}
onChange={(e) => setAbout(e.target.value || '')}
/>
</div>
<div className="form-control w-full">
<label className="label">
<span className="mb-1">Additional tags</span>
</label>
<Spacer h={4} />
<input
placeholder="Politics, Economics, Rationality"
className="input input-bordered resize-none"
disabled={isSubmitting}
value={otherTags}
onChange={(e) => setOtherTags(e.target.value || '')}
/>
</div>
<label className="label">
<span className="mb-1">Primary tag</span>
</label>
<TagsList noLink tags={[`#${toCamelCase(name)}`]} />
<Spacer h={4} />
<Spacer h={4} />
<TagsList
tags={parseWordsAsTags(otherTags).map((tag) => `#${tag}`)}
noLink
/>
</>
)}
<div className="form-control w-full">
<label className="label">
<span className="mb-1">Additional tags</span>
</label>
<input
placeholder="Politics, Economics, Rationality (Optional)"
className="input input-bordered resize-none"
disabled={isSubmitting}
value={otherTags}
onChange={(e) => setOtherTags(e.target.value || '')}
/>
</div>
<Spacer h={4} />
<TagsList
tags={parseWordsAsTags(otherTags).map((tag) => `#${tag}`)}
noLink
/>
</div>
</ConfirmationButton>
)