rudimentary test with tauri and rust retrieval

This commit is contained in:
catto 2024-04-09 19:54:49 +02:00
parent d0b9381437
commit d6e3f840b4
7 changed files with 76 additions and 43 deletions

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="stylesheet" href="/src/styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri App</title>
<title>Snotes Deck</title>
<script type="module" src="/src/main.ts" defer></script>
<style>
.logo.vite:hover {
@ -19,38 +19,18 @@
<body>
<div class="container">
<h1>Welcome to Tauri!</h1>
<h1>Snotes Deck Test</h1>
<div class="row">
<a href="https://vitejs.dev" target="_blank">
<img src="/src/assets/vite.svg" class="logo vite" alt="Vite logo" />
</a>
<a href="https://tauri.app" target="_blank">
<img
src="/src/assets/tauri.svg"
class="logo tauri"
alt="Tauri logo"
/>
</a>
<a href="https://www.typescriptlang.org/docs" target="_blank">
<img
src="/src/assets/typescript.svg"
class="logo typescript"
alt="typescript logo"
/>
</a>
</div>
<p>Click on the Tauri logo to learn more about the framework</p>
<form class="row" id="greet-form">
<input id="greet-input" placeholder="Type your note here..." />
<form class="row" id="create-form">
<input id="create-input" placeholder="Note..." />
<input id="create-tag" placeholder="Tag..." />
<button type="submit">Save</button>
</form>
<p id="greet-msg"></p>
<p id="create-msg"></p>
<button id="show-notes-button">Show Notes</button>
<button class="row" id="show-notes-button">Refresh Notes</button>
<p style="white-space: pre-line" id="notes-list"></p>
</div>
</body>

View File

@ -1,7 +1,7 @@
[package]
name = "snotes-deck"
version = "0.0.0"
description = "A Tauri App"
description = "A simple little Note App"
authors = ["you"]
edition = "2021"

View File

@ -15,9 +15,17 @@ fn get_notes_list() -> String {
format!("{}", notes)
}
#[tauri::command]
fn create_note(content: &str, tag: &str) -> bool {
println!("reached");
libsnotes::create_note(&content.to_string(), &tag.to_string()).unwrap();
true
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, get_notes_list])
.invoke_handler(tauri::generate_handler![greet, get_notes_list, create_note])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -8,7 +8,7 @@
},
"package": {
"productName": "snotes-deck",
"version": "0.0.0"
"version": "0.0.1"
},
"tauri": {
"allowlist": {
@ -20,7 +20,7 @@
},
"windows": [
{
"title": "snotes-deck",
"title": "Snotes Deck",
"width": 800,
"height": 600
}
@ -31,7 +31,7 @@
"bundle": {
"active": true,
"targets": "all",
"identifier": "com.tauri.dev",
"identifier": "space.maidsin.snotes-deck",
"icon": [
"icons/32x32.png",
"icons/128x128.png",

View File

@ -1,32 +1,66 @@
import { invoke } from "@tauri-apps/api/tauri";
//import { Note } from "./model";
let greetInputEl: HTMLInputElement | null;
let greetMsgEl: HTMLElement | null;
let notesMsgEl: HTMLElement | null;
//let createMsgEl: HTMLElement | null;
async function greet() {
if (greetMsgEl && greetInputEl) {
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
greetMsgEl.textContent = await invoke("greet", {
name: greetInputEl.value,
let createNoteContentEl: HTMLInputElement | null;
let createNoteTagEl: HTMLInputElement | null;
// create
async function createNote() {
console.log("reached ssssjs")
if (createNoteContentEl && createNoteTagEl) {
console.log("reached js")
await invoke("create_note", {
content: createNoteContentEl.value,
tag: createNoteTagEl.value
});
}
}
// read
async function showNotes() {
if (notesMsgEl) {
notesMsgEl.textContent = await invoke("get_notes_list");
}
}
// TODO: read better array of note elements with id iterable the whole thing
// update
// async function updateNote() {
// if (true) {
// await invoke("update_note", {
// id: null,
// content: null,
// tag: null
// });
// }
// }
// delete
// async function deleteNote() {
// if (true) {
// await invoke("delete_note", {
// id: null
// }
// )
// }
// }
window.addEventListener("DOMContentLoaded", () => {
greetInputEl = document.querySelector("#greet-input");
greetMsgEl = document.querySelector("#greet-msg");
createNoteContentEl = document.querySelector("#create-input");
createNoteTagEl = document.querySelector("#create-tag");
// createMsgEl = document.querySelector("#create-msg");
notesMsgEl = document.querySelector("#notes-list");
document.querySelector("#greet-form")?.addEventListener("submit", (e) => {
showNotes();
document.querySelector("#create-form")?.addEventListener("submit", (e) => {
e.preventDefault();
greet();
createNote();
showNotes();
});
document.querySelector("#show-notes-button")?.addEventListener("click", (e) => {
e.preventDefault();

6
src/model.ts Normal file
View File

@ -0,0 +1,6 @@
export type Note = {
id: Number,
content: String,
date: String,
tag: String;
};

View File

@ -84,6 +84,11 @@ button {
outline: none;
}
#show-notes-button {
max-width: 30%;
align-self: center;
}
#greet-input {
margin-right: 5px;
}