fix(event): add client tags, handle loading on note submission

This commit is contained in:
en 2025-02-14 17:29:06 +01:00
parent dc4db40232
commit 30602d2e55
4 changed files with 19 additions and 10 deletions

View File

@ -2,7 +2,7 @@ import { NDKSubscriptionCacheUsage } from '@nostr-dev-kit/ndk'
import { FALLBACK_PROFILE_IMAGE } from '../../constants' import { FALLBACK_PROFILE_IMAGE } from '../../constants'
import { useAppSelector } from 'hooks' import { useAppSelector } from 'hooks'
import { useProfile } from 'hooks/useProfile' import { useProfile } from 'hooks/useProfile'
import { Navigate, useSubmit } from 'react-router-dom' import { Navigate, useNavigation, useSubmit } from 'react-router-dom'
import { appRoutes } from 'routes' import { appRoutes } from 'routes'
import { useEffect, useRef, useState } from 'react' import { useEffect, useRef, useState } from 'react'
import { adjustTextareaHeight } from 'utils' import { adjustTextareaHeight } from 'utils'
@ -17,6 +17,7 @@ export const NoteSubmit = ({
initialContent, initialContent,
handleClose handleClose
}: NoteSubmitProps) => { }: NoteSubmitProps) => {
const navigation = useNavigation()
const userState = useAppSelector((state) => state.user) const userState = useAppSelector((state) => state.user)
const profile = useProfile(userState.user?.pubkey as string | undefined, { const profile = useProfile(userState.user?.pubkey as string | undefined, {
cacheUsage: NDKSubscriptionCacheUsage.PARALLEL cacheUsage: NDKSubscriptionCacheUsage.PARALLEL
@ -131,8 +132,9 @@ export const NoteSubmit = ({
className='btn btnMain' className='btn btnMain'
type='submit' type='submit'
style={{ padding: '5px 20px', borderRadius: '8px' }} style={{ padding: '5px 20px', borderRadius: '8px' }}
disabled={navigation.state !== 'idle'}
> >
Post {navigation.state === 'idle' ? 'Post' : 'Posting...'}
</button> </button>
</div> </div>
</div> </div>

View File

@ -124,3 +124,6 @@ export const FALLBACK_PROFILE_IMAGE =
export const PROFILE_BLOG_FILTER_LIMIT = 20 export const PROFILE_BLOG_FILTER_LIMIT = 20
export const MAX_VISIBLE_TEXT_PER_COMMENT = 500 export const MAX_VISIBLE_TEXT_PER_COMMENT = 500
export const CLIENT_NAME_VALUE = 'DEG Mods'
export const CLIENT_TAG_VALUE =
'31990:f4bf1fb5ba8be839f70c7331733e309f780822b311f63e01f9dc8abbb428f8d5:bf1987d6-b772-43c6-bce7-42b638a9ffed'

View File

@ -11,7 +11,12 @@ import NDK, {
zapInvoiceFromEvent zapInvoiceFromEvent
} from '@nostr-dev-kit/ndk' } from '@nostr-dev-kit/ndk'
import NDKCacheAdapterDexie from '@nostr-dev-kit/ndk-cache-dexie' import NDKCacheAdapterDexie from '@nostr-dev-kit/ndk-cache-dexie'
import { MOD_FILTER_LIMIT, T_TAG_VALUE } from 'constants.ts' import {
CLIENT_NAME_VALUE,
CLIENT_TAG_VALUE,
MOD_FILTER_LIMIT,
T_TAG_VALUE
} from 'constants.ts'
import { Dexie } from 'dexie' import { Dexie } from 'dexie'
import { createContext, ReactNode, useEffect, useMemo } from 'react' import { createContext, ReactNode, useEffect, useMemo } from 'react'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
@ -127,6 +132,8 @@ export const NDKContextProvider = ({ children }: { children: ReactNode }) => {
enableOutboxModel: true, enableOutboxModel: true,
autoConnectUserRelays: true, autoConnectUserRelays: true,
autoFetchUserMutelist: true, autoFetchUserMutelist: true,
clientName: CLIENT_NAME_VALUE,
clientNip89: CLIENT_TAG_VALUE,
explicitRelayUrls: [ explicitRelayUrls: [
'wss://user.kindpag.es', 'wss://user.kindpag.es',
'wss://purplepag.es', 'wss://purplepag.es',

View File

@ -44,19 +44,16 @@ export const feedPostRouteAction =
kind: NDKKind.Text, kind: NDKKind.Text,
created_at: currentTimeStamp, created_at: currentTimeStamp,
content: content, content: content,
tags: [], tags: [
['L', 'source'],
['l', window.location.host, 'source']
],
pubkey: hexPubkey pubkey: hexPubkey
}) })
try { try {
await ndkEvent.generateTags()
if (formSubmit.nsfw) ndkEvent.tags.push(['L', 'content-warning']) if (formSubmit.nsfw) ndkEvent.tags.push(['L', 'content-warning'])
ndkEvent.tags.push(['L', 'source'])
ndkEvent.tags.push(['l', window.location.host, 'source'])
ndkEvent.tags.push(['client', 'DEG Mods'])
await ndkEvent.sign() await ndkEvent.sign()
const note1 = ndkEvent.encode() const note1 = ndkEvent.encode()
const publishedOnRelays = await ndkEvent.publish() const publishedOnRelays = await ndkEvent.publish()