Fix lint errors

This commit is contained in:
Abdo 2025-06-02 06:14:15 +03:00
parent 05360e2d19
commit 07d3b6d2b5
6 changed files with 28 additions and 21 deletions

View file

@ -387,19 +387,23 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
if type == "blur":
self.currentField = None
# run any filters
if gui_hooks.editor_did_unfocus_field(False, self.note, ord):
if self.note and gui_hooks.editor_did_unfocus_field(
False, self.note, ord
):
# something updated the note; update it after a subsequent focus
# event has had time to fire
self.mw.progress.timer(
100, self.loadNoteKeepingFocus, False, parent=self.widget
)
else:
if self.note:
gui_hooks.editor_did_fire_typing_timer(self.note)
# focused into field?
elif cmd.startswith("focus"):
(type, num) = cmd.split(":", 1)
self.last_field_index = self.currentField = int(num)
if self.note:
gui_hooks.editor_did_focus_field(self.note, self.currentField)
elif cmd.startswith("toggleStickyAll"):
@ -436,6 +440,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
return new_state
elif cmd.startswith("saveTags"):
if self.note:
gui_hooks.editor_did_update_tags(self.note)
elif cmd.startswith("editorState"):
@ -516,6 +521,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
assert self.mw.pm.profile is not None
js = f"loadNote({json.dumps(self.nid)}, {mid}, {json.dumps(focus_to)}, {json.dumps(self.orig_note_id)});"
if self.note:
js = gui_hooks.editor_will_load_note(js, self.note, self)
self.web.evalWithCallback(
f'require("anki/ui").loaded.then(() => {{ {js} }})', oncallback
@ -523,6 +529,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
@deprecated(replaced_by=load_note)
def loadNote(self, focusTo: int | None = None) -> None:
assert self.note is not None
self.load_note(self.note.mid, focus_to=focusTo)
def call_after_note_saved(

View file

@ -372,28 +372,28 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
async function noteCanBeAdded(): Promise<boolean> {
let problem: string | null = null;
const result = await noteFieldsCheck(note!);
if(result.state === NoteFieldsCheckResponse_State.EMPTY) {
if(isImageOcclusion) {
if (result.state === NoteFieldsCheckResponse_State.EMPTY) {
if (isImageOcclusion) {
problem = tr.notetypesNoOcclusionCreated2();
} else {
problem = tr.addingTheFirstFieldIsEmpty();
}
}
if(result.state === NoteFieldsCheckResponse_State.MISSING_CLOZE) {
if (result.state === NoteFieldsCheckResponse_State.MISSING_CLOZE) {
// TODO: askUser(tr.addingYouHaveAClozeDeletionNote())
return false;
}
if(result.state === NoteFieldsCheckResponse_State.NOTETYPE_NOT_CLOZE) {
if (result.state === NoteFieldsCheckResponse_State.NOTETYPE_NOT_CLOZE) {
problem = tr.addingClozeOutsideClozeNotetype();
}
if(result.state === NoteFieldsCheckResponse_State.FIELD_NOT_CLOZE) {
if (result.state === NoteFieldsCheckResponse_State.FIELD_NOT_CLOZE) {
problem = tr.addingClozeOutsideClozeField();
}
return problem ? false : true;
}
async function addCurrentNoteInner(deckId: bigint) {
if(!await noteCanBeAdded()) {
if (!(await noteCanBeAdded())) {
return;
}
await addNote({
@ -404,10 +404,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
export async function addCurrentNote(deckId: bigint) {
if(mode !== "add") {
if (mode !== "add") {
return;
}
if(isImageOcclusion) {
if (isImageOcclusion) {
saveOcclusions();
await addCurrentNoteInner(deckId);
resetIOImageLoaded();
@ -679,7 +679,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} else {
setNote(
await getNote({
nid!,
nid: nid!,
}),
);
}

View file

@ -15,9 +15,9 @@ async function save(): Promise<void> {
export const load = (async ({ params }) => {
let mode: IOMode;
if (/^\d+/.test(params.imagePathOrNoteId)) {
mode = { kind: "edit", noteId: Number(params.imagePathOrNoteId) };
mode = { kind: "edit", noteId: BigInt(params.imagePathOrNoteId) };
} else {
mode = { kind: "add", imagePath: params.imagePathOrNoteId, notetypeId: 0 };
mode = { kind: "add", imagePath: params.imagePathOrNoteId, notetypeId: 0n };
}
// for adding note from mobile devices

View file

@ -31,7 +31,7 @@ export const addOrUpdateNote = async function(
if (mode.kind == "edit") {
const result = await updateImageOcclusionNote({
noteId: BigInt(mode.noteId),
noteId: mode.noteId,
occlusions: occlusionCloze,
header,
backExtra,
@ -53,7 +53,7 @@ export const addOrUpdateNote = async function(
};
// show toast message
const showResult = (noteId: number | null, result: OpChanges, count: number) => {
const showResult = (noteId: bigint | null, result: OpChanges, count: number) => {
const props = $state({
message: "",
type: "error" as "error" | "success",

View file

@ -50,10 +50,10 @@ export async function setupImageOcclusion(mode: IOMode, target = document.body):
if (window.location.hash.startsWith("#test-")) {
const imagePath = window.location.hash.replace("#test-", "");
setupImageOcclusion({ kind: "add", imagePath, notetypeId: 0 });
setupImageOcclusion({ kind: "add", imagePath, notetypeId: 0n });
}
if (window.location.hash.startsWith("#testforedit-")) {
const noteId = parseInt(window.location.hash.replace("#testforedit-", ""));
const noteId = BigInt(window.location.hash.replace("#testforedit-", ""));
setupImageOcclusion({ kind: "edit", noteId });
}

View file

@ -44,7 +44,7 @@ export const setupMaskEditor = async (
};
export const setupMaskEditorForEdit = async (
noteId: number,
noteId: bigint,
onImageLoaded: (event: ImageLoadedEvent) => void,
): Promise<fabric.Canvas> => {
const clozeNoteResponse = await getImageOcclusionNote({ noteId: BigInt(noteId) });