|
|
|
|
@ -1,10 +1,8 @@
@@ -1,10 +1,8 @@
|
|
|
|
|
import { Button } from '@/components/ui/button' |
|
|
|
|
import { useToast } from '@/hooks/use-toast' |
|
|
|
|
import { createCommentDraftEvent, createShortTextNoteDraftEvent } from '@/lib/draft-event' |
|
|
|
|
import { useFeed } from '@/providers/FeedProvider.tsx' |
|
|
|
|
import { useNostr } from '@/providers/NostrProvider' |
|
|
|
|
import client from '@/services/client.service' |
|
|
|
|
import relayInfoService from '@/services/relay-info.service' |
|
|
|
|
import { ChevronDown, ImageUp, LoaderCircle } from 'lucide-react' |
|
|
|
|
import { Event, kinds } from 'nostr-tools' |
|
|
|
|
import { useState } from 'react' |
|
|
|
|
@ -14,7 +12,6 @@ import Mentions from './Mentions'
@@ -14,7 +12,6 @@ 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' |
|
|
|
|
|
|
|
|
|
export default function NormalPostContent({ |
|
|
|
|
@ -29,12 +26,12 @@ export default function NormalPostContent({
@@ -29,12 +26,12 @@ export default function NormalPostContent({
|
|
|
|
|
const { t } = useTranslation() |
|
|
|
|
const { toast } = useToast() |
|
|
|
|
const { publish, checkLogin } = useNostr() |
|
|
|
|
const { relayUrls } = useFeed() |
|
|
|
|
const [content, setContent] = useState(defaultContent) |
|
|
|
|
const [pictureInfos, setPictureInfos] = useState<{ url: string; tags: string[][] }[]>([]) |
|
|
|
|
const [posting, setPosting] = useState(false) |
|
|
|
|
const [showMoreOptions, setShowMoreOptions] = useState(false) |
|
|
|
|
const [postOptions, setPostOptions] = useState<TPostOptions>({}) |
|
|
|
|
const [addClientTag, setAddClientTag] = useState(false) |
|
|
|
|
const [specifiedRelayUrls, setSpecifiedRelayUrls] = useState<string[] | undefined>(undefined) |
|
|
|
|
const [uploadingPicture, setUploadingPicture] = useState(false) |
|
|
|
|
const canPost = !!content && !posting |
|
|
|
|
|
|
|
|
|
@ -53,25 +50,20 @@ export default function NormalPostContent({
@@ -53,25 +50,20 @@ export default function NormalPostContent({
|
|
|
|
|
const relayList = await client.fetchRelayList(parentEvent.pubkey) |
|
|
|
|
additionalRelayUrls.push(...relayList.read.slice(0, 5)) |
|
|
|
|
} |
|
|
|
|
let protectedEvent = false |
|
|
|
|
if (postOptions.sendOnlyToCurrentRelays) { |
|
|
|
|
const relayInfos = await relayInfoService.getRelayInfos(relayUrls) |
|
|
|
|
protectedEvent = relayInfos.every((info) => info?.supported_nips?.includes(70)) |
|
|
|
|
} |
|
|
|
|
const draftEvent = |
|
|
|
|
parentEvent && parentEvent.kind !== kinds.ShortTextNote |
|
|
|
|
? await createCommentDraftEvent(content, parentEvent, pictureInfos, { |
|
|
|
|
addClientTag: postOptions.addClientTag, |
|
|
|
|
protectedEvent |
|
|
|
|
addClientTag, |
|
|
|
|
protectedEvent: !!specifiedRelayUrls |
|
|
|
|
}) |
|
|
|
|
: await createShortTextNoteDraftEvent(content, pictureInfos, { |
|
|
|
|
parentEvent, |
|
|
|
|
addClientTag: postOptions.addClientTag, |
|
|
|
|
protectedEvent |
|
|
|
|
addClientTag, |
|
|
|
|
protectedEvent: !!specifiedRelayUrls |
|
|
|
|
}) |
|
|
|
|
await publish(draftEvent, { |
|
|
|
|
additionalRelayUrls, |
|
|
|
|
specifiedRelayUrls: postOptions.sendOnlyToCurrentRelays ? relayUrls : undefined |
|
|
|
|
specifiedRelayUrls |
|
|
|
|
}) |
|
|
|
|
setContent('') |
|
|
|
|
close() |
|
|
|
|
@ -114,8 +106,8 @@ export default function NormalPostContent({
@@ -114,8 +106,8 @@ export default function NormalPostContent({
|
|
|
|
|
{content && <Preview content={content} />} |
|
|
|
|
<SendOnlyToSwitch |
|
|
|
|
parentEvent={parentEvent} |
|
|
|
|
postOptions={postOptions} |
|
|
|
|
setPostOptions={setPostOptions} |
|
|
|
|
specifiedRelayUrls={specifiedRelayUrls} |
|
|
|
|
setSpecifiedRelayUrls={setSpecifiedRelayUrls} |
|
|
|
|
/> |
|
|
|
|
<div className="flex items-center justify-between"> |
|
|
|
|
<div className="flex gap-2 items-center"> |
|
|
|
|
@ -163,8 +155,8 @@ export default function NormalPostContent({
@@ -163,8 +155,8 @@ export default function NormalPostContent({
|
|
|
|
|
</div> |
|
|
|
|
<PostOptions |
|
|
|
|
show={showMoreOptions} |
|
|
|
|
postOptions={postOptions} |
|
|
|
|
setPostOptions={setPostOptions} |
|
|
|
|
addClientTag={addClientTag} |
|
|
|
|
setAddClientTag={setAddClientTag} |
|
|
|
|
/> |
|
|
|
|
<div className="flex gap-2 items-center justify-around sm:hidden"> |
|
|
|
|
<Button |
|
|
|
|
|