Add about field to Fold
This commit is contained in:
parent
f571eda0e5
commit
a736b5ac1b
|
@ -2,6 +2,7 @@ export type Fold = {
|
||||||
id: string
|
id: string
|
||||||
slug: string
|
slug: string
|
||||||
name: string
|
name: string
|
||||||
|
about: string
|
||||||
curatorId: string // User id
|
curatorId: string // User id
|
||||||
createdTime: number
|
createdTime: number
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ export const createFold = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
async (
|
async (
|
||||||
data: {
|
data: {
|
||||||
name: string
|
name: string
|
||||||
|
about: string
|
||||||
tags: string[]
|
tags: string[]
|
||||||
},
|
},
|
||||||
context
|
context
|
||||||
|
@ -22,7 +23,7 @@ export const createFold = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
const creator = await getUser(userId)
|
const creator = await getUser(userId)
|
||||||
if (!creator) return { status: 'error', message: 'User not found' }
|
if (!creator) return { status: 'error', message: 'User not found' }
|
||||||
|
|
||||||
const { name, tags } = data
|
const { name, about, tags } = data
|
||||||
|
|
||||||
if (!name || typeof name !== 'string')
|
if (!name || typeof name !== 'string')
|
||||||
return { status: 'error', message: 'Name must be a non-empty 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,
|
creator.username,
|
||||||
'named',
|
'named',
|
||||||
name,
|
name,
|
||||||
'on',
|
'about',
|
||||||
|
about,
|
||||||
|
'tags',
|
||||||
tags
|
tags
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,6 +51,7 @@ export const createFold = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
curatorId: userId,
|
curatorId: userId,
|
||||||
slug,
|
slug,
|
||||||
name,
|
name,
|
||||||
|
about,
|
||||||
tags,
|
tags,
|
||||||
createdTime: Date.now(),
|
createdTime: Date.now(),
|
||||||
contractIds: [],
|
contractIds: [],
|
||||||
|
|
|
@ -12,7 +12,8 @@ import { TagsList } from './tags-list'
|
||||||
|
|
||||||
export function EditFoldButton(props: { fold: Fold }) {
|
export function EditFoldButton(props: { fold: Fold }) {
|
||||||
const { fold } = props
|
const { fold } = props
|
||||||
const [name, setName] = useState(fold?.name ?? '')
|
const [name, setName] = useState(fold.name)
|
||||||
|
const [about, setAbout] = useState(fold.about ?? '')
|
||||||
|
|
||||||
const initialOtherTags =
|
const initialOtherTags =
|
||||||
fold?.tags.filter((tag) => tag !== toCamelCase(name)).join(', ') ?? ''
|
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 tags = parseWordsAsTags(toCamelCase(name) + ' ' + otherTags)
|
||||||
|
|
||||||
const saveDisabled =
|
const saveDisabled =
|
||||||
!name || (name === fold.name && _.isEqual(tags, fold.tags))
|
name === fold.name &&
|
||||||
|
_.isEqual(tags, fold.tags) &&
|
||||||
|
about === (fold.about ?? '')
|
||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
|
|
||||||
await updateFold(fold, {
|
await updateFold(fold, {
|
||||||
name,
|
name,
|
||||||
|
about,
|
||||||
tags,
|
tags,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -66,6 +70,23 @@ export function EditFoldButton(props: { fold: Fold }) {
|
||||||
|
|
||||||
<Spacer h={4} />
|
<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">
|
<div className="form-control w-full">
|
||||||
<label className="label">
|
<label className="label">
|
||||||
<span className="mb-1">Tags</span>
|
<span className="mb-1">Tags</span>
|
||||||
|
|
|
@ -11,7 +11,7 @@ export const cloudFunction = <RequestData, ResponseData>(name: string) =>
|
||||||
export const createContract = cloudFunction('createContract')
|
export const createContract = cloudFunction('createContract')
|
||||||
|
|
||||||
export const createFold = cloudFunction<
|
export const createFold = cloudFunction<
|
||||||
{ name: string; tags: string[] },
|
{ name: string; about: string; tags: string[] },
|
||||||
{ status: 'error' | 'success'; message?: string; fold?: Fold }
|
{ status: 'error' | 'success'; message?: string; fold?: Fold }
|
||||||
>('createFold')
|
>('createFold')
|
||||||
|
|
||||||
|
|
|
@ -242,7 +242,7 @@ export default function FoldPage(props: {
|
||||||
|
|
||||||
function FoldOverview(props: { fold: Fold; curator: User }) {
|
function FoldOverview(props: { fold: Fold; curator: User }) {
|
||||||
const { fold, curator } = props
|
const { fold, curator } = props
|
||||||
const { tags } = fold
|
const { about, tags } = fold
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="max-w-sm">
|
<Col className="max-w-sm">
|
||||||
|
@ -259,10 +259,12 @@ function FoldOverview(props: { fold: Fold; curator: User }) {
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
<Spacer h={2} />
|
{about && (
|
||||||
<div className="text-gray-500">
|
<>
|
||||||
This is a community for predicting asdf asd fasdf asdf asdf .
|
<Spacer h={2} />
|
||||||
</div>
|
<div className="text-gray-500">{about}</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
<Spacer h={2} />
|
<Spacer h={2} />
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,7 @@ export default function Folds(props: {
|
||||||
|
|
||||||
function CreateFoldButton() {
|
function CreateFoldButton() {
|
||||||
const [name, setName] = useState('')
|
const [name, setName] = useState('')
|
||||||
|
const [about, setAbout] = useState('')
|
||||||
const [otherTags, setOtherTags] = useState('')
|
const [otherTags, setOtherTags] = useState('')
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
|
|
||||||
|
@ -120,6 +121,7 @@ function CreateFoldButton() {
|
||||||
const result = await createFold({
|
const result = await createFold({
|
||||||
name,
|
name,
|
||||||
tags,
|
tags,
|
||||||
|
about,
|
||||||
}).then((r) => r.data || {})
|
}).then((r) => r.data || {})
|
||||||
|
|
||||||
if (result.fold) {
|
if (result.fold) {
|
||||||
|
@ -145,7 +147,7 @@ function CreateFoldButton() {
|
||||||
}}
|
}}
|
||||||
submitBtn={{
|
submitBtn={{
|
||||||
label: 'Create',
|
label: 'Create',
|
||||||
className: clsx(name ? 'btn-primary' : 'btn-disabled'),
|
className: clsx(name && about ? 'btn-primary' : 'btn-disabled'),
|
||||||
}}
|
}}
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
>
|
>
|
||||||
|
@ -175,37 +177,50 @@ function CreateFoldButton() {
|
||||||
|
|
||||||
<Spacer h={4} />
|
<Spacer h={4} />
|
||||||
|
|
||||||
{name && (
|
<div className="form-control w-full">
|
||||||
<>
|
<label className="label">
|
||||||
<label className="label">
|
<span className="mb-1">About</span>
|
||||||
<span className="mb-1">Primary tag</span>
|
</label>
|
||||||
</label>
|
|
||||||
<TagsList noLink tags={[`#${toCamelCase(name)}`]} />
|
|
||||||
|
|
||||||
<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">
|
<Spacer h={4} />
|
||||||
<label className="label">
|
|
||||||
<span className="mb-1">Additional tags</span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<input
|
<label className="label">
|
||||||
placeholder="Politics, Economics, Rationality"
|
<span className="mb-1">Primary tag</span>
|
||||||
className="input input-bordered resize-none"
|
</label>
|
||||||
disabled={isSubmitting}
|
<TagsList noLink tags={[`#${toCamelCase(name)}`]} />
|
||||||
value={otherTags}
|
|
||||||
onChange={(e) => setOtherTags(e.target.value || '')}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Spacer h={4} />
|
<Spacer h={4} />
|
||||||
|
|
||||||
<TagsList
|
<div className="form-control w-full">
|
||||||
tags={parseWordsAsTags(otherTags).map((tag) => `#${tag}`)}
|
<label className="label">
|
||||||
noLink
|
<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>
|
</div>
|
||||||
</ConfirmationButton>
|
</ConfirmationButton>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user