From 2cde70dff42a4e7c9569ad4ea9178ec87cf52b87 Mon Sep 17 00:00:00 2001 From: codytseng Date: Tue, 11 Feb 2025 22:46:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=92=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PostEditor/NormalPostContent.tsx | 30 +++++-------- .../PostEditor/PicturePostContent.tsx | 29 +++++------- src/components/PostEditor/PostOptions.tsx | 22 +++------ .../PostEditor/SendOnlyToSwitch.tsx | 45 ++++++++++--------- src/components/PostEditor/types.ts | 4 -- src/i18n/en.ts | 2 +- src/i18n/zh.ts | 2 +- src/layouts/SecondaryPageLayout/index.tsx | 4 +- src/services/client.service.ts | 12 ++--- 9 files changed, 64 insertions(+), 86 deletions(-) delete mode 100644 src/components/PostEditor/types.ts diff --git a/src/components/PostEditor/NormalPostContent.tsx b/src/components/PostEditor/NormalPostContent.tsx index 226c8a1a..f90ca1c0 100644 --- a/src/components/PostEditor/NormalPostContent.tsx +++ b/src/components/PostEditor/NormalPostContent.tsx @@ -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' 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({ 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({}) + const [addClientTag, setAddClientTag] = useState(false) + const [specifiedRelayUrls, setSpecifiedRelayUrls] = useState(undefined) const [uploadingPicture, setUploadingPicture] = useState(false) const canPost = !!content && !posting @@ -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({ {content && }
@@ -163,8 +155,8 @@ export default function NormalPostContent({