Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
-   fix #87 errors when review new cards;
-   fix data sync.
  • Loading branch information
Newdea authored Oct 19, 2024
2 parents 6d8d92b + 7f9eaeb commit 7c79f2d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 34 deletions.
4 changes: 4 additions & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
22 changes: 18 additions & 4 deletions src/FlashcardReviewSequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -140,6 +142,11 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer {
}

async processReview_ReviewMode(response: ReviewResponse): Promise<void> {
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:
Expand All @@ -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);
}
Expand All @@ -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<void> {
// 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
Expand Down
5 changes: 4 additions & 1 deletion src/dataStore/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,17 @@ 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) {
return -1;
}

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 {
Expand Down
17 changes: 12 additions & 5 deletions src/dataStore/itemTrans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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;
Expand All @@ -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;
Expand Down
20 changes: 2 additions & 18 deletions src/gui/FlashcardReviewView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -377,25 +376,10 @@ export class FlashcardReviewView {
}

private async _processReview(response: ReviewResponse): Promise<void> {
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<void> {
this.reviewSequencer.skipCurrentCard();
await this._handleSkipCard();
Expand Down
8 changes: 5 additions & 3 deletions src/gui/reviewresponse-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 7c79f2d

Please sign in to comment.