From 41f821159ae42033aa245ddef1feca48f6a0c389 Mon Sep 17 00:00:00 2001 From: SwiftHawk Date: Thu, 16 May 2024 16:22:05 +0500 Subject: [PATCH] chore create a component for user --- src/components/username.tsx | 45 ++++++++++++++++++++- src/pages/create/index.tsx | 49 ++++++++--------------- src/pages/sign/index.tsx | 78 ++++++++++--------------------------- src/pages/verify/index.tsx | 53 ++++++++++--------------- 4 files changed, 101 insertions(+), 124 deletions(-) diff --git a/src/components/username.tsx b/src/components/username.tsx index 928d0c6..387a4c6 100644 --- a/src/components/username.tsx +++ b/src/components/username.tsx @@ -1,6 +1,9 @@ -import { Typography, IconButton } from '@mui/material' +import { Typography, IconButton, Box, useTheme } from '@mui/material' import { useSelector } from 'react-redux' import { State } from '../store/rootReducer' +import { hexToNpub } from '../utils' +import { Link } from 'react-router-dom' +import { getProfileRoute } from '../routes' type Props = { username: string @@ -44,3 +47,43 @@ const Username = ({ username, avatarContent, handleClick }: Props) => { } export default Username + +type UserProps = { + pubkey: string + name: string + image?: string +} + +export const UserComponent = ({ pubkey, name, image }: UserProps) => { + const theme = useTheme() + + const npub = hexToNpub(pubkey) + const roboImage = `https://robohash.org/${npub}.png?set=set3` + + return ( + + User Image + + + {name} + + + + ) +} diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 909461e..2f9fc67 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -18,18 +18,22 @@ import { Tooltip, Typography } from '@mui/material' +import JSZip from 'jszip' import { MuiFileInput } from 'mui-file-input' import { useEffect, useState } from 'react' -import { Link, useNavigate } from 'react-router-dom' +import { useSelector } from 'react-redux' +import { useNavigate } from 'react-router-dom' +import { toast } from 'react-toastify' import { LoadingSpinner } from '../../components/LoadingSpinner' +import { UserComponent } from '../../components/username' import { MetadataController, NostrController } from '../../controllers' -import { appPrivateRoutes, getProfileRoute } from '../../routes' +import { appPrivateRoutes } from '../../routes' +import { State } from '../../store/rootReducer' import { ProfileMetadata, User, UserRole } from '../../types' import { encryptArrayBuffer, generateEncryptionKey, getHash, - getRoboHashPicture, hexToNpub, pubToHex, queryNip05, @@ -39,10 +43,6 @@ import { uploadToFileStorage } from '../../utils' import styles from './style.module.scss' -import { toast } from 'react-toastify' -import JSZip from 'jszip' -import { useSelector } from 'react-redux' -import { State } from '../../store/rootReducer' export const CreatePage = () => { const navigate = useNavigate() @@ -489,10 +489,6 @@ const DisplayUser = ({ }) }, [users]) - const imageLoadError = (event: any, pubkey: string) => { - event.target.src = getRoboHashPicture(pubkey) - } - return ( @@ -506,31 +502,18 @@ const DisplayUser = ({ {users.map((user, index) => { const userMeta = metadata[user.pubkey] - const npub = hexToNpub(user.pubkey) - const roboUrl = `https://robohash.org/${npub}.png?set=set3` return ( - - {imageLoadError(event, user.pubkey)}} - src={userMeta?.picture || roboUrl} - alt="Profile Image" - className="profile-image" - style={{ - borderWidth: '3px', - borderStyle: 'solid', - borderColor: `#${user.pubkey.substring(0, 6)}` - }} - /> - - - {userMeta?.display_name || - userMeta?.name || - shorten(npub)} - - - +