From cdad6dd9ece6534bd60684dc7c08ce9620f19d39 Mon Sep 17 00:00:00 2001 From: Max Coppen <44031065+mxcop@users.noreply.github.com> Date: Wed, 2 Nov 2022 22:45:45 +0100 Subject: [PATCH] wip: working example page --- examples/api/src/main.rs | 2 +- examples/api/src/views/mod.rs | 4 ++ examples/api/src/views/updater.rs | 63 +++++++++++++++---------------- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/examples/api/src/main.rs b/examples/api/src/main.rs index c8a2ebc..6d1e97b 100644 --- a/examples/api/src/main.rs +++ b/examples/api/src/main.rs @@ -18,7 +18,7 @@ fn Header(cx: Scope) -> View { "Clipboard" } a(href="/updater") { - "Updater" + "Updater" } a(href="/communication") { "Communication" diff --git a/examples/api/src/views/mod.rs b/examples/api/src/views/mod.rs index 88f6dca..441b135 100644 --- a/examples/api/src/views/mod.rs +++ b/examples/api/src/views/mod.rs @@ -1,6 +1,7 @@ mod app; mod clipboard; mod communication; +mod updater; mod welcome; use sycamore::view::View; @@ -15,6 +16,8 @@ pub enum Page { Clipboard, #[to("/communication")] Communication, + #[to("/updater")] + Updater, #[not_found] NotFound } @@ -24,6 +27,7 @@ pub fn switch(cx: Scope, route: &ReadSignal) -> View { Page::App => app::App(cx), Page::Clipboard => clipboard::Clipboard(cx), Page::Communication => communication::Communication(cx), + Page::Updater => updater::Updater(cx), Page::NotFound => welcome::Welcome(cx) } } \ No newline at end of file diff --git a/examples/api/src/views/updater.rs b/examples/api/src/views/updater.rs index 53c844c..b022248 100644 --- a/examples/api/src/views/updater.rs +++ b/examples/api/src/views/updater.rs @@ -3,43 +3,40 @@ use tauri_sys::clipboard::{read_text, write_text}; #[component] pub fn Updater(cx: Scope) -> View { - // let text = create_signal(cx, "clipboard message".to_string()); + let text = create_signal(cx, "clipboard message".to_string()); - // let write = move |_| { - // sycamore::futures::spawn_local_scoped(cx, async move { - // write_text(&text.get()).await - // // .then(() => { - // // onMessage('Wrote to the clipboard') - // // }) - // // .catch(onMessage) - // }); - // }; + let write = move |_| { + sycamore::futures::spawn_local_scoped(cx, async move { + write_text(&text.get()).await + // .then(() => { + // onMessage('Wrote to the clipboard') + // }) + // .catch(onMessage) + }); + }; - // let read = |_| { - // sycamore::futures::spawn_local(async move { - // let text = read_text().await; + let read = |_| { + sycamore::futures::spawn_local(async move { + let text = read_text().await; - // log::info!("Read text from clipboard {:?}", text); - // // readText() - // // .then((contents) => { - // // onMessage(`Clipboard contents: ${contents}`) - // // }) - // // .catch(onMessage) - // }); - // }; + log::info!("Read text from clipboard {:?}", text); + // readText() + // .then((contents) => { + // onMessage(`Clipboard contents: ${contents}`) + // }) + // .catch(onMessage) + }); + }; - // view! { cx, - // div(class="flex gap-1") { - // input(class="grow input",placeholder="Text to write to the clipboard",bind:value=text) - // button(class="btn",type="button",on:click=write) { - // "Write" - // } - // button(class="btn",type="button",on:click=read) { - // "Read" - // } - // } - // } view! { cx, - div(class="updater") { } + div(class="flex gap-1") { + input(class="grow input",placeholder="Text to write to the clipboard",bind:value=text) + button(class="btn",type="button",on:click=write) { + "Write" + } + button(class="btn",type="button",on:click=read) { + "Read" + } + } } }