Create teams when arbitrary details are changed

These teams have no weapons and won't show up anywhere but the user's profile. We should probably clean out completely empty teams every once in a while with a CRON job.
This commit is contained in:
Justin Edmund 2023-01-07 23:25:55 -08:00
parent 4a219378c7
commit 5de556b367

View file

@ -59,44 +59,60 @@ const Party = (props: Props) => {
} }
} }
function updateDetails(details: DetailsObject) { async function updateDetails(details: DetailsObject) {
if ( if (
appState.party.name !== details.name || appState.party.name !== details.name ||
appState.party.description !== details.description || appState.party.description !== details.description ||
appState.party.raid?.id !== details.raid?.id appState.party.raid?.id !== details.raid?.id
) { ) {
if (appState.party.id) if (!appState.party.id)
api.endpoints.parties await createParty().then((response) => {
.update(appState.party.id, { // If the party has no ID, create a new party
party: { const party = response.data.party
name: details.name, storeParty(party)
description: details.description,
raid_id: details.raid?.id,
charge_attack: details.chargeAttack,
full_auto: details.fullAuto,
auto_guard: details.autoGuard,
clear_time: details.clearTime,
button_count: details.buttonCount,
chain_count: details.chainCount,
turn_count: details.turnCount,
},
})
.then(() => {
appState.party.name = details.name
appState.party.description = details.description
appState.party.raid = details.raid
appState.party.chargeAttack = details.chargeAttack // Then, push the browser history to the new party's URL
appState.party.fullAuto = details.fullAuto if (props.pushHistory) props.pushHistory(`/p/${party.shortcode}`)
appState.party.autoGuard = details.autoGuard })
appState.party.clearTime = details.clearTime // Update the party
appState.party.buttonCount = details.buttonCount await sendUpdate(details)
appState.party.chainCount = details.chainCount }
appState.party.turnCount = details.turnCount }
appState.party.updated_at = party.updated_at async function sendUpdate(details: DetailsObject) {
}) if (appState.party.id) {
return await api.endpoints.parties
.update(appState.party.id, {
party: {
name: details.name,
description: details.description,
raid_id: details.raid?.id,
charge_attack: details.chargeAttack,
full_auto: details.fullAuto,
auto_guard: details.autoGuard,
clear_time: details.clearTime,
button_count: details.buttonCount,
chain_count: details.chainCount,
turn_count: details.turnCount,
},
})
.then(() => {
appState.party.name = details.name
appState.party.description = details.description
appState.party.raid = details.raid
appState.party.chargeAttack = details.chargeAttack
appState.party.fullAuto = details.fullAuto
appState.party.autoGuard = details.autoGuard
appState.party.clearTime = details.clearTime
appState.party.buttonCount = details.buttonCount
appState.party.chainCount = details.chainCount
appState.party.turnCount = details.turnCount
appState.party.updated_at = party.updated_at
})
} }
} }