Skip to content

Commit

Permalink
determine item type from router.query.type if available otherwise use…
Browse files Browse the repository at this point in the history
… item fields
  • Loading branch information
AustinKelsay committed Feb 18, 2024
1 parent 0c71cb2 commit f92f333
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
29 changes: 27 additions & 2 deletions components/adv-post-form.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState, useEffect } from 'react'
import AccordianItem from './accordian-item'
import { Input, InputUserSuggest, VariableInput, Checkbox } from './form'
import InputGroup from 'react-bootstrap/InputGroup'
Expand All @@ -19,12 +20,36 @@ export function AdvPostInitial ({ forward, boost }) {
}
}

export default function AdvPostForm ({ children }) {
export default function AdvPostForm ({ children, item }) {
const me = useMe()
const { merge } = useFeeButton()
const router = useRouter()
const [itemType, setItemType] = useState()

const itemType = router.query.type
useEffect(() => {
const determineItemType = () => {
if (router && router.query.type) {
return router.query.type
} else if (item) {
const typeMap = {
url: 'link',
bounty: 'bounty',
pollCost: 'poll'
}

for (const [key, type] of Object.entries(typeMap)) {
if (item[key]) {
return type
}
}

return 'discussion'
}
}

const type = determineItemType()
setItemType(type)
}, [item, router])

function renderCrosspostDetails (itemType) {
switch (itemType) {
Expand Down
2 changes: 1 addition & 1 deletion components/bounty-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function BountyForm ({
: null
}
/>
<AdvPostForm edit={!!item} />
<AdvPostForm edit={!!item} item={item} />
<ItemButtonBar itemId={item?.id} canDelete={false} />
</Form>
)
Expand Down
2 changes: 1 addition & 1 deletion components/discussion-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function DiscussionForm ({
? <div className='text-muted fw-bold'><Countdown date={editThreshold} /></div>
: null}
/>
<AdvPostForm edit={!!item} />
<AdvPostForm edit={!!item} item={item} />
<ItemButtonBar itemId={item?.id} />
{!item &&
<div className={`mt-3 ${related.length > 0 ? '' : 'invisible'}`}>
Expand Down
2 changes: 1 addition & 1 deletion components/link-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export function LinkForm ({ item, sub, editThreshold, children }) {
}
}}
/>
<AdvPostForm edit={!!item}>
<AdvPostForm edit={!!item} item={item}>
<MarkdownInput
label='context'
name='text'
Expand Down
2 changes: 1 addition & 1 deletion components/poll-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function PollForm ({ item, sub, editThreshold, children }) {
: null}
maxLength={MAX_POLL_CHOICE_LENGTH}
/>
<AdvPostForm edit={!!item} />
<AdvPostForm edit={!!item} item={item} />
<ItemButtonBar itemId={item?.id} />
</Form>
)
Expand Down
4 changes: 2 additions & 2 deletions components/use-crossposter.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ export default function useCrossposter () {
}
} catch (error) {
await crosspostError(error.message)
failedRelays = []
failedRelays = []

// wait 2 seconds to show error then break
await new Promise(resolve => setTimeout(resolve, 2000))
return { allSuccessful, noteId }
Expand Down

0 comments on commit f92f333

Please sign in to comment.