Skip to content

Commit

Permalink
fix: Handle edge case when the statement is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixiaorui committed Jun 23, 2024
1 parent 1691069 commit c29dce2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/client/store/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ const statementIndex = ref(0);

export function useStatement() {
function setupStatement(course: Ref<Course | undefined>) {
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();
Expand Down

0 comments on commit c29dce2

Please sign in to comment.