feat: 💨

This commit is contained in:
codytseng
2025-02-11 10:15:05 +08:00
parent ab1fff53ef
commit d322f595fe
6 changed files with 88 additions and 39 deletions

View File

@@ -1,4 +1,5 @@
import { createReactionDraftEvent } from '@/lib/draft-event'
import { isProtectedEvent } from '@/lib/event'
import { cn } from '@/lib/utils'
import { useNostr } from '@/providers/NostrProvider'
import { useNoteStats } from '@/providers/NoteStatsProvider'
@@ -54,7 +55,13 @@ export default function LikeButton({
const targetRelayList = await client.fetchRelayList(event.pubkey)
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)
} catch (error) {
console.error('like failed', error)

View File

@@ -12,6 +12,7 @@ import TextareaWithMentions from '../TextareaWithMentions.tsx'
import Mentions from './Mentions'
import PostOptions from './PostOptions.tsx'
import Preview from './Preview'
import SendOnlyToSwitch from './SendOnlyToSwitch.tsx'
import { TPostOptions } from './types.ts'
import Uploader from './Uploader'
@@ -110,6 +111,11 @@ export default function NormalPostContent({
placeholder={t('Write something...')}
/>
{content && <Preview content={content} />}
<SendOnlyToSwitch
parentEvent={parentEvent}
postOptions={postOptions}
setPostOptions={setPostOptions}
/>
<div className="flex items-center justify-between">
<div className="flex gap-2 items-center">
<Uploader

View File

@@ -12,6 +12,7 @@ import Image from '../Image'
import TextareaWithMentions from '../TextareaWithMentions.tsx'
import Mentions from './Mentions'
import PostOptions from './PostOptions.tsx'
import SendOnlyToSwitch from './SendOnlyToSwitch.tsx'
import { TPostOptions } from './types.ts'
import Uploader from './Uploader'
@@ -94,6 +95,7 @@ export default function PicturePostContent({ close }: { close: () => void }) {
textValue={content}
placeholder={t('Write something...')}
/>
<SendOnlyToSwitch postOptions={postOptions} setPostOptions={setPostOptions} />
<div className="flex items-center justify-between">
<Button
variant="link"

View File

@@ -1,10 +1,6 @@
import { Label } from '@/components/ui/label'
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
import { Switch } from '@/components/ui/switch'
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 { useTranslation } from 'react-i18next'
import { TPostOptions } from './types'
@@ -19,13 +15,12 @@ export default function PostOptions({
setPostOptions: Dispatch<SetStateAction<TPostOptions>>
}) {
const { t } = useTranslation()
const { relayUrls } = useFeed()
useEffect(() => {
setPostOptions({
addClientTag: window.localStorage.getItem(StorageKey.ADD_CLIENT_TAG) === 'true',
sendOnlyToCurrentRelays: false
})
setPostOptions((prev) => ({
...prev,
addClientTag: window.localStorage.getItem(StorageKey.ADD_CLIENT_TAG) === 'true'
}))
}, [])
if (!show) return null
@@ -48,35 +43,6 @@ export default function PostOptions({
<div className="text-muted-foreground text-xs">
{t('Show others this was sent via Jumble')}
</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>
)
}

View 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>
)
}

View File

@@ -9,6 +9,7 @@ import {
extractImagesFromContent,
extractMentions,
getEventCoordinate,
isProtectedEvent,
isReplaceable
} from './event'
@@ -25,6 +26,10 @@ export function createReactionDraftEvent(event: Event): TDraftEvent {
tags.push(hint ? ['a', getEventCoordinate(event), hint] : ['a', getEventCoordinate(event)])
}
if (isProtectedEvent(event)) {
tags.push(['-'])
}
return {
kind: kinds.Reaction,
content: '+',