More refactoring
This commit is contained in:
parent
9680b3574d
commit
e3b9833c6f
4 changed files with 17 additions and 19 deletions
|
@ -1,11 +1,3 @@
|
||||||
export interface flashcard {
|
|
||||||
id?: IDBValidKey;
|
|
||||||
src: string;
|
|
||||||
result: string;
|
|
||||||
dateAdded: Date;
|
|
||||||
exported: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Flashcards {
|
export class Flashcards {
|
||||||
db: IDBDatabase;
|
db: IDBDatabase;
|
||||||
|
|
||||||
|
@ -26,8 +18,8 @@ export class Flashcards {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
addTranslation(t: Translation | flashcard): Promise<flashcard> {
|
addTranslation(t: Translation | Flashcard): Promise<Flashcard> {
|
||||||
let card: flashcard;
|
let card: Flashcard;
|
||||||
if ("dateAdded" in t && "exported" in t) card = t;
|
if ("dateAdded" in t && "exported" in t) card = t;
|
||||||
else {
|
else {
|
||||||
card = {
|
card = {
|
||||||
|
@ -50,7 +42,7 @@ export class Flashcards {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllCards(): Promise<Array<flashcard>> {
|
async getAllCards(): Promise<Array<Flashcard>> {
|
||||||
let req = this.db
|
let req = this.db
|
||||||
.transaction(["flashcards"], "readonly")
|
.transaction(["flashcards"], "readonly")
|
||||||
.objectStore("flashcards")
|
.objectStore("flashcards")
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
//There has to be a better way to do this while remaining type safe...
|
//There has to be a better way to do this while remaining type safe...
|
||||||
import { browser, Runtime } from "webextension-polyfill-ts";
|
import { browser, Runtime } from "webextension-polyfill-ts";
|
||||||
import { flashcard } from "./background/database";
|
|
||||||
|
|
||||||
export class Communicator {
|
export class Communicator {
|
||||||
setEnabledCallback: (value: boolean, sender: Runtime.MessageSender) => void;
|
setEnabledCallback: (value: boolean, sender: Runtime.MessageSender) => void;
|
||||||
|
@ -11,9 +10,9 @@ export class Communicator {
|
||||||
) => Promise<Translation>;
|
) => Promise<Translation>;
|
||||||
|
|
||||||
addFlashcardCallback: (
|
addFlashcardCallback: (
|
||||||
value: Translation | flashcard,
|
value: Translation | Flashcard,
|
||||||
sender: Runtime.MessageSender
|
sender: Runtime.MessageSender
|
||||||
) => Promise<flashcard>;
|
) => Promise<Flashcard>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
browser.runtime.onMessage.addListener(
|
browser.runtime.onMessage.addListener(
|
||||||
|
@ -41,7 +40,7 @@ export class Communicator {
|
||||||
commandKind: commandKinds.translate,
|
commandKind: commandKinds.translate,
|
||||||
toTranslate: toTranslate,
|
toTranslate: toTranslate,
|
||||||
});
|
});
|
||||||
static addFlashcard = (card: flashcard | Translation) => {
|
static addFlashcard = (card: Flashcard | Translation) => {
|
||||||
sendMessage({ commandKind: commandKinds.addFlashcard, card: card });
|
sendMessage({ commandKind: commandKinds.addFlashcard, card: card });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -70,7 +69,7 @@ interface translate {
|
||||||
|
|
||||||
interface addFlashcard {
|
interface addFlashcard {
|
||||||
commandKind: commandKinds.addFlashcard;
|
commandKind: commandKinds.addFlashcard;
|
||||||
card: Translation | flashcard;
|
card: Translation | Flashcard;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type command = setEnabled | getEnabled | translate | addFlashcard;
|
export type command = setEnabled | getEnabled | translate | addFlashcard;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import "./custom_elements";
|
import "./custom_elements";
|
||||||
import Communicator from "../../communication";
|
import { Communicator } from "../../communication";
|
||||||
import tippy from "tippy.js";
|
import tippy from "tippy.js";
|
||||||
import "tippy.js/dist/tippy.css";
|
import "tippy.js/dist/tippy.css";
|
||||||
import "./tippy.scss";
|
import "./tippy.scss";
|
||||||
|
|
11
src/types.d.ts
vendored
11
src/types.d.ts
vendored
|
@ -3,8 +3,15 @@ declare module "*?raw" {
|
||||||
export = contents;
|
export = contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
type TranslationRequest = string;
|
declare interface Translation {
|
||||||
interface Translation {
|
|
||||||
src: string;
|
src: string;
|
||||||
result: string;
|
result: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare interface Flashcard {
|
||||||
|
id?: IDBValidKey;
|
||||||
|
src: string;
|
||||||
|
result: string;
|
||||||
|
dateAdded: Date;
|
||||||
|
exported: boolean;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue