This commit is contained in:
parent
96587e3e6a
commit
3bf2437d17
@ -1,3 +1,4 @@
|
||||
import { Clear } from '@mui/icons-material'
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@ -12,13 +13,20 @@ import {
|
||||
TextField,
|
||||
Typography
|
||||
} from '@mui/material'
|
||||
import axios from 'axios'
|
||||
import JSZip from 'jszip'
|
||||
import { MuiFileInput } from 'mui-file-input'
|
||||
import styles from './style.module.scss'
|
||||
import { Dispatch, SetStateAction, useEffect, useState } from 'react'
|
||||
import placeholderAvatar from '../../assets/images/nostr-logo.jpg'
|
||||
import { ProfileMetadata } from '../../types'
|
||||
import { MetadataController, NostrController } from '../../controllers'
|
||||
import { EventTemplate } from 'nostr-tools'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useSelector } from 'react-redux'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { toast } from 'react-toastify'
|
||||
import placeholderAvatar from '../../assets/images/nostr-logo.jpg'
|
||||
import { LoadingSpinner } from '../../components/LoadingSpinner'
|
||||
import { MetadataController, NostrController } from '../../controllers'
|
||||
import { getProfileRoute } from '../../routes'
|
||||
import { State } from '../../store/rootReducer'
|
||||
import { ProfileMetadata } from '../../types'
|
||||
import {
|
||||
encryptArrayBuffer,
|
||||
generateEncryptionKey,
|
||||
@ -27,25 +35,13 @@ import {
|
||||
queryNip05,
|
||||
shorten
|
||||
} from '../../utils'
|
||||
import { LoadingSpinner } from '../../components/LoadingSpinner'
|
||||
import { getProfileRoute } from '../../routes'
|
||||
import { Clear } from '@mui/icons-material'
|
||||
import JSZip from 'jszip'
|
||||
import { toast } from 'react-toastify'
|
||||
import { useSelector } from 'react-redux'
|
||||
import { State } from '../../store/rootReducer'
|
||||
import { EventTemplate } from 'nostr-tools'
|
||||
import axios from 'axios'
|
||||
import styles from './style.module.scss'
|
||||
|
||||
enum SelectionType {
|
||||
signer = 'Signer',
|
||||
viewer = 'Viewer'
|
||||
}
|
||||
|
||||
type MetadataMap = {
|
||||
[key: string]: ProfileMetadata
|
||||
}
|
||||
|
||||
export const HomePage = () => {
|
||||
const [inputValue, setInputValue] = useState('')
|
||||
const [type, setType] = useState<SelectionType>(SelectionType.signer)
|
||||
@ -54,8 +50,6 @@ export const HomePage = () => {
|
||||
const [signers, setSigners] = useState<string[]>([])
|
||||
const [viewers, setViewers] = useState<string[]>([])
|
||||
|
||||
const [metadataMap, setMetadataMap] = useState<MetadataMap>({})
|
||||
|
||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([])
|
||||
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
@ -351,7 +345,7 @@ export const HomePage = () => {
|
||||
|
||||
// todo: do not use hardcoded relay
|
||||
await nostrController
|
||||
.publishEvent(signedEvent, 'wss://relay.snort.social')
|
||||
.publishEvent(signedEvent, 'wss://relay.damus.io')
|
||||
.then(() => {
|
||||
toast.success('DM sent to first signer')
|
||||
})
|
||||
@ -462,8 +456,6 @@ export const HomePage = () => {
|
||||
<DisplaySignerOrViewer
|
||||
key={`signer-${index}`}
|
||||
pubkey={signer}
|
||||
metadataMap={metadataMap}
|
||||
setMetadataMap={setMetadataMap}
|
||||
remove={() => handleRemove(signer, SelectionType.signer)}
|
||||
/>
|
||||
))}
|
||||
@ -493,8 +485,6 @@ export const HomePage = () => {
|
||||
<DisplaySignerOrViewer
|
||||
key={`viewer-${index}`}
|
||||
pubkey={viewer}
|
||||
metadataMap={metadataMap}
|
||||
setMetadataMap={setMetadataMap}
|
||||
remove={() => handleRemove(viewer, SelectionType.viewer)}
|
||||
/>
|
||||
))}
|
||||
@ -513,22 +503,17 @@ export const HomePage = () => {
|
||||
|
||||
type DisplaySignerOrViewerProps = {
|
||||
pubkey: string
|
||||
metadataMap: MetadataMap
|
||||
setMetadataMap: Dispatch<SetStateAction<MetadataMap>>
|
||||
remove: () => void
|
||||
}
|
||||
|
||||
const DisplaySignerOrViewer = ({
|
||||
pubkey,
|
||||
metadataMap,
|
||||
setMetadataMap,
|
||||
remove
|
||||
}: DisplaySignerOrViewerProps) => {
|
||||
const [metadata, setMetadata] = useState<ProfileMetadata>()
|
||||
|
||||
useEffect(() => {
|
||||
const getMetadata = async (pubkey: string) => {
|
||||
console.log('1 :>> ', 1)
|
||||
const metadataController = new MetadataController()
|
||||
const metadataEvent = await metadataController
|
||||
.findMetadata(pubkey)
|
||||
@ -543,26 +528,12 @@ const DisplaySignerOrViewer = ({
|
||||
if (metadataEvent) {
|
||||
const metadataContent =
|
||||
metadataController.extractProfileMetadataContent(metadataEvent)
|
||||
if (metadataContent) {
|
||||
setMetadata(metadataContent)
|
||||
setMetadataMap((prev) => ({
|
||||
...prev,
|
||||
[pubkey]: metadataContent
|
||||
}))
|
||||
}
|
||||
if (metadataContent) setMetadata(metadataContent)
|
||||
}
|
||||
}
|
||||
|
||||
const existingMetadata = metadataMap[pubkey]
|
||||
|
||||
console.log('metadataMap :>> ', metadataMap)
|
||||
|
||||
if (existingMetadata) {
|
||||
setMetadata(existingMetadata)
|
||||
} else {
|
||||
getMetadata(pubkey)
|
||||
}
|
||||
}, [pubkey, metadataMap])
|
||||
getMetadata(pubkey)
|
||||
}, [pubkey])
|
||||
|
||||
const imageLoadError = (event: any) => {
|
||||
event.target.src = placeholderAvatar
|
||||
|
Loading…
Reference in New Issue
Block a user