diff --git a/frontend/components/ActionsArea.tsx b/frontend/components/ActionsArea.tsx
index d85f8c3f..55379bd9 100644
--- a/frontend/components/ActionsArea.tsx
+++ b/frontend/components/ActionsArea.tsx
@@ -58,10 +58,10 @@ const ActionsArea = () => {
const latestTurn = turns.asArray.sort((a, b) => a.index - b.index)[
turns.allIds.length - 1
]
- const latestPhases = phases.asArray.filter((p) => p.turn === latestTurn.id)
- const latestPhase = latestPhases.sort((a, b) => a.index - b.index)[
+ const latestPhases = (latestTurn) ? phases.asArray.filter((p) => p.turn === latestTurn.id) : []
+ const latestPhase = (latestPhases.length > 0) ? latestPhases.sort((a, b) => a.index - b.index)[
latestPhases.length - 1
- ]
+ ] : null
if (thisFactionsPendingActions) {
const requiredAction = thisFactionsPendingActions.asArray.find(
diff --git a/frontend/components/MetaSection.tsx b/frontend/components/MetaSection.tsx
index f6bbb4fc..c542b865 100644
--- a/frontend/components/MetaSection.tsx
+++ b/frontend/components/MetaSection.tsx
@@ -79,10 +79,13 @@ const MetaSection = () => {
]
// Get the latest phase
- const latestPhases = phases.asArray.filter((p) => p.turn === latestTurn.id)
- const latestPhase = latestPhases.sort((a, b) => a.index - b.index)[
- latestPhases.length - 1
- ]
+ const latestPhases = latestTurn
+ ? phases.asArray.filter((p) => p.turn === latestTurn.id)
+ : []
+ const latestPhase =
+ latestPhases.length > 0
+ ? latestPhases.sort((a, b) => a.index - b.index)[latestPhases.length - 1]
+ : null
const getPhaseTerm = (phase: string) => {
switch (phase) {
@@ -157,13 +160,15 @@ const MetaSection = () => {
height={20}
className="align-middle mt-[-4px] mb-[-2px] mr-1"
/>
- {game.end_date ? (
- Game over
- ) : (
-
- Turn {latestTurn?.index},{" "}
- {latestPhase && getPhaseTerm(latestPhase.name)}
-
+ {latestTurn && latestPhase && (
+ game.end_date ? (
+ Game over
+ ) : (
+
+ Turn {latestTurn?.index},{" "}
+ {latestPhase && getPhaseTerm(latestPhase.name)}
+
+ )
)}