From 16f7058e536648ddce8f9949b276071ae6baa854 Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Tue, 11 Jan 2022 21:44:05 -0500 Subject: [PATCH] Fix duplicate previous pages --- src/ui/GameRoot.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ui/GameRoot.tsx b/src/ui/GameRoot.tsx index dd5633e3c..3211a2b9f 100644 --- a/src/ui/GameRoot.tsx +++ b/src/ui/GameRoot.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from "react"; -import { cloneDeep } from "lodash"; +import { cloneDeep, isEqual } from "lodash"; import { IPlayer } from "../PersonObjects/IPlayer"; import { IEngine } from "../IEngine"; import { ITerminal } from "../Terminal/ITerminal"; @@ -251,11 +251,16 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme } function setCurrentPage(page: Page, ...args: any): void { - const history = [ - { page, args: cloneDeep(args) }, + const newPage = { page, args: cloneDeep(args) }; + const previousPage = pageHistory[0]; + const isDifferentThenPrevious = page !== previousPage?.page || !isEqual([...args], previousPage?.args); + if (isDifferentThenPrevious) { + const history = [ + newPage, ...pageHistory ].slice(0, 20); - setPageHistory(history) + setPageHistory(history) + } setPage(page) }