Show longest cowboy streak in profile (#353)
* Show longest cowboy streak in profile * Fix image offset * Initialize maxStreak for every user * Use resolver instead of denormalization for maxStreak --------- Co-authored-by: ekzyis <ek@stacker.news>
This commit is contained in:
parent
bf4b8714fe
commit
0d3328e509
|
@ -570,6 +570,10 @@ export default {
|
||||||
})
|
})
|
||||||
return item?.id
|
return item?.id
|
||||||
},
|
},
|
||||||
|
maxStreak: async (user, args, { models }) => {
|
||||||
|
const [{ max }] = await models.$queryRaw`SELECT MAX(COALESCE("endedAt", "startedAt") - "startedAt") FROM "Streak" WHERE "userId" = ${user.id}`
|
||||||
|
return max
|
||||||
|
},
|
||||||
nitems: async (user, { when }, { models }) => {
|
nitems: async (user, { when }, { models }) => {
|
||||||
if (typeof user.nitems === 'number') {
|
if (typeof user.nitems === 'number') {
|
||||||
return user.nitems
|
return user.nitems
|
||||||
|
|
|
@ -62,6 +62,7 @@ export default gql`
|
||||||
bioId: Int
|
bioId: Int
|
||||||
photoId: Int
|
photoId: Int
|
||||||
streak: Int
|
streak: Int
|
||||||
|
maxStreak: Int
|
||||||
sats: Int!
|
sats: Int!
|
||||||
since: Int
|
since: Int
|
||||||
upvotePopover: Boolean!
|
upvotePopover: Boolean!
|
||||||
|
|
|
@ -50,7 +50,7 @@ export default function UserHeader ({ user }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className='d-flex mt-2 flex-wrap flex-column flex-sm-row'>
|
<div className='d-flex mt-2 flex-wrap flex-column flex-sm-row'>
|
||||||
<div className='position-relative' style={{ width: 'fit-content' }}>
|
<div className='position-relative align-self-start' style={{ width: 'fit-content' }}>
|
||||||
<Image
|
<Image
|
||||||
src={user.photoId ? `https://${process.env.NEXT_PUBLIC_AWS_UPLOAD_BUCKET}.s3.amazonaws.com/${user.photoId}` : '/dorian400.jpg'} width='135' height='135'
|
src={user.photoId ? `https://${process.env.NEXT_PUBLIC_AWS_UPLOAD_BUCKET}.s3.amazonaws.com/${user.photoId}` : '/dorian400.jpg'} width='135' height='135'
|
||||||
className={styles.userimg}
|
className={styles.userimg}
|
||||||
|
@ -140,10 +140,13 @@ export default function UserHeader ({ user }) {
|
||||||
</a>
|
</a>
|
||||||
<div className='text-center font-weight-bold text-muted mt-3'>click or scan</div>
|
<div className='text-center font-weight-bold text-muted mt-3'>click or scan</div>
|
||||||
</ModalButton>
|
</ModalButton>
|
||||||
<small className='ml-0 mt-3 mt-sm-0 text-muted d-flex-inline'>stacking since: {user.since
|
<div className='d-flex flex-column mt-1 ml-0'>
|
||||||
? <Link href={`/items/${user.since}`} passHref><a className='ml-1'>#{user.since}</a></Link>
|
<small className='text-muted d-flex-inline'>stacking since: {user.since
|
||||||
: <span>never</span>}
|
? <Link href={`/items/${user.since}`} passHref><a className='ml-1'>#{user.since}</a></Link>
|
||||||
</small>
|
: <span>never</span>}
|
||||||
|
</small>
|
||||||
|
<small className='text-muted d-flex-inline'>longest cowboy streak: {user.maxStreak !== null ? user.maxStreak : 'none'}</small>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Nav
|
<Nav
|
||||||
|
|
|
@ -128,6 +128,7 @@ export const USER_FIELDS = gql`
|
||||||
createdAt
|
createdAt
|
||||||
name
|
name
|
||||||
streak
|
streak
|
||||||
|
maxStreak
|
||||||
hideCowboyHat
|
hideCowboyHat
|
||||||
nitems
|
nitems
|
||||||
ncomments
|
ncomments
|
||||||
|
|
|
@ -52,7 +52,7 @@ model User {
|
||||||
subs String[]
|
subs String[]
|
||||||
|
|
||||||
// streak
|
// streak
|
||||||
streak Int?
|
streak Int?
|
||||||
|
|
||||||
// walkthrough
|
// walkthrough
|
||||||
upvotePopover Boolean @default(false)
|
upvotePopover Boolean @default(false)
|
||||||
|
|
Loading…
Reference in New Issue