Update PartyHeader and fix behavior

* Send true to editable prop is party is editable
* Fix turn count token display
* Fix party name style
* Add custom classes to various Buttons
* Only show PartyDropdown if a party is new
* Determine which buttons to show based on editable prop, not snapshot
* Remove unused code from Header
* Make new button route shallowly
This commit is contained in:
Justin Edmund 2023-06-30 22:53:17 -07:00
parent c9cfb45b57
commit 4401756277
4 changed files with 25 additions and 27 deletions

View file

@ -51,22 +51,6 @@ const Header = () => {
const [leftMenuOpen, setLeftMenuOpen] = useState(false) const [leftMenuOpen, setLeftMenuOpen] = useState(false)
const [rightMenuOpen, setRightMenuOpen] = useState(false) const [rightMenuOpen, setRightMenuOpen] = useState(false)
const [name, setName] = useState('')
const [originalName, setOriginalName] = useState('')
// Snapshots
const { party: partySnapshot } = useSnapshot(appState)
// Subscribe to app state to listen for party name and
// unsubscribe when component is unmounted
const unsubscribe = subscribe(appState, () => {
const newName =
appState.party && appState.party.name ? appState.party.name : ''
setName(newName)
})
useEffect(() => () => unsubscribe(), [])
// Methods: Event handlers (Buttons) // Methods: Event handlers (Buttons)
function handleLeftMenuButtonClicked() { function handleLeftMenuButtonClicked() {
setLeftMenuOpen(!leftMenuOpen) setLeftMenuOpen(!leftMenuOpen)
@ -126,7 +110,7 @@ const Header = () => {
}) })
// Push the root URL // Push the root URL
router.push('/new') router.push('/new', undefined, { shallow: true })
} }
const profileImage = () => { const profileImage = () => {

View file

@ -444,7 +444,7 @@ const Party = (props: Props) => {
<PartyHeader <PartyHeader
party={props.team} party={props.team}
new={props.new || false} new={props.new || false}
editable={party.editable} editable={props.new ? true : party.editable}
deleteCallback={deleteTeam} deleteCallback={deleteTeam}
remixCallback={remixTeam} remixCallback={remixTeam}
updateCallback={updateDetails} updateCallback={updateDetails}

View file

@ -6,6 +6,8 @@
max-width: $grid-width; max-width: $grid-width;
@include breakpoint(phone) { @include breakpoint(phone) {
margin-top: 0;
.Button:not(.IconButton) { .Button:not(.IconButton) {
justify-content: center; justify-content: center;
width: 100%; width: 100%;
@ -165,12 +167,15 @@
align-items: center; align-items: center;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
flex-wrap: wrap;
line-height: 1.4;
& > div { & > div {
align-items: center; align-items: center;
display: inline-flex; display: inline-flex;
font-size: $font-small; font-size: $font-small;
height: 26px; height: 26px;
white-space: nowrap;
} }
& > *:not(:last-child):after { & > *:not(:last-child):after {
@ -188,6 +193,11 @@
color: var(--text-primary); color: var(--text-primary);
} }
a {
display: flex;
align-items: center;
}
a:hover:not(.fire):not(.water):not(.wind):not(.earth):not(.dark):not( a:hover:not(.fire):not(.water):not(.wind):not(.earth):not(.dark):not(
.light .light
) { ) {
@ -214,6 +224,10 @@
& > .right { & > .right {
display: flex; display: flex;
gap: $unit-half; gap: $unit-half;
& > * {
flex-grow: 1;
}
} }
} }

View file

@ -45,9 +45,6 @@ const PartyHeader = (props: Props) => {
const router = useRouter() const router = useRouter()
const locale = router.locale || 'en' const locale = router.locale || 'en'
const isNewParty =
router.asPath === '/' || router.asPath.split('/')[1] === 'new'
const { party: partySnapshot } = useSnapshot(appState) const { party: partySnapshot } = useSnapshot(appState)
// State: Component // State: Component
@ -285,7 +282,7 @@ const PartyHeader = (props: Props) => {
{fullAutoToken} {fullAutoToken}
{autoSummonToken} {autoSummonToken}
{autoGuardToken} {autoGuardToken}
{party.turnCount && turnCountToken} {party.turnCount !== undefined && turnCountToken}
{party.clearTime > 0 && clearTimeToken()} {party.clearTime > 0 && clearTimeToken()}
{buttonChainToken()} {buttonChainToken()}
</> </>
@ -300,6 +297,7 @@ const PartyHeader = (props: Props) => {
leftAccessoryIcon={<SaveIcon />} leftAccessoryIcon={<SaveIcon />}
className={classNames({ className={classNames({
save: true, save: true,
grow: true,
saved: partySnapshot.favorited, saved: partySnapshot.favorited,
})} })}
text={ text={
@ -316,7 +314,7 @@ const PartyHeader = (props: Props) => {
<Tooltip content={t('tooltips.remix')}> <Tooltip content={t('tooltips.remix')}>
<Button <Button
leftAccessoryIcon={<RemixIcon />} leftAccessoryIcon={<RemixIcon />}
className="Remix" className="grow"
text={t('buttons.remix')} text={t('buttons.remix')}
onClick={openRemixTeamAlert} onClick={openRemixTeamAlert}
/> />
@ -330,16 +328,17 @@ const PartyHeader = (props: Props) => {
<section className={styles.info}> <section className={styles.info}>
<div className={styles.left}> <div className={styles.left}>
<div className={styles.header}> <div className={styles.header}>
<h1 className={party.name ? '' : 'empty'}> <h1 className={party.name ? '' : styles.empty}>
{party.name ? party.name : t('no_title')} {party.name ? party.name : t('no_title')}
</h1> </h1>
{party.remix && party.sourceParty && ( {party.remix && party.sourceParty && (
<Tooltip content={t('tooltips.source')}> <Tooltip content={t('tooltips.source')}>
<Button <Button
blended={true} blended={true}
className="remixed"
leftAccessoryIcon={<RemixIcon />} leftAccessoryIcon={<RemixIcon />}
text={t('tokens.remix')} text={t('tokens.remix')}
size="icon" size="small"
onClick={() => goTo(party.sourceParty?.shortcode)} onClick={() => goTo(party.sourceParty?.shortcode)}
/> />
</Tooltip> </Tooltip>
@ -358,18 +357,19 @@ const PartyHeader = (props: Props) => {
)} )}
</div> </div>
</div> </div>
{party.editable ? ( {props.editable ? (
<div className={styles.right}> <div className={styles.right}>
<EditPartyModal <EditPartyModal
party={props.party} party={props.party}
updateCallback={props.updateCallback} updateCallback={props.updateCallback}
> >
<Button <Button
className="full"
leftAccessoryIcon={<EditIcon />} leftAccessoryIcon={<EditIcon />}
text={t('buttons.show_info')} text={t('buttons.show_info')}
/> />
</EditPartyModal> </EditPartyModal>
{!isNewParty && ( {!props.new && (
<PartyDropdown <PartyDropdown
editable={props.editable} editable={props.editable}
deleteTeamCallback={props.deleteCallback} deleteTeamCallback={props.deleteCallback}