WIP profiles
This commit is contained in:
parent
9f48daecc3
commit
4ba1227605
|
@ -10,6 +10,9 @@ import { gql, useApolloClient, useMutation } from '@apollo/client'
|
||||||
import styles from './user-header.module.css'
|
import styles from './user-header.module.css'
|
||||||
import { useMe } from './me'
|
import { useMe } from './me'
|
||||||
import { NAME_MUTATION, NAME_QUERY } from '../fragments/users'
|
import { NAME_MUTATION, NAME_QUERY } from '../fragments/users'
|
||||||
|
import Image from 'next/image'
|
||||||
|
import QRCode from 'qrcode.react'
|
||||||
|
import LightningIcon from '../svgs/bolt.svg'
|
||||||
|
|
||||||
export default function UserHeader ({ user }) {
|
export default function UserHeader ({ user }) {
|
||||||
const [editting, setEditting] = useState(false)
|
const [editting, setEditting] = useState(false)
|
||||||
|
@ -19,7 +22,7 @@ export default function UserHeader ({ user }) {
|
||||||
const [setName] = useMutation(NAME_MUTATION)
|
const [setName] = useMutation(NAME_MUTATION)
|
||||||
|
|
||||||
const isMe = me?.name === user.name
|
const isMe = me?.name === user.name
|
||||||
const Satistics = () => <h1 className='mb-0'><small className='text-success'>{isMe ? `${user.sats} sats \\ ` : ''}{user.stacked} stacked</small></h1>
|
const Satistics = () => <div className={`mb-4 ${styles.username} text-success`}>{isMe ? `${user.sats} sats \\ ` : ''}{user.stacked} stacked</div>
|
||||||
|
|
||||||
const UserSchema = Yup.object({
|
const UserSchema = Yup.object({
|
||||||
name: Yup.string()
|
name: Yup.string()
|
||||||
|
@ -39,64 +42,78 @@ export default function UserHeader ({ user }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div className='d-flex align-items-center mt-2 flex-wrap'>
|
||||||
{editting
|
<Image
|
||||||
? (
|
src='/dorian400.jpg' width='200' height='166' layout='fixed'
|
||||||
<Form
|
className={styles.userimg}
|
||||||
schema={UserSchema}
|
/>
|
||||||
initial={{
|
<div className='ml-3'>
|
||||||
name: user.name
|
{editting
|
||||||
}}
|
? (
|
||||||
validateImmediately
|
<Form
|
||||||
onSubmit={async ({ name }) => {
|
schema={UserSchema}
|
||||||
if (name === user.name) {
|
initial={{
|
||||||
setEditting(false)
|
name: user.name
|
||||||
return
|
}}
|
||||||
}
|
validateImmediately
|
||||||
const { error } = await setName({ variables: { name } })
|
onSubmit={async ({ name }) => {
|
||||||
if (error) {
|
if (name === user.name) {
|
||||||
throw new Error({ message: error.toString() })
|
setEditting(false)
|
||||||
}
|
return
|
||||||
router.replace({
|
}
|
||||||
pathname: router.pathname,
|
const { error } = await setName({ variables: { name } })
|
||||||
query: { ...router.query, name }
|
if (error) {
|
||||||
})
|
throw new Error({ message: error.toString() })
|
||||||
|
}
|
||||||
|
router.replace({
|
||||||
|
pathname: router.pathname,
|
||||||
|
query: { ...router.query, name }
|
||||||
|
})
|
||||||
|
|
||||||
client.writeFragment({
|
client.writeFragment({
|
||||||
id: `User:${user.id}`,
|
id: `User:${user.id}`,
|
||||||
fragment: gql`
|
fragment: gql`
|
||||||
fragment CurUser on User {
|
fragment CurUser on User {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
data: {
|
data: {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
setEditting(false)
|
setEditting(false)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className='d-flex align-items-center'>
|
<div className='d-flex align-items-center mb-1'>
|
||||||
<Input
|
<Input
|
||||||
prepend=<InputGroup.Text>@</InputGroup.Text>
|
prepend=<InputGroup.Text>@</InputGroup.Text>
|
||||||
name='name'
|
name='name'
|
||||||
autoFocus
|
autoFocus
|
||||||
groupClassName={`mb-0 ${styles.username}`}
|
groupClassName={styles.usernameForm}
|
||||||
showValid
|
showValid
|
||||||
/>
|
/>
|
||||||
<SubmitButton variant='link' onClick={() => setEditting(true)}>save</SubmitButton>
|
<SubmitButton variant='link' onClick={() => setEditting(true)}>save</SubmitButton>
|
||||||
|
</div>
|
||||||
|
</Form>
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
<div className='d-flex align-items-center mb-1'>
|
||||||
|
<div className={styles.username}>@{user.name}</div>
|
||||||
|
{isMe &&
|
||||||
|
<Button className='py-0' variant='link' onClick={() => setEditting(true)}>edit nym</Button>}
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
)}
|
||||||
)
|
<Satistics user={user} />
|
||||||
: (
|
<Button className='font-weight-bold'>
|
||||||
<div className='d-flex align-items-center'>
|
<LightningIcon
|
||||||
<h2 className='mb-0'>@{user.name}</h2>
|
width={20}
|
||||||
{isMe &&
|
height={20}
|
||||||
<Button variant='link' onClick={() => setEditting(true)}>edit nym</Button>}
|
className='mr-1'
|
||||||
</div>
|
/>{user.name}@stacker.news
|
||||||
)}
|
</Button>
|
||||||
<Satistics user={user} />
|
</div>
|
||||||
|
<QRCode className='ml-auto' value='fdsajfkldsajlkfjdlksajfkldjsalkjfdklsa' renderAs='svg' size={166} />
|
||||||
</div>
|
</div>
|
||||||
<Nav
|
<Nav
|
||||||
className={styles.nav}
|
className={styles.nav}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
.username {
|
.usernameForm {
|
||||||
width: 300px;
|
width: 300px;
|
||||||
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav {
|
.nav {
|
||||||
|
@ -13,4 +14,15 @@
|
||||||
|
|
||||||
.nav div:last-child a {
|
.nav div:last-child a {
|
||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.userimg {
|
||||||
|
clip-path: polygon(0% 0%, 83% 0%, 100% 100%, 17% 100%);
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.username {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 150%;
|
||||||
|
line-height: 1.25rem;
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Loading…
Reference in New Issue