From 98552c853c001de8e5ccfe8a17ff8f8aa39676f6 Mon Sep 17 00:00:00 2001 From: keyan Date: Tue, 25 Jul 2023 15:29:45 -0500 Subject: [PATCH] fix back button behavior on select navigation --- components/fee-button.js | 2 - components/header.js | 23 ++++----- components/job-form.js | 7 ++- components/recent-header.js | 31 ++++++------ components/search.js | 22 ++++---- components/sub-select-form.js | 5 +- components/top-header.js | 13 +++-- components/usage-header.js | 32 ++++++------ components/user-list.js | 4 +- lib/md.js | 2 - pages/[name]/[type].js | 19 ++++--- pages/referrals/[when].js | 32 ++++++------ pages/stackers/[when].js | 95 ++++++++++++++++++----------------- 13 files changed, 142 insertions(+), 145 deletions(-) diff --git a/components/fee-button.js b/components/fee-button.js index a224760f..6b47f25b 100644 --- a/components/fee-button.js +++ b/components/fee-button.js @@ -49,8 +49,6 @@ export default function FeeButton ({ parentId, hasImgLink, baseFee, ChildButton, const boost = Number(formik?.values?.boost) || 0 const cost = baseFee * (hasImgLink ? 10 : 1) * Math.pow(10, repetition) + Number(boost) - console.log('cost', cost, 'baseFee', baseFee, repetition, hasImgLink, boost) - const show = alwaysShow || !formik?.isSubmitting return (
diff --git a/components/header.js b/components/header.js index 4506137f..f168121e 100644 --- a/components/header.js +++ b/components/header.js @@ -17,7 +17,7 @@ import NoteIcon from '../svgs/notification-4-fill.svg' import { useQuery } from '@apollo/client' import LightningIcon from '../svgs/bolt.svg' import CowboyHat from './cowboy-hat' -import { Form, Select } from './form' +import { Select } from './form' import SearchIcon from '../svgs/search-line.svg' import BackArrow from '../svgs/arrow-left-line.svg' import { SUBS } from '../lib/constants' @@ -181,18 +181,15 @@ function NavItems ({ className, sub, prefix }) { return ( <> -
- router.push(e.target.value === 'home' ? '/' : `/~${e.target.value}`)} + name='sub' + size='sm' + value={sub} + noForm + items={['home', ...SUBS]} + /> diff --git a/components/job-form.js b/components/job-form.js index 9dff9e15..2246878a 100644 --- a/components/job-form.js +++ b/components/job-form.js @@ -144,7 +144,7 @@ export default function JobForm ({ item, sub }) { required clear /> - + {item && }
{item @@ -165,7 +165,7 @@ export default function JobForm ({ item, sub }) { ) } -function PromoteJob ({ item, sub, storageKeyPrefix }) { +function PromoteJob ({ item, sub }) { const [monthly, setMonthly] = useState(satsMin2Mo(item?.maxBid || 0)) const [getAuctionPosition, { data }] = useLazyQuery(gql` query AuctionPosition($id: ID, $bid: Int!) { @@ -175,7 +175,7 @@ function PromoteJob ({ item, sub, storageKeyPrefix }) { const position = data?.auctionPosition useEffect(() => { - const initialMaxBid = Number(item?.maxBid || window.localStorage.getItem(storageKeyPrefix + '-maxBid')) || 0 + const initialMaxBid = Number(item?.maxBid) || 0 getAuctionPosition({ variables: { id: item?.id, bid: initialMaxBid } }) setMonthly(satsMin2Mo(initialMaxBid)) }, []) @@ -211,7 +211,6 @@ function PromoteJob ({ item, sub, storageKeyPrefix }) { }} append={sats/min} hint={} - storageKeyPrefix={storageKeyPrefix} /> <>
This bid puts your job in position: {position}
diff --git a/components/recent-header.js b/components/recent-header.js index de7098fe..045f7c1e 100644 --- a/components/recent-header.js +++ b/components/recent-header.js @@ -1,5 +1,5 @@ import { ITEM_TYPES } from '../lib/constants' -import { Form, Select } from './form' +import { Select } from './form' import { useRouter } from 'next/router' export default function RecentHeader ({ type, sub }) { @@ -8,22 +8,19 @@ export default function RecentHeader ({ type, sub }) { const items = ITEM_TYPES(sub) + type ||= router.query.type || type || 'posts' return ( - -
- router.push(prefix + (e.target.value === 'posts' ? '/recent' : `/recent/${e.target.value}`))} + /> +
) } diff --git a/components/search.js b/components/search.js index 593c1122..ccdbb6de 100644 --- a/components/search.js +++ b/components/search.js @@ -42,9 +42,9 @@ export default function Search ({ sub }) { return } - if (values.what === '') delete values.what - if (values.sort === '') delete values.sort - if (values.when === '') delete values.when + if (values.what === '' || values.what === 'all') delete values.what + if (values.sort === '' || values.sort === 'match') delete values.sort + if (values.when === '' || values.when === 'forever') delete values.when await router.push({ pathname: prefix + '/search', query: values @@ -54,7 +54,10 @@ export default function Search ({ sub }) { const showSearch = atBottom || searching || router.query.q const filter = sub !== 'jobs' - const what = router.pathname.startsWith('/stackers') ? 'stackers' : router.query.what + const what = router.pathname.startsWith('/stackers') ? 'stackers' : router.query.what || 'all' + const sort = router.query.sort || 'match' + const when = router.query.when || 'forever' + return ( <>
@@ -63,12 +66,7 @@ export default function Search ({ sub }) { ? ( {filter && @@ -78,6 +76,7 @@ export default function Search ({ sub }) { onChange={(formik, e) => search({ ...formik?.values, what: e.target.value })} name='what' size='sm' + overrideValue={what} items={['all', 'posts', 'comments', 'stackers']} /> {what !== 'stackers' && @@ -88,6 +87,7 @@ export default function Search ({ sub }) { onChange={(formik, e) => search({ ...formik?.values, sort: e.target.value })} name='sort' size='sm' + overrideValue={sort} items={['match', 'recent', 'comments', 'sats', 'votes']} /> for @@ -96,6 +96,7 @@ export default function Search ({ sub }) { onChange={(formik, e) => search({ ...formik?.values, when: e.target.value })} name='when' size='sm' + overrideValue={when} items={['forever', 'day', 'week', 'month', 'year']} /> @@ -109,6 +110,7 @@ export default function Search ({ sub }) { groupClassName='me-3 mb-0 flex-grow-1' className='flex-grow-1' clear + overrideValue={q} onChange={async (formik, e) => { setSearching(true) setQ(e.target.value?.trim()) diff --git a/components/sub-select-form.js b/components/sub-select-form.js index 5e05992a..166e1c95 100644 --- a/components/sub-select-form.js +++ b/components/sub-select-form.js @@ -30,6 +30,9 @@ export default function SubSelect ({ label, sub, setSub, item, ...props }) { ) + sub ||= router.query.sub + const extraProps = props.noForm ? { value: sub } : { overrideValue: sub } + return ( router.push(`/stackers/${e.target.value}`)} - /> -
- +
+ stacker analytics for + router.push(`/referrals/${e.target.value}`)} - /> - - +

+ {totalReferrals} referrals & {totalSats} sats in the last +