chore: quick fix
All checks were successful
Release / build_and_release (push) Successful in 1m15s

This commit is contained in:
SwiftHawk 2024-04-08 18:05:28 +05:00
parent 96587e3e6a
commit 3bf2437d17

View File

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