From c29dce23289e136d7df34be15a7617b0a1cb7307 Mon Sep 17 00:00:00 2001 From: cuixiaorui Date: Sun, 23 Jun 2024 17:08:30 +0800 Subject: [PATCH] fix: Handle edge case when the statement is deleted --- apps/client/store/statement.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/client/store/statement.ts b/apps/client/store/statement.ts index cf4407367..b9e89c3b0 100644 --- a/apps/client/store/statement.ts +++ b/apps/client/store/statement.ts @@ -16,7 +16,14 @@ const statementIndex = ref(0); export function useStatement() { function setupStatement(course: Ref) { - statementIndex.value = course.value!.statementIndex || 0; + // 课程的 statement 会被删除, + // 如果记录的 statementIndex 所对应的 statement 被删除了 + // 那么默认返回第一个 statement + if (course.value!.statementIndex >= course.value!.statements.length) { + statementIndex.value = 0; + } else { + statementIndex.value = course.value!.statementIndex || 0; + } const debouncedSaveProgress = debounce(() => { saveProgress();