diff --git a/components/PartyDetails/index.tsx b/components/PartyDetails/index.tsx index 369016be..646da2c3 100644 --- a/components/PartyDetails/index.tsx +++ b/components/PartyDetails/index.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState, ChangeEvent, KeyboardEvent } from 'react' import Link from 'next/link' import { useRouter } from 'next/router' -import { useSnapshot } from 'valtio' +import { subscribe, useSnapshot } from 'valtio' import { useTranslation } from 'next-i18next' import clonedeep from 'lodash.clonedeep' @@ -25,7 +25,7 @@ import Token from '~components/Token' import api from '~utils/api' import { accountState } from '~utils/accountState' -import { appState } from '~utils/appState' +import { appState, initialAppState } from '~utils/appState' import { formatTimeAgo } from '~utils/timeAgo' import { youtube } from '~utils/youtube' @@ -124,6 +124,26 @@ const PartyDetails = (props: Props) => { } }, [props.party]) + // Subscribe to router changes and reset state + // if the new route is a new team + useEffect(() => { + router.events.on('routeChangeStart', (url, { shallow }) => { + if (url === '/new' || url === '/') { + const party = initialAppState.party + + setName(party.name ? party.name : '') + setAutoGuard(party.autoGuard) + setFullAuto(party.fullAuto) + setChargeAttack(party.chargeAttack) + setClearTime(party.clearTime) + setRemixes(party.remixes) + setTurnCount(party.turnCount) + setButtonCount(party.buttonCount) + setChainCount(party.chainCount) + } + }) + }, []) + useEffect(() => { // Extract the video IDs from the description if (appState.party.description) { @@ -475,161 +495,163 @@ const PartyDetails = (props: Props) => { } } - const editable = ( -
- - -
    -
  • - -
  • -
  • - -
  • -
  • - -
  • -
-
    -
  • - -
  • -
  • - -
  • -
  • - -
  • -
- + + +
  • + +
  • + + -
    -
    - {router.pathname !== '/new' ? ( +
    +
    + {router.pathname !== '/new' ? ( +
    +
    +
    -
    -
    -
    -
    - ) + + ) + } const clearTimeString = () => { const minutes = Math.floor(clearTime / 60) @@ -664,38 +686,46 @@ const PartyDetails = (props: Props) => { } } - const readOnly = ( -
    -
    - - {`${t('party.details.labels.charge_attack')} ${ - chargeAttack ? 'On' : 'Off' - }`} - - - - {`${t('party.details.labels.full_auto')} ${fullAuto ? 'On' : 'Off'}`} - - - - {`${t('party.details.labels.auto_guard')} ${fullAuto ? 'On' : 'Off'}`} - - - {turnCount ? ( - - {t('party.details.turns.with_count', { - count: turnCount, - })} + const readOnly = () => { + return ( +
    +
    + + {`${t('party.details.labels.charge_attack')} ${ + chargeAttack ? 'On' : 'Off' + }`} - ) : ( - '' - )} - {clearTime > 0 ? {clearTimeString()} : ''} - {buttonChainToken()} + + + {`${t('party.details.labels.full_auto')} ${ + fullAuto ? 'On' : 'Off' + }`} + + + + {`${t('party.details.labels.auto_guard')} ${ + fullAuto ? 'On' : 'Off' + }`} + + + {turnCount ? ( + + {t('party.details.turns.with_count', { + count: turnCount, + })} + + ) : ( + '' + )} + {clearTime > 0 ? {clearTimeString()} : ''} + {buttonChainToken()} +
    + {embeddedDescription}
    - {embeddedDescription} -
    - ) + ) + } const remixSection = () => { return ( @@ -755,8 +785,8 @@ const PartyDetails = (props: Props) => { '' )} - {readOnly} - {editable} + {readOnly()} + {editable()} {deleteAlert()}