From f92f333ec768c21638df0bc04b88210fc25975d1 Mon Sep 17 00:00:00 2001 From: austinkelsay Date: Sun, 18 Feb 2024 16:28:09 -0600 Subject: [PATCH] determine item type from router.query.type if available otherwise use item fields --- components/adv-post-form.js | 29 +++++++++++++++++++++++++++-- components/bounty-form.js | 2 +- components/discussion-form.js | 2 +- components/link-form.js | 2 +- components/poll-form.js | 2 +- components/use-crossposter.js | 4 ++-- 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/components/adv-post-form.js b/components/adv-post-form.js index 7a5af9497..09414a52e 100644 --- a/components/adv-post-form.js +++ b/components/adv-post-form.js @@ -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' @@ -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) { diff --git a/components/bounty-form.js b/components/bounty-form.js index 548e50d4b..46f80a11d 100644 --- a/components/bounty-form.js +++ b/components/bounty-form.js @@ -143,7 +143,7 @@ export function BountyForm ({ : null } /> - + ) diff --git a/components/discussion-form.js b/components/discussion-form.js index 7086f7e9f..0860b60e7 100644 --- a/components/discussion-form.js +++ b/components/discussion-form.js @@ -123,7 +123,7 @@ export function DiscussionForm ({ ?
: null} /> - + {!item &&
0 ? '' : 'invisible'}`}> diff --git a/components/link-form.js b/components/link-form.js index fe133efbd..5873527d3 100644 --- a/components/link-form.js +++ b/components/link-form.js @@ -194,7 +194,7 @@ export function LinkForm ({ item, sub, editThreshold, children }) { } }} /> - + - + ) diff --git a/components/use-crossposter.js b/components/use-crossposter.js index bc25d1686..d689ff830 100644 --- a/components/use-crossposter.js +++ b/components/use-crossposter.js @@ -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 }