From 1da152cbccd0f404f84742668ff26ee2f067a944 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 4 Mar 2022 07:31:02 -0800 Subject: [PATCH] Fix title for new teams --- components/PartyDetails/index.tsx | 39 +++++++++++++++++++++---------- pages/new/index.tsx | 4 ---- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/components/PartyDetails/index.tsx b/components/PartyDetails/index.tsx index e7410812..e711dc3f 100644 --- a/components/PartyDetails/index.tsx +++ b/components/PartyDetails/index.tsx @@ -5,12 +5,12 @@ import Linkify from 'react-linkify' import classNames from 'classnames' import CharLimitedFieldset from '~components/CharLimitedFieldset' +import RaidDropdown from '~components/RaidDropdown' import TextFieldset from '~components/TextFieldset' import { appState } from '~utils/appState' import './index.scss' -import RaidDropdown from '~components/RaidDropdown' // Props interface Props { @@ -19,7 +19,7 @@ interface Props { } const PartyDetails = (props: Props) => { - const appSnapshot = useSnapshot(appState) + const { party, raids } = useSnapshot(appState) const nameInput = React.createRef() const descriptionInput = React.createRef() @@ -28,13 +28,13 @@ const PartyDetails = (props: Props) => { const readOnlyClasses = classNames({ 'PartyDetails': true, 'ReadOnly': true, - 'Visible': !appSnapshot.party.detailsVisible + 'Visible': !party.detailsVisible }) const editableClasses = classNames({ 'PartyDetails': true, 'Editable': true, - 'Visible': appSnapshot.party.detailsVisible + 'Visible': party.detailsVisible }) const [errors, setErrors] = useState<{ [key: string]: string }>({ @@ -63,7 +63,7 @@ const PartyDetails = (props: Props) => { function updateDetails(event: React.ChangeEvent) { const nameValue = nameInput.current?.value const descriptionValue = descriptionInput.current?.value - const raid = appSnapshot.raids.find(raid => raid.id == raidSelect.current?.value) + const raid = raids.find(raid => raid.id == raidSelect.current?.value) props.updateCallback(nameValue, descriptionValue, raid) } @@ -73,7 +73,7 @@ const PartyDetails = (props: Props) => { { /> { const readOnly = (
- { (appSnapshot.party.name) ?

{appSnapshot.party.name}

: '' } - { (appSnapshot.party.raid) ?
{appSnapshot.party.raid.name.en}
: '' } - { (appSnapshot.party.description) ?

{appSnapshot.party.description}

: '' } + { (party.name) ?

{party.name}

: '' } + { (party.raid) ?
{party.raid.name.en}
: '' } + { (party.description) ?

{party.description}

: '' }
) + const generateTitle = () => { + let title = '' + + const username = (party.user != null) ? `@${party.user?.username}` : 'Anonymous' + + if (party.name != null) + title = `${party.name} by ${username}` + else if (party.name == null && party.editable) + title = "New Team" + else + title = `Untitled team by ${username}` + + return title + } + return (
- { (appSnapshot.party.name != null) ? appSnapshot.party.name : 'Untitled team'} by { (appSnapshot.party.user != null) ? `@${appSnapshot.party.user?.username}` : 'Anonymous' } + {generateTitle()} {readOnly} diff --git a/pages/new/index.tsx b/pages/new/index.tsx index 34b0c6c1..98ea6549 100644 --- a/pages/new/index.tsx +++ b/pages/new/index.tsx @@ -1,5 +1,4 @@ import React from 'react' -import Head from 'next/head' import Party from '~components/Party' const NewRoute = () => { @@ -10,9 +9,6 @@ const NewRoute = () => { return (
- - New Team -
)