feat: 💨
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user