stacker.news/components/adv-post-form.js

84 lines
2.9 KiB
JavaScript
Raw Normal View History

2021-09-11 21:52:19 +00:00
import AccordianItem from './accordian-item'
import * as Yup from 'yup'
2022-08-26 22:20:09 +00:00
import { Input, InputUserSuggest } from './form'
2021-09-11 21:52:19 +00:00
import { InputGroup } from 'react-bootstrap'
2022-03-09 19:44:50 +00:00
import { BOOST_MIN } from '../lib/constants'
2022-04-19 18:32:39 +00:00
import { NAME_QUERY } from '../fragments/users'
2022-07-24 00:00:57 +00:00
import Info from './info'
2021-09-11 21:52:19 +00:00
2022-04-19 18:32:39 +00:00
export function AdvPostSchema (client) {
return {
boost: Yup.number().typeError('must be a number')
2022-08-18 18:15:24 +00:00
.min(BOOST_MIN, `must be blank or at least ${BOOST_MIN}`).integer('must be whole').test({
name: 'boost',
test: async boost => {
if (!boost || boost % BOOST_MIN === 0) return true
return false
},
message: `must be divisble be ${BOOST_MIN}`
}),
2022-04-19 18:32:39 +00:00
forward: Yup.string()
.test({
name: 'name',
test: async name => {
if (!name || !name.length) return true
const { data } = await client.query({ query: NAME_QUERY, variables: { name }, fetchPolicy: 'network-only' })
return !data.nameAvailable
},
message: 'user does not exist'
})
}
2021-09-11 21:52:19 +00:00
}
2022-08-18 18:15:24 +00:00
export function AdvPostInitial ({ forward }) {
return {
boost: '',
forward: forward || ''
}
2021-09-11 21:52:19 +00:00
}
2022-08-18 18:15:24 +00:00
export default function AdvPostForm ({ edit }) {
2021-09-11 21:52:19 +00:00
return (
<AccordianItem
2021-09-12 16:55:38 +00:00
header={<div style={{ fontWeight: 'bold', fontSize: '92%' }}>options</div>}
2021-09-11 21:52:19 +00:00
body={
2022-04-18 20:19:07 +00:00
<>
<Input
2022-07-24 00:00:57 +00:00
label={
2022-08-18 18:15:24 +00:00
<div className='d-flex align-items-center'>{edit ? 'add boost' : 'boost'}
2022-07-24 00:00:57 +00:00
<Info>
<ol className='font-weight-bold'>
<li>Boost ranks posts higher temporarily based on the amount</li>
<li>The minimum boost is {BOOST_MIN} sats</li>
<li>Each {BOOST_MIN} sats of boost is equivalent to one trusted upvote
<ul>
<li>e.g. {BOOST_MIN * 2} sats is like 2 votes</li>
</ul>
</li>
<li>The decay of boost "votes" increases at 2x the rate of organic votes
<ul>
<li>i.e. boost votes fall out of ranking faster</li>
</ul>
</li>
<li>100% of sats from boost are given back to top users as rewards</li>
</ol>
</Info>
</div>
}
2022-04-18 20:19:07 +00:00
name='boost'
hint={<span className='text-muted'>ranks posts higher temporarily based on the amount</span>}
append={<InputGroup.Text className='text-monospace'>sats</InputGroup.Text>}
/>
2022-08-26 22:20:09 +00:00
<InputUserSuggest
2022-04-25 17:07:31 +00:00
label={<>forward sats to</>}
2022-04-18 20:19:07 +00:00
name='forward'
2022-04-19 18:32:39 +00:00
hint={<span className='text-muted'>100% of sats will be sent to this user</span>}
2022-04-18 20:19:07 +00:00
prepend=<InputGroup.Text>@</InputGroup.Text>
2022-04-19 18:32:39 +00:00
showValid
2022-04-18 20:19:07 +00:00
/>
</>
2021-09-11 21:52:19 +00:00
}
/>
)
}