Update GridRep to accommodate save button
This commit is contained in:
parent
4998072475
commit
bf3007f85e
1 changed files with 30 additions and 5 deletions
|
|
@ -1,25 +1,35 @@
|
||||||
|
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
|
import { useSnapshot } from 'valtio'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
|
|
||||||
|
import { accountState } from '~utils/accountState'
|
||||||
import { formatTimeAgo } from '~utils/timeAgo'
|
import { formatTimeAgo } from '~utils/timeAgo'
|
||||||
|
|
||||||
|
import Button from '~components/Button'
|
||||||
|
import { ButtonType } from '~utils/enums'
|
||||||
|
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
shortcode: string
|
shortcode: string
|
||||||
|
id: string
|
||||||
name: string
|
name: string
|
||||||
raid: Raid
|
raid: Raid
|
||||||
grid: GridWeapon[]
|
grid: GridWeapon[]
|
||||||
user?: User
|
user?: User
|
||||||
|
favorited: boolean
|
||||||
createdAt: Date
|
createdAt: Date
|
||||||
displayUser?: boolean | false
|
displayUser?: boolean | false
|
||||||
onClick: (shortcode: string) => void
|
onClick: (shortcode: string) => void
|
||||||
|
onSave: (partyId: string, favorited: boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const GridRep = (props: Props) => {
|
const GridRep = (props: Props) => {
|
||||||
const numWeapons: number = 9
|
const numWeapons: number = 9
|
||||||
|
|
||||||
|
const { account } = useSnapshot(accountState)
|
||||||
|
|
||||||
const [mainhand, setMainhand] = useState<Weapon>()
|
const [mainhand, setMainhand] = useState<Weapon>()
|
||||||
const [weapons, setWeapons] = useState<GridArray<Weapon>>({})
|
const [weapons, setWeapons] = useState<GridArray<Weapon>>({})
|
||||||
|
|
||||||
|
|
@ -64,6 +74,10 @@ const GridRep = (props: Props) => {
|
||||||
<img alt={weapons[position]?.name.en} src={`${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-grid/${weapons[position]?.granblue_id}.jpg`} /> : ''
|
<img alt={weapons[position]?.name.en} src={`${process.env.NEXT_PUBLIC_SIERO_IMG_URL}/weapon-grid/${weapons[position]?.granblue_id}.jpg`} /> : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendSaveData() {
|
||||||
|
props.onSave(props.id, props.favorited)
|
||||||
|
}
|
||||||
|
|
||||||
const userImage = () => {
|
const userImage = () => {
|
||||||
if (props.user)
|
if (props.user)
|
||||||
return (
|
return (
|
||||||
|
|
@ -80,7 +94,7 @@ const GridRep = (props: Props) => {
|
||||||
|
|
||||||
const details = (
|
const details = (
|
||||||
<div className="Details">
|
<div className="Details">
|
||||||
<h2 className={titleClass}>{ (props.name) ? props.name : 'Untitled' }</h2>
|
<h2 className={titleClass} onClick={navigate}>{ (props.name) ? props.name : 'Untitled' }</h2>
|
||||||
<div className="bottom">
|
<div className="bottom">
|
||||||
<div className={raidClass}>{ (props.raid) ? props.raid.name.en : 'No raid set' }</div>
|
<div className={raidClass}>{ (props.raid) ? props.raid.name.en : 'No raid set' }</div>
|
||||||
<time className="last-updated" dateTime={props.createdAt.toISOString()}>{formatTimeAgo(props.createdAt, 'en-us')}</time>
|
<time className="last-updated" dateTime={props.createdAt.toISOString()}>{formatTimeAgo(props.createdAt, 'en-us')}</time>
|
||||||
|
|
@ -90,8 +104,19 @@ const GridRep = (props: Props) => {
|
||||||
|
|
||||||
const detailsWithUsername = (
|
const detailsWithUsername = (
|
||||||
<div className="Details">
|
<div className="Details">
|
||||||
<h2 className={titleClass}>{ (props.name) ? props.name : 'Untitled' }</h2>
|
<div className="top">
|
||||||
<div className={raidClass}>{ (props.raid) ? props.raid.name.en : 'No raid set' }</div>
|
<div className="info">
|
||||||
|
<h2 className={titleClass} onClick={navigate}>{ (props.name) ? props.name : 'Untitled' }</h2>
|
||||||
|
<div className={raidClass}>{ (props.raid) ? props.raid.name.en : 'No raid set' }</div>
|
||||||
|
</div>
|
||||||
|
{ (!props.user || (account.user && account.user.id !== props.user.id)) ?
|
||||||
|
<Button
|
||||||
|
active={props.favorited}
|
||||||
|
icon="save"
|
||||||
|
type={ButtonType.IconOnly}
|
||||||
|
click={sendSaveData}
|
||||||
|
/> : ''}
|
||||||
|
</div>
|
||||||
<div className="bottom">
|
<div className="bottom">
|
||||||
<div className={userClass}>
|
<div className={userClass}>
|
||||||
{ userImage() }
|
{ userImage() }
|
||||||
|
|
@ -103,9 +128,9 @@ const GridRep = (props: Props) => {
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="GridRep" onClick={navigate}>
|
<div className="GridRep">
|
||||||
{ (props.displayUser) ? detailsWithUsername : details}
|
{ (props.displayUser) ? detailsWithUsername : details}
|
||||||
<div className="Grid">
|
<div className="Grid" onClick={navigate}>
|
||||||
<div className="weapon grid_mainhand">
|
<div className="weapon grid_mainhand">
|
||||||
{generateMainhandImage()}
|
{generateMainhandImage()}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue