feat: 💨
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { createReactionDraftEvent } from '@/lib/draft-event'
|
import { createReactionDraftEvent } from '@/lib/draft-event'
|
||||||
|
import { isProtectedEvent } from '@/lib/event'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { useNostr } from '@/providers/NostrProvider'
|
import { useNostr } from '@/providers/NostrProvider'
|
||||||
import { useNoteStats } from '@/providers/NoteStatsProvider'
|
import { useNoteStats } from '@/providers/NoteStatsProvider'
|
||||||
@@ -54,7 +55,13 @@ export default function LikeButton({
|
|||||||
|
|
||||||
const targetRelayList = await client.fetchRelayList(event.pubkey)
|
const targetRelayList = await client.fetchRelayList(event.pubkey)
|
||||||
const reaction = createReactionDraftEvent(event)
|
const reaction = createReactionDraftEvent(event)
|
||||||
await publish(reaction, { additionalRelayUrls: targetRelayList.read.slice(0, 3) })
|
const isProtected = isProtectedEvent(event)
|
||||||
|
if (isProtected) {
|
||||||
|
const seenOn = client.getSeenEventRelayUrls(event.id)
|
||||||
|
await publish(reaction, { specifiedRelayUrls: seenOn })
|
||||||
|
} else {
|
||||||
|
await publish(reaction, { additionalRelayUrls: targetRelayList.read.slice(0, 3) })
|
||||||
|
}
|
||||||
markNoteAsLiked(event.id)
|
markNoteAsLiked(event.id)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('like failed', error)
|
console.error('like failed', error)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import TextareaWithMentions from '../TextareaWithMentions.tsx'
|
|||||||
import Mentions from './Mentions'
|
import Mentions from './Mentions'
|
||||||
import PostOptions from './PostOptions.tsx'
|
import PostOptions from './PostOptions.tsx'
|
||||||
import Preview from './Preview'
|
import Preview from './Preview'
|
||||||
|
import SendOnlyToSwitch from './SendOnlyToSwitch.tsx'
|
||||||
import { TPostOptions } from './types.ts'
|
import { TPostOptions } from './types.ts'
|
||||||
import Uploader from './Uploader'
|
import Uploader from './Uploader'
|
||||||
|
|
||||||
@@ -110,6 +111,11 @@ export default function NormalPostContent({
|
|||||||
placeholder={t('Write something...')}
|
placeholder={t('Write something...')}
|
||||||
/>
|
/>
|
||||||
{content && <Preview content={content} />}
|
{content && <Preview content={content} />}
|
||||||
|
<SendOnlyToSwitch
|
||||||
|
parentEvent={parentEvent}
|
||||||
|
postOptions={postOptions}
|
||||||
|
setPostOptions={setPostOptions}
|
||||||
|
/>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div className="flex gap-2 items-center">
|
<div className="flex gap-2 items-center">
|
||||||
<Uploader
|
<Uploader
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import Image from '../Image'
|
|||||||
import TextareaWithMentions from '../TextareaWithMentions.tsx'
|
import TextareaWithMentions from '../TextareaWithMentions.tsx'
|
||||||
import Mentions from './Mentions'
|
import Mentions from './Mentions'
|
||||||
import PostOptions from './PostOptions.tsx'
|
import PostOptions from './PostOptions.tsx'
|
||||||
|
import SendOnlyToSwitch from './SendOnlyToSwitch.tsx'
|
||||||
import { TPostOptions } from './types.ts'
|
import { TPostOptions } from './types.ts'
|
||||||
import Uploader from './Uploader'
|
import Uploader from './Uploader'
|
||||||
|
|
||||||
@@ -94,6 +95,7 @@ export default function PicturePostContent({ close }: { close: () => void }) {
|
|||||||
textValue={content}
|
textValue={content}
|
||||||
placeholder={t('Write something...')}
|
placeholder={t('Write something...')}
|
||||||
/>
|
/>
|
||||||
|
<SendOnlyToSwitch postOptions={postOptions} setPostOptions={setPostOptions} />
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
|
||||||
import { Switch } from '@/components/ui/switch'
|
import { Switch } from '@/components/ui/switch'
|
||||||
import { StorageKey } from '@/constants'
|
import { StorageKey } from '@/constants'
|
||||||
import { simplifyUrl } from '@/lib/url'
|
|
||||||
import { useFeed } from '@/providers/FeedProvider'
|
|
||||||
import { Info } from 'lucide-react'
|
|
||||||
import { Dispatch, SetStateAction, useEffect } from 'react'
|
import { Dispatch, SetStateAction, useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { TPostOptions } from './types'
|
import { TPostOptions } from './types'
|
||||||
@@ -19,13 +15,12 @@ export default function PostOptions({
|
|||||||
setPostOptions: Dispatch<SetStateAction<TPostOptions>>
|
setPostOptions: Dispatch<SetStateAction<TPostOptions>>
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { relayUrls } = useFeed()
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPostOptions({
|
setPostOptions((prev) => ({
|
||||||
addClientTag: window.localStorage.getItem(StorageKey.ADD_CLIENT_TAG) === 'true',
|
...prev,
|
||||||
sendOnlyToCurrentRelays: false
|
addClientTag: window.localStorage.getItem(StorageKey.ADD_CLIENT_TAG) === 'true'
|
||||||
})
|
}))
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
if (!show) return null
|
if (!show) return null
|
||||||
@@ -48,35 +43,6 @@ export default function PostOptions({
|
|||||||
<div className="text-muted-foreground text-xs">
|
<div className="text-muted-foreground text-xs">
|
||||||
{t('Show others this was sent via Jumble')}
|
{t('Show others this was sent via Jumble')}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
<Label htmlFor="send-only-to-current-relays" className="truncate">
|
|
||||||
{relayUrls.length === 1
|
|
||||||
? t('Send only to r', { r: simplifyUrl(relayUrls[0]) })
|
|
||||||
: t('Send only to current relays')}
|
|
||||||
</Label>
|
|
||||||
{relayUrls.length > 1 && (
|
|
||||||
<Popover>
|
|
||||||
<PopoverTrigger>
|
|
||||||
<Info size={14} />
|
|
||||||
</PopoverTrigger>
|
|
||||||
<PopoverContent className="w-fit text-sm">
|
|
||||||
{relayUrls.map((url) => (
|
|
||||||
<div key={url}>{simplifyUrl(url)}</div>
|
|
||||||
))}
|
|
||||||
</PopoverContent>
|
|
||||||
</Popover>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<Switch
|
|
||||||
className="shrink-0"
|
|
||||||
id="send-only-to-current-relays"
|
|
||||||
checked={postOptions.sendOnlyToCurrentRelays}
|
|
||||||
onCheckedChange={(checked) =>
|
|
||||||
setPostOptions((prev) => ({ ...prev, sendOnlyToCurrentRelays: checked }))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
63
src/components/PostEditor/SendOnlyToSwitch.tsx
Normal file
63
src/components/PostEditor/SendOnlyToSwitch.tsx
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import { Label } from '@/components/ui/label'
|
||||||
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
||||||
|
import { Switch } from '@/components/ui/switch'
|
||||||
|
import { isProtectedEvent } from '@/lib/event'
|
||||||
|
import { simplifyUrl } from '@/lib/url'
|
||||||
|
import { useFeed } from '@/providers/FeedProvider'
|
||||||
|
import { Info } from 'lucide-react'
|
||||||
|
import { Event } from 'nostr-tools'
|
||||||
|
import { Dispatch, SetStateAction, useEffect } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { TPostOptions } from './types'
|
||||||
|
|
||||||
|
export default function SendOnlyToSwitch({
|
||||||
|
parentEvent,
|
||||||
|
postOptions,
|
||||||
|
setPostOptions
|
||||||
|
}: {
|
||||||
|
parentEvent?: Event
|
||||||
|
postOptions: TPostOptions
|
||||||
|
setPostOptions: Dispatch<SetStateAction<TPostOptions>>
|
||||||
|
}) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const { relayUrls } = useFeed()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const isProtected = parentEvent ? isProtectedEvent(parentEvent) : false
|
||||||
|
if (isProtected) {
|
||||||
|
setPostOptions((prev) => ({ ...prev, sendOnlyToCurrentRelays: true }))
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Label htmlFor="send-only-to-current-relays" className="truncate">
|
||||||
|
{relayUrls.length === 1
|
||||||
|
? t('Send only to r', { r: simplifyUrl(relayUrls[0]) })
|
||||||
|
: t('Send only to current relays')}
|
||||||
|
</Label>
|
||||||
|
{relayUrls.length > 1 && (
|
||||||
|
<Popover>
|
||||||
|
<PopoverTrigger>
|
||||||
|
<Info size={14} />
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="w-fit text-sm">
|
||||||
|
{relayUrls.map((url) => (
|
||||||
|
<div key={url}>{simplifyUrl(url)}</div>
|
||||||
|
))}
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<Switch
|
||||||
|
className="shrink-0"
|
||||||
|
id="send-only-to-current-relays"
|
||||||
|
checked={postOptions.sendOnlyToCurrentRelays}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
setPostOptions((prev) => ({ ...prev, sendOnlyToCurrentRelays: checked }))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
extractImagesFromContent,
|
extractImagesFromContent,
|
||||||
extractMentions,
|
extractMentions,
|
||||||
getEventCoordinate,
|
getEventCoordinate,
|
||||||
|
isProtectedEvent,
|
||||||
isReplaceable
|
isReplaceable
|
||||||
} from './event'
|
} from './event'
|
||||||
|
|
||||||
@@ -25,6 +26,10 @@ export function createReactionDraftEvent(event: Event): TDraftEvent {
|
|||||||
tags.push(hint ? ['a', getEventCoordinate(event), hint] : ['a', getEventCoordinate(event)])
|
tags.push(hint ? ['a', getEventCoordinate(event), hint] : ['a', getEventCoordinate(event)])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isProtectedEvent(event)) {
|
||||||
|
tags.push(['-'])
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
kind: kinds.Reaction,
|
kind: kinds.Reaction,
|
||||||
content: '+',
|
content: '+',
|
||||||
|
|||||||
Reference in New Issue
Block a user