From 3083d805ad02bde84d42fc65e22d8e96ebb55959 Mon Sep 17 00:00:00 2001 From: Newdea <9208450+Newdea@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:37:30 +0800 Subject: [PATCH 1/5] fix sync --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index afd25447..a0cb4349 100644 --- a/src/main.ts +++ b/src/main.ts @@ -192,7 +192,7 @@ export default class SRPlugin extends Plugin { window.setInterval( async () => { await this.sync(); - this.store.save(); + // this.store.save(); }, 5 * 60 * 1000, ), From a0458a773df486f64ef4d296513f81ada956e059 Mon Sep 17 00:00:00 2001 From: Newdea <9208450+Newdea@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:55:40 +0800 Subject: [PATCH 2/5] fix blockid --- src/dataStore/itemTrans.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/dataStore/itemTrans.ts b/src/dataStore/itemTrans.ts index 2a955c19..d26f7267 100644 --- a/src/dataStore/itemTrans.ts +++ b/src/dataStore/itemTrans.ts @@ -144,10 +144,8 @@ export class ItemTrans { let blockID = question.questionText.obsidianBlockId; const count: number = question.cards.length; const scheduling: RegExpMatchArray[] = []; - if (settings.cardBlockID && !blockID) { - blockID = question.questionText.genBlockId = "^" + BlockUtils.generateBlockId(); - } let cardinfo = trackedFile.getSyncCardInfo(lineNo, cardTextHash, blockID); + if (cardinfo != null) { cardinfo.itemIds .map((id: number) => store.getItembyID(id).getSched()) @@ -162,6 +160,15 @@ export class ItemTrans { cardinfo = trackedFile.trackCard(lineNo, cardTextHash); } + // update blockid + if (settings.cardBlockID && !blockID) { + if (!cardinfo.blockID) { + blockID = "^" + BlockUtils.generateBlockId(); + cardinfo = trackedFile.getSyncCardInfo(lineNo, cardTextHash, blockID); + } + question.questionText.genBlockId = cardinfo.blockID; + } + const dtppath = question.topicPathList.list[0] ?? undefined; let deckname = dtppath?.hasPath ? dtppath.path[0] : topicPath.path[0]; deckname = Tags.isDefaultDackName(deckname) ? deckname : "#" + deckname; @@ -187,8 +194,8 @@ function updateCardObjs(cards: Card[], cardinfo: CardInfo, scheduling: RegExpMat const cardObj = cards[i]; const hasScheduleInfo: boolean = i < schedInfoList.length; const schedule: CardScheduleInfo = schedInfoList[i]; - const hassched = !schedule.isDummyScheduleForNewCard(); - cardObj.scheduleInfo = hasScheduleInfo && hassched ? schedule : null; + const hassched = hasScheduleInfo && !schedule.isDummyScheduleForNewCard(); + cardObj.scheduleInfo = hassched ? schedule : null; cardObj.Id = carditemIds[i]; if (hassched) update = true; From e8186162f6625cadc1a08d8dae9028fcfcb0d9a7 Mon Sep 17 00:00:00 2001 From: Newdea <9208450+Newdea@users.noreply.github.com> Date: Sat, 24 Aug 2024 15:08:47 +0800 Subject: [PATCH 3/5] fix cram review --- src/FlashcardReviewSequencer.ts | 22 ++++++++++++++++++---- src/dataStore/data.ts | 5 ++++- src/gui/FlashcardReviewView.tsx | 20 ++------------------ src/main.ts | 1 + 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/FlashcardReviewSequencer.ts b/src/FlashcardReviewSequencer.ts index 671d16f8..9dddc12d 100644 --- a/src/FlashcardReviewSequencer.ts +++ b/src/FlashcardReviewSequencer.ts @@ -9,6 +9,8 @@ import { Note } from "./Note"; import { IDeckTreeIterator } from "./DeckTreeIterator"; import { IQuestionPostponementList } from "./QuestionPostponementList"; import { DataLocation } from "src/dataStore/dataLocation"; +import { DataStore } from "./dataStore/data"; +import { RPITEMTYPE } from "./dataStore/repetitionItem"; export interface IFlashcardReviewSequencer { get hasCurrentCard(): boolean; @@ -140,6 +142,11 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer { } async processReview_ReviewMode(response: ReviewResponse): Promise { + if (this.settings.dataLocation !== DataLocation.SaveOnNoteFile) { + // just update storedata + this._processReviewbyAlgo(response); + } + if (this.settings.dataLocation === DataLocation.SaveOnNoteFile) { if (response != ReviewResponse.Reset || this.currentCard.hasSchedule) { // We need to update the schedule if: @@ -154,10 +161,8 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer { // Update the source file with the updated schedule await this.currentQuestion.writeQuestion(this.settings); } - } else if ( - this.settings.cardBlockID && - !this.currentQuestion.questionText.obsidianBlockId - ) { + } + if (this.settings.cardBlockID && !this.currentQuestion.questionText.obsidianBlockId) { // Update the source file with the updated block id await this.currentQuestion.writeQuestion(this.settings); } @@ -179,6 +184,15 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer { } } + private _processReviewbyAlgo(response: ReviewResponse) { + // const opt = algo.srsOptions()[response]; + const store = DataStore.getInstance(); + const id = this.currentCard.Id; + store.updateReviewedCounts(id, RPITEMTYPE.CARD); + store.reviewId(id, response); + store.save(); + } + private async burySiblingCards(): Promise { // We check if there are any sibling cards still in the deck, // We do this because otherwise we would be adding every reviewed card to the postponement list, even for a diff --git a/src/dataStore/data.ts b/src/dataStore/data.ts index dbdcd3d4..48e56140 100644 --- a/src/dataStore/data.ts +++ b/src/dataStore/data.ts @@ -330,7 +330,7 @@ export class DataStore { * @param {number} itemId * @param {string} option */ - reviewId(itemId: number, option: string) { + reviewId(itemId: number, option: string | number) { const item = this.getItembyID(itemId); let result: ReviewResult; if (item == null) { @@ -338,6 +338,9 @@ export class DataStore { } const algorithm = SrsAlgorithm.getInstance(); + if (typeof option === "number") { + option = algorithm.srsOptions()[option] as string; + } if (this.data.queues.isInRepeatQueue(itemId)) { result = algorithm.onSelection(item, option, true); } else { diff --git a/src/gui/FlashcardReviewView.tsx b/src/gui/FlashcardReviewView.tsx index 1a73a042..a01aa0df 100644 --- a/src/gui/FlashcardReviewView.tsx +++ b/src/gui/FlashcardReviewView.tsx @@ -16,12 +16,11 @@ import { Note } from "src/Note"; import { RenderMarkdownWrapper } from "src/util/RenderMarkdownWrapper"; import { CardScheduleInfo } from "src/CardSchedule"; import { FlashcardModalMode } from "./FlashcardModal"; -import { RPITEMTYPE, RepetitionItem } from "src/dataStore/repetitionItem"; +import { RepetitionItem } from "src/dataStore/repetitionItem"; import { SrTFile } from "src/SRFile"; import { ItemInfoModal } from "./info"; -import { setDueDates } from "src/algorithms/balance/balance"; import { DataLocation } from "src/dataStore/dataLocation"; -import { BlockUtils, debug } from "src/util/utils_recall"; +import { debug } from "src/util/utils_recall"; export class FlashcardReviewView { public app: App; @@ -377,25 +376,10 @@ export class FlashcardReviewView { } private async _processReview(response: ReviewResponse): Promise { - if (this.settings.dataLocation !== DataLocation.SaveOnNoteFile) { - // just update storedata - this._processReviewbyAlgo(response); - } await this.reviewSequencer.processReview(response); await this._handleSkipCard(); } - private _processReviewbyAlgo(response: ReviewResponse) { - const algo = this.plugin.algorithm; - setDueDates(this.plugin.cardStats.delayedDays.dict, this.plugin.cardStats.delayedDays.dict); - const opt = algo.srsOptions()[response]; - const store = this.plugin.store; - const id = this._currentCard.Id; - store.updateReviewedCounts(id, RPITEMTYPE.CARD); - store.reviewId(id, opt); - store.save(); - } - private async _skipCurrentCard(): Promise { this.reviewSequencer.skipCurrentCard(); await this._handleSkipCard(); diff --git a/src/main.ts b/src/main.ts index a0cb4349..7d4bdc0f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -487,6 +487,7 @@ export default class SRPlugin extends Plugin { ); const calc: DeckTreeStatsCalculator = new DeckTreeStatsCalculator(); this.cardStats = calc.calculate(this.deckTree); + setDueDates(this.cardStats.delayedDays.dict, this.cardStats.delayedDays.dict); if (this.data.settings.showDebugMessages) { this.showSyncInfo(); From 2123efce9e7e209c4cd52da5ca2ca4700b6c2661 Mon Sep 17 00:00:00 2001 From: Newdea <9208450+Newdea@users.noreply.github.com> Date: Sat, 19 Oct 2024 09:22:21 +0800 Subject: [PATCH 4/5] fix app --- src/gui/reviewresponse-modal.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gui/reviewresponse-modal.tsx b/src/gui/reviewresponse-modal.tsx index 4cedc9c6..a3449e05 100644 --- a/src/gui/reviewresponse-modal.tsx +++ b/src/gui/reviewresponse-modal.tsx @@ -8,6 +8,7 @@ import { SrsAlgorithm } from "src/algorithms/algorithms"; import { RepetitionItem } from "src/dataStore/repetitionItem"; // import { debug } from "src/util/utils_recall"; import { TouchOnMobile } from "src/Events/touchEvent"; +import { Iadapter } from "src/dataStore/adapter"; export class reviewResponseModal { private static instance: reviewResponseModal; @@ -113,7 +114,7 @@ export class reviewResponseModal { return; } - const openFile: TFile | null = app.workspace.getActiveFile(); + const openFile: TFile | null = Iadapter.instance.app.workspace.getActiveFile(); if (openFile && openFile.extension === "md") { if (this.submitCallback) { this.submitCallback(openFile, this.options.indexOf(s)); @@ -220,7 +221,8 @@ export class reviewResponseModal { bar && bar.checkVisibility() && this.isDisplay() && - app.workspace.getActiveViewOfType(MarkdownView).getMode() === "preview" + Iadapter.instance.app.workspace.getActiveViewOfType(MarkdownView).getMode() === + "preview" ) { const consume = () => { e.preventDefault(); @@ -298,7 +300,7 @@ export class reviewResponseModal { const tout = Platform.isMobile ? 5000 : 10000; const timmer = setInterval(() => { const rrBar = document.getElementById(this.barId); - const Markdown = app.workspace.getActiveViewOfType(MarkdownView); + const Markdown = Iadapter.instance.app.workspace.getActiveViewOfType(MarkdownView); if (rrBar) { if (!Markdown) { this.selfDestruct(); From 7f9eaeb7d84c5f2258b3385c910b7faec17f120a Mon Sep 17 00:00:00 2001 From: Newdea <9208450+Newdea@users.noreply.github.com> Date: Sat, 19 Oct 2024 09:29:30 +0800 Subject: [PATCH 5/5] update version --- docs/docs/changelog.md | 4 ++++ manifest.json | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md index c2fbec29..4c3aa0a6 100644 --- a/docs/docs/changelog.md +++ b/docs/docs/changelog.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +## [1.12.5.13] + +- fix #87 errors when review new cards; +- fix data sync. ## [1.12.5.12] diff --git a/manifest.json b/manifest.json index b37d703e..8af47f8d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-spaced-repetition-recall", "name": "Spaced Repetition Recall", - "version": "1.12.5.12", + "version": "1.12.5.13", "minAppVersion": "1.2.8", "description": "Fight the forgetting curve by reviewing flashcards & entire notes.", "author": "Newdea", diff --git a/package.json b/package.json index d31060cb..a03cb918 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-spaced-repetition", - "version": "1.12.5.12", + "version": "1.12.5.13", "description": "Fight the forgetting curve by reviewing flashcards & entire notes.", "main": "main.js", "scripts": {