aboutsummaryrefslogtreecommitdiff
path: root/src-ui/src/main.ts
diff options
context:
space:
mode:
authorJeremy Chone <jeremy.chone@gmail.com>2022-06-20 12:43:09 -0700
committerJeremy Chone <jeremy.chone@gmail.com>2022-06-20 12:43:09 -0700
commit5ffb5c1d55397162a419945eb81b942fad6603fc (patch)
treee3ec46506ff1a94d939ef53ce018e10b29213df2 /src-ui/src/main.ts
parent051748771895bb040188221c3e4136878dbedb8a (diff)
downloadFlightCore-5ffb5c1d55397162a419945eb81b942fad6603fc.tar.gz
FlightCore-5ffb5c1d55397162a419945eb81b942fad6603fc.zip
. full code
Diffstat (limited to 'src-ui/src/main.ts')
-rw-r--r--src-ui/src/main.ts33
1 files changed, 32 insertions, 1 deletions
diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts
index aa31bb93..6492a32a 100644
--- a/src-ui/src/main.ts
+++ b/src-ui/src/main.ts
@@ -1,4 +1,35 @@
+import { invoke } from '@tauri-apps/api';
+import { Event as TauriEvent, listen } from '@tauri-apps/api/event';
+const $ = document.querySelector.bind(document);
document.addEventListener("DOMContentLoaded", async function () {
- document.body.textContent = "Hello from main.ts";
+ // get the elements
+ const helloEl = $("div.hello") as HTMLElement;
+ const counterButtonEl = $("counter-button") as HTMLElement;
+ const counterResultEl = $("counter-result") as HTMLElement;
+ const pingEl = $("backend-ping") as HTMLElement;
+
+ // listen backend-ping event
+ listen("backend-ping", function (evt: TauriEvent<any>) {
+ pingEl.classList.add("on");
+ setTimeout(function () {
+ pingEl.classList.remove("on")
+ }, 500);
+ })
+
+ // counter button click
+ counterButtonEl.addEventListener("pointerup", async function () {
+ const result = await invoke("add_count", { num: 3 }) as string;
+ counterResultEl.textContent = result;
+ });
+
+ // hello click
+ helloEl.addEventListener("pointerup", async function () {
+ const result = await invoke("hello_world") as string;
+ helloEl.textContent = result;
+ setTimeout(function () {
+ helloEl.textContent = "Click again";
+ }, 1000);
+ });
+
}); \ No newline at end of file