diff --git a/libsnotes/src/lib.rs b/libsnotes/src/lib.rs index 421b5f4..ada048f 100644 --- a/libsnotes/src/lib.rs +++ b/libsnotes/src/lib.rs @@ -21,6 +21,11 @@ pub fn init_db() -> Result<()> { date TEXT NOT NULL, tag TEXT ); + CREATE TABLE IF NOT EXISTS favourites ( + fid INTEGER PRIMARY KEY AUTOINCREMENT, + nid INTEGER NOT NULL, + FOREIGN KEY (nid) REFERENCES notes (nid) ON DELETE CASCADE + ); "; match connection.execute(query_table, []) { diff --git a/src/main.ts b/src/main.ts index 0d3cf34..c1a535c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -200,30 +200,32 @@ window.addEventListener("DOMContentLoaded", async () => { // OCR const uploadOcrImageButtonEl = document.getElementById('image-button') as HTMLButtonElement; const ocrFileInputEl = document.getElementById('fileInput') as HTMLInputElement; - uploadOcrImageButtonEl.addEventListener('click', () => { ocrFileInputEl.click(); // Simulate click on the file input }); - ocrFileInputEl.addEventListener('change', (event) => { + ocrFileInputEl.addEventListener('change', async (event) => { const files = (event.target as HTMLInputElement).files; if (files) { console.log('Selected file:', files[0].name); - ocrFileInputEl.src = URL.createObjectURL(files[0]); - (async () => { - // TODO: change ocr language in settings - const worker = await createWorker('eng'); - const ret = await worker.recognize(files[0]); - console.log(ret.data.text); - if (createNoteContentEl) [ - createNoteContentEl.value += ret.data.text - ] - await worker.terminate(); - })(); + // Assuming you have an img element to display the selected file + const imageDisplayEl = document.getElementById('imageDisplay') as HTMLImageElement; + if (imageDisplayEl) { + imageDisplayEl.src = URL.createObjectURL(files[0]); + } + + const worker = await createWorker('eng'); + const ret = await worker.recognize(files[0]); + console.log(ret.data.text); + if (createNoteContentEl) { + createNoteContentEl.value += ret.data.text; + } + await worker.terminate(); } }); + refreshContextMenuElements(); });