From 697fc68c3a3c5c70230c4b655cc52b578423dd62 Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Sat, 7 Oct 2023 20:09:32 -0700 Subject: [PATCH] refactor(NodeService): Clean up getNextNode() for AT/CM modes (#1453) --- src/assets/wise5/services/nodeService.ts | 29 +++++++----------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/assets/wise5/services/nodeService.ts b/src/assets/wise5/services/nodeService.ts index 7948ba27ae8..f6abc4ab9ab 100644 --- a/src/assets/wise5/services/nodeService.ts +++ b/src/assets/wise5/services/nodeService.ts @@ -53,32 +53,19 @@ export class NodeService { * @param currentId (optional) * @returns a promise that returns the next node id */ - getNextNodeId(currentId?): Promise { + getNextNodeId(currentId?: string): Promise { const promise = new Promise((resolve, reject) => { let nextNodeId = null; - let currentNodeId = null; - let mode = this.ConfigService.getMode(); - if (currentId) { - currentNodeId = currentId; - } else { - let currentNode = null; - currentNode = this.DataService.getCurrentNode(); - if (currentNode) { - currentNodeId = currentNode.id; - } - } + const currentNodeId = currentId ?? this.DataService.getCurrentNodeId(); if (currentNodeId) { - if (mode === 'classroomMonitor' || mode === 'author') { - let currentNodeOrder = this.ProjectService.getNodeOrderById(currentNodeId); + if (['author', 'classroomMonitor'].includes(this.ConfigService.getMode())) { + const currentNodeOrder = this.ProjectService.getNodeOrderById(currentNodeId); if (currentNodeOrder) { - let nextNodeOrder = currentNodeOrder + 1; - let nextId = this.ProjectService.getNodeIdByOrder(nextNodeOrder); + const nextId = this.ProjectService.getNodeIdByOrder(currentNodeOrder + 1); if (nextId) { - if (this.ProjectService.isApplicationNode(nextId)) { - nextNodeId = nextId; - } else if (this.ProjectService.isGroupNode(nextId)) { - nextNodeId = this.getNextNodeId(nextId); - } + nextNodeId = this.ProjectService.isApplicationNode(nextId) + ? nextId + : this.getNextNodeId(nextId); } } resolve(nextNodeId);