From 6eedfb8f3fe0785a98ed36408061c9ed7ab9645a Mon Sep 17 00:00:00 2001 From: Davinci Date: Tue, 21 May 2024 15:21:07 +0200 Subject: [PATCH] feat: added profile banner --- src/index.css | 2 +- src/pages/profile/index.tsx | 188 +++++++++---------- src/pages/profile/style.module.scss | 32 +++- src/pages/settings/profile/index.tsx | 19 ++ src/pages/settings/profile/style.module.scss | 14 ++ src/types/profile.ts | 1 + src/utils/string.ts | 7 + 7 files changed, 162 insertions(+), 101 deletions(-) diff --git a/src/index.css b/src/index.css index 3f10537..a9ed198 100644 --- a/src/index.css +++ b/src/index.css @@ -71,7 +71,7 @@ button { } .main { - padding: 64px 0; + padding: 60px 0; } .hide-mobile { diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx index a7da30f..47087d1 100644 --- a/src/pages/profile/index.tsx +++ b/src/pages/profile/index.tsx @@ -16,12 +16,11 @@ import { NostrJoiningBlock, ProfileMetadata } from '../../types' import styles from './style.module.scss' import { useSelector } from 'react-redux' import { State } from '../../store/rootReducer' -import { getRoboHashPicture, shorten } from '../../utils' +import { getRoboHashPicture, hexToNpub, shorten } from '../../utils' import { truncate } from 'lodash' import { getProfileSettingsRoute } from '../../routes' import EditIcon from '@mui/icons-material/Edit'; import LinkIcon from '@mui/icons-material/Link'; -import RestoreIcon from '@mui/icons-material/Restore'; import { LoadingSpinner } from '../../components/LoadingSpinner' export const ProfilePage = () => { @@ -107,7 +106,13 @@ export const ProfilePage = () => { } }, [isUsersOwnProfile, metadataState, pubkey, metadataController]) - const textElementWithCopyIcon = (text: string) => { + /** + * Rendering text with button which copies the provided text + * @param text to be visible + * @param sx props (MUI) to customize style + * @returns HTML rendered text + */ + const textElementWithCopyIcon = (text: string, sx?: SxProps, shortenOffset?: number) => { const onClick = () => { navigator.clipboard.writeText(text) @@ -118,19 +123,13 @@ export const ProfilePage = () => { } return ( - - {shorten(text)} + + {shorten(text, shortenOffset)} ) } - const titleElement = (text: string, sx?: SxProps) => ( - - {text} - - ) - /** * Handles the logic for Image URL. * If no picture in kind 0 found - use robohash avatar @@ -154,97 +153,94 @@ export const ProfilePage = () => { {isLoading && } {pubkey && ( - - -
- -
-
- - - - - {profileMetadata && - titleElement( - truncate( - profileMetadata.display_name || - profileMetadata.name || - pubkey, - { - length: 16 - } - ), - { marginRight: 1 } - )} - - - {textElementWithCopyIcon(pubkey || '')} - - - {profileMetadata?.nip05 && - textElementWithCopyIcon(profileMetadata.nip05)} - - + + {profileMetadata && profileMetadata.banner ? : ''} + - - {profileMetadata?.website && ( - - - {profileMetadata.website} - - )} - - - - {nostrJoiningBlock && ( - - - On nostr since {nostrJoiningBlock.block.toLocaleString()} - - )} - + + + +
+ +
+
+ + + {nostrJoiningBlock ? `On nostr since ${nostrJoiningBlock.block.toLocaleString()}` : 'On nostr since: unknown'} + + + + {isUsersOwnProfile && ( + navigate(getProfileSettingsRoute(pubkey))}> + + + )}
- - {isUsersOwnProfile && ( - navigate(getProfileSettingsRoute(pubkey))}> - - + + + + {profileMetadata && + + {truncate( + profileMetadata.display_name || + profileMetadata.name || + hexToNpub(pubkey), + { + length: 16 + } + )} + } + + + {textElementWithCopyIcon(hexToNpub(pubkey) || '', { color: '#5e5e5e' }, 5)} + + + {profileMetadata?.nip05 && + textElementWithCopyIcon(profileMetadata.nip05, { color: '#5e5e5e' })} + + + {profileMetadata?.lud16 && + textElementWithCopyIcon(profileMetadata.lud16, { color: '#5e5e5e' })} + + + + + {profileMetadata?.website && ( + + {profileMetadata.website} + + + )} + + + + {profileMetadata?.about && ( + + {profileMetadata.about} + )} - - {profileMetadata?.about && ( - - {profileMetadata.about} - - )} -
)} diff --git a/src/pages/profile/style.module.scss b/src/pages/profile/style.module.scss index 3e1afcc..9fe952d 100644 --- a/src/pages/profile/style.module.scss +++ b/src/pages/profile/style.module.scss @@ -1,6 +1,26 @@ -.upper { +.banner { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + min-height: 210px; + + img { + width: 100%; + } + + &.noImage { + background-color: rgb(219, 219, 219); + } +} + +.belowBanner { + padding: 0 15px; +} + +.upper { + width: 100%; display: flex; - padding-top: 15px; } .container { @@ -9,6 +29,11 @@ .left { margin-right: 10px; + margin-top: -35px; +} + +.middle { + flex: 1; } .right { @@ -35,7 +60,6 @@ } .website { - // margin-top: 10px !important; margin-bottom: 15px 0 !important; } @@ -46,6 +70,6 @@ .captionIcon { color: #15999b; - margin-right: 10px; + margin-left: 5px; font-size: 12px; } \ No newline at end of file diff --git a/src/pages/settings/profile/index.tsx b/src/pages/settings/profile/index.tsx index 86799ed..7bde460 100644 --- a/src/pages/settings/profile/index.tsx +++ b/src/pages/settings/profile/index.tsx @@ -1,5 +1,6 @@ import ContentCopyIcon from '@mui/icons-material/ContentCopy' import { + Box, IconButton, InputProps, List, @@ -283,6 +284,24 @@ export const ProfileSettingsPage = () => { > {profileMetadata && (
+ + {profileMetadata.banner ? ( + Banner Image + ): No banner found } + + + {editItem('banner', 'Banner URL', undefined, undefined)} + { // return original string if it is not long enough if (str.length < offset * 2 + 4) return str