feat: pow
This commit is contained in:
parent
95f4b207d5
commit
4cc16d5e58
24 changed files with 191 additions and 67 deletions
|
|
@ -4,7 +4,8 @@ import { ScrollArea } from '@/components/ui/scroll-area'
|
|||
import {
|
||||
createCommentDraftEvent,
|
||||
createPollDraftEvent,
|
||||
createShortTextNoteDraftEvent
|
||||
createShortTextNoteDraftEvent,
|
||||
deleteDraftEventCache
|
||||
} from '@/lib/draft-event'
|
||||
import { isTouchDevice } from '@/lib/utils'
|
||||
import { useNostr } from '@/providers/NostrProvider'
|
||||
|
|
@ -56,6 +57,7 @@ export default function PostContent({
|
|||
endsAt: undefined,
|
||||
relays: []
|
||||
})
|
||||
const [minPow, setMinPow] = useState(0)
|
||||
const isFirstRender = useRef(true)
|
||||
const canPost =
|
||||
!!pubkey &&
|
||||
|
|
@ -133,10 +135,12 @@ export default function PostContent({
|
|||
|
||||
const newEvent = await publish(draftEvent, {
|
||||
specifiedRelayUrls,
|
||||
additionalRelayUrls: isPoll ? pollCreateData.relays : []
|
||||
additionalRelayUrls: isPoll ? pollCreateData.relays : [],
|
||||
minPow
|
||||
})
|
||||
addReplies([newEvent])
|
||||
postEditorCache.clearPostCache({ defaultContent, parentEvent })
|
||||
deleteDraftEventCache(draftEvent)
|
||||
addReplies([newEvent])
|
||||
close()
|
||||
} catch (error) {
|
||||
if (error instanceof AggregateError) {
|
||||
|
|
@ -311,11 +315,14 @@ export default function PostContent({
|
|||
</div>
|
||||
</div>
|
||||
<PostOptions
|
||||
posting={posting}
|
||||
show={showMoreOptions}
|
||||
addClientTag={addClientTag}
|
||||
setAddClientTag={setAddClientTag}
|
||||
isNsfw={isNsfw}
|
||||
setIsNsfw={setIsNsfw}
|
||||
minPow={minPow}
|
||||
setMinPow={setMinPow}
|
||||
/>
|
||||
<div className="flex gap-2 items-center justify-around sm:hidden">
|
||||
<Button
|
||||
|
|
|
|||
|
|
@ -1,21 +1,28 @@
|
|||
import { Label } from '@/components/ui/label'
|
||||
import { Slider } from '@/components/ui/slider'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { StorageKey } from '@/constants'
|
||||
import { Dispatch, SetStateAction, useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
export default function PostOptions({
|
||||
posting,
|
||||
show,
|
||||
addClientTag,
|
||||
setAddClientTag,
|
||||
isNsfw,
|
||||
setIsNsfw
|
||||
setIsNsfw,
|
||||
minPow,
|
||||
setMinPow
|
||||
}: {
|
||||
posting: boolean
|
||||
show: boolean
|
||||
addClientTag: boolean
|
||||
setAddClientTag: Dispatch<SetStateAction<boolean>>
|
||||
isNsfw: boolean
|
||||
setIsNsfw: Dispatch<SetStateAction<boolean>>
|
||||
minPow: number
|
||||
setMinPow: Dispatch<SetStateAction<number>>
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
|
||||
|
|
@ -43,6 +50,7 @@ export default function PostOptions({
|
|||
id="add-client-tag"
|
||||
checked={addClientTag}
|
||||
onCheckedChange={onAddClientTagChange}
|
||||
disabled={posting}
|
||||
/>
|
||||
</div>
|
||||
<div className="text-muted-foreground text-xs">
|
||||
|
|
@ -52,7 +60,24 @@ export default function PostOptions({
|
|||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Label htmlFor="add-nsfw-tag">{t('NSFW')}</Label>
|
||||
<Switch id="add-nsfw-tag" checked={isNsfw} onCheckedChange={onNsfwChange} />
|
||||
<Switch
|
||||
id="add-nsfw-tag"
|
||||
checked={isNsfw}
|
||||
onCheckedChange={onNsfwChange}
|
||||
disabled={posting}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 pb-4">
|
||||
<Label>{t('Proof of Work (difficulty {{minPow}})', { minPow })}</Label>
|
||||
<Slider
|
||||
defaultValue={[0]}
|
||||
value={[minPow]}
|
||||
onValueChange={([pow]) => setMinPow(pow)}
|
||||
max={28}
|
||||
step={1}
|
||||
disabled={posting}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue