Fix the router and stub out a number of crates to get compiling

This commit is contained in:
Jonathan Kelley committed 2024-01-13 20:51:37 -08:00
1 parent 4c6e515da4
commit fae0b08e61
226 files changed
+1057 -1482

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ fn main() {
dioxus_web::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! (
div {
style: "text-align: center;",
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
align_content: "a",
+2 -2
View File
@@ -40,8 +40,8 @@ const RECT_STYLE: &str = r#"
text-aligh: center;
"#;
fn app(cx: Scope) -> Element {
let events = use_ref(cx, std::collections::VecDeque::new);
fn app() -> Element {
let events = use_ref(std::collections::VecDeque::new);
let log_event = move |event: Event| {
let mut events = events.write();
-73
View File
@@ -1,73 +0,0 @@
#![allow(non_snake_case)]
/*
Dioxus manages borrow lifetimes for you. This means any child may borrow from its parent. However, it is not possible
to hand out an &mut T to children - all props are consumed by &P, so you'd only get an &&mut T.
How does it work?
Dioxus will manually drop closures and props - things that borrow data before the component is ran again. This is done
"bottom up" from the lowest child all the way to the initiating parent. As it traverses each listener and prop, the
drop implementation is manually called, freeing any memory and ensuring that memory is not leaked.
We cannot drop from the parent to the children - if the drop implementation modifies the data, downstream references
might be broken since we take an &mut T and and &T to the data. Instead, we work bottom up, making sure to remove any
potential references to the data before finally giving out an &mut T. This prevents us from mutably aliasing the data,
and is proven to be safe with MIRI.
*/
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let text = cx.use_hook(|| vec![String::from("abc=def")]);
let first = text.get_mut(0).unwrap();
cx.render(rsx! {
div {
Child1 { text: first }
}
})
}
#[derive(Props)]
struct C1Props<'a> {
text: &'a mut String,
}
fn Child1<'a>(cx: Scope<'a, C1Props<'a>>) -> Element {
let (left, right) = cx.props.text.split_once('=').unwrap();
cx.render(rsx! {
div {
Child2 { text: left }
Child2 { text: right }
}
})
}
#[derive(Props)]
struct C2Props<'a> {
text: &'a str,
}
fn Child2<'a>(cx: Scope<'a, C2Props<'a>>) -> Element {
cx.render(rsx! {
Child3 { text: cx.props.text }
})
}
#[derive(Props)]
struct C3Props<'a> {
text: &'a str,
}
fn Child3<'a>(cx: Scope<'a, C3Props<'a>>) -> Element {
cx.render(rsx! {
div { "{cx.props.text}"}
})
}
+2 -2
View File
@@ -18,8 +18,8 @@ fn main() {
dioxus_desktop::launch_cfg(app, config);
}
fn app(cx: Scope) -> Element {
let val = use_state(cx, || String::from("0"));
fn app() -> Element {
let val = use_state(|| String::from("0"));
let input_digit = move |num: u8| {
if val.get() == "0" {
+2 -2
View File
@@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let login = use_callback!(cx, move |_| async move {
fn app() -> Element {
let login = use_callback!(move |_| async move {
let res = reqwest::get("https://dog.ceo/api/breeds/list/all")
.await
.unwrap()
+3 -3
View File
@@ -5,10 +5,10 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let mut count = use_signal(cx, || 0);
fn app() -> Element {
let mut count = use_signal(|| 0);
use_future!(cx, || async move {
use_future!(|| async move {
loop {
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
count += 1;
+4 -4
View File
@@ -7,10 +7,10 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let emails_sent = use_ref(cx, Vec::new);
fn app() -> Element {
let emails_sent = use_ref(Vec::new);
let tx = use_coroutine(cx, |mut rx: UnboundedReceiver<String>| {
let tx = use_coroutine(|mut rx: UnboundedReceiver<String>| {
to_owned![emails_sent];
async move {
while let Some(message) = rx.next().await {
@@ -48,7 +48,7 @@ struct ComposeProps {
}
fn compose(cx: Scope<ComposeProps>) -> Element {
let user_input = use_state(cx, String::new);
let user_input = use_state(String::new);
cx.render(rsx! {
div {
+4 -4
View File
@@ -6,11 +6,11 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let elements: &UseRef<Vec<Rc<MountedData>>> = use_ref(cx, Vec::new);
let running = use_state(cx, || true);
fn app() -> Element {
let elements: &UseRef<Vec<Rc<MountedData>>> = use_ref(Vec::new);
let running = use_state(|| true);
use_future!(cx, |(elements, running)| async move {
use_future!(|(elements, running)| async move {
let mut focused = 0;
if *running.current() {
loop {
+2 -2
View File
@@ -7,8 +7,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let counters = use_state(cx, || vec![0, 0, 0]);
fn app() -> Element {
let counters = use_state(|| vec![0, 0, 0]);
let sum: usize = counters.iter().copied().sum();
render! {
+11 -11
View File
@@ -27,8 +27,8 @@ pub struct Client {
type ClientContext = Vec<Client>;
#[component]
fn App(cx: Scope) -> Element {
use_shared_state_provider::<ClientContext>(cx, Default::default);
fn App() -> Element {
use_shared_state_provider::<ClientContext>(Default::default);
render! {
link {
@@ -53,8 +53,8 @@ fn App(cx: Scope) -> Element {
}
#[component]
fn ClientList(cx: Scope) -> Element {
let clients = use_shared_state::<ClientContext>(cx).unwrap();
fn ClientList() -> Element {
let clients = use_shared_state::<ClientContext>().unwrap();
cx.render(rsx! {
h2 { "List of Clients" }
@@ -75,11 +75,11 @@ fn ClientList(cx: Scope) -> Element {
}
#[component]
fn ClientAdd(cx: Scope) -> Element {
let clients = use_shared_state::<ClientContext>(cx).unwrap();
let first_name = use_state(cx, String::new);
let last_name = use_state(cx, String::new);
let description = use_state(cx, String::new);
fn ClientAdd() -> Element {
let clients = use_shared_state::<ClientContext>().unwrap();
let first_name = use_state(String::new);
let last_name = use_state(String::new);
let description = use_state(String::new);
cx.render(rsx! {
h2 { "Add new Client" }
@@ -142,8 +142,8 @@ fn ClientAdd(cx: Scope) -> Element {
}
#[component]
fn Settings(cx: Scope) -> Element {
let clients = use_shared_state::<ClientContext>(cx).unwrap();
fn Settings() -> Element {
let clients = use_shared_state::<ClientContext>().unwrap();
cx.render(rsx! {
h2 { "Settings" }
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
p {
+1 -1
View File
@@ -31,7 +31,7 @@ fn main() {
);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
h1 {"hello world!"}
+2 -2
View File
@@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let disabled = use_state(cx, || false);
fn app() -> Element {
let disabled = use_state(|| false);
cx.render(rsx! {
div {
+4 -4
View File
@@ -12,9 +12,9 @@ struct ListBreeds {
#[component]
fn AppRoot(cx: Scope<'_>) -> Element {
let breed = use_state(cx, || "deerhound".to_string());
let breed = use_state(|| "deerhound".to_string());
let breeds = use_future!(cx, || async move {
let breeds = use_future!(|| async move {
reqwest::get("https://dog.ceo/api/breeds/list/all")
.await
.unwrap()
@@ -51,8 +51,8 @@ struct DogApi {
}
#[component]
fn BreedPic(cx: Scope, breed: String) -> Element {
let fut = use_future!(cx, |breed| async move {
fn BreedPic(breed: String) -> Element {
let fut = use_future!(|breed| async move {
reqwest::get(format!("https://dog.ceo/api/breed/{breed}/images/random"))
.await
.unwrap()
+2 -2
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
let count = if cx.generation() % 2 == 0 { 10 } else { 0 };
println!("Generation: {}", cx.generation());
@@ -20,7 +20,7 @@ fn app(cx: Scope) -> Element {
}
}
fn drop_child(cx: Scope) -> Element {
fn drop_child() -> Element {
cx.use_hook(|| Drops);
render! {
div{}
+2 -2
View File
@@ -5,8 +5,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
use_asset_handler(cx, "logos", |request, response| {
fn app() -> Element {
use_asset_handler("logos", |request, response| {
// Note that the "logos" prefix is stripped from the URI
//
// However, the asset is absolute to its "virtual folder" - meaning it starts with a leading slash
+2 -2
View File
@@ -5,7 +5,7 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
cx.render(rsx! {
ErrorBoundary {
handle_error: |error: CapturedError| rsx! {"Found error {error}"},
@@ -17,7 +17,7 @@ fn App(cx: Scope) -> Element {
}
#[component]
fn DemoC(cx: Scope, x: i32) -> Element {
fn DemoC(x: i32) -> Element {
let result = Err("Error");
result.throw()?;
+2 -2
View File
@@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let future = use_future(cx, (), |_| async move {
fn app() -> Element {
let future = use_future((), |_| async move {
let eval = eval(
r#"
dioxus.send("Hi from JS!");
+6 -6
View File
@@ -9,9 +9,9 @@ fn main() {
static NAME: Atom<String> = Atom(|_| "world".to_string());
fn app(cx: Scope) -> Element {
fn app() -> Element {
use_init_atom_root(cx);
let name = use_read(cx, &NAME);
let name = use_read(&NAME);
cx.render(rsx! {
div { "hello {name}!" }
@@ -20,8 +20,8 @@ fn app(cx: Scope) -> Element {
})
}
fn Child(cx: Scope) -> Element {
let set_name = use_set(cx, &NAME);
fn Child() -> Element {
let set_name = use_set(&NAME);
cx.render(rsx! {
button {
@@ -33,8 +33,8 @@ fn Child(cx: Scope) -> Element {
static NAMES: AtomRef<Vec<String>> = AtomRef(|_| vec!["world".to_string()]);
fn ChildWithRef(cx: Scope) -> Element {
let names = use_atom_ref(cx, &NAMES);
fn ChildWithRef() -> Element {
let names = use_atom_ref(&NAMES);
cx.render(rsx! {
div {
+2 -2
View File
@@ -20,8 +20,8 @@ fn main() {
const _STYLE: &str = manganis::mg!(file("./examples/assets/fileexplorer.css"));
fn app(cx: Scope) -> Element {
let files = use_ref(cx, Files::new);
fn app() -> Element {
let files = use_ref(Files::new);
cx.render(rsx! {
div {
+3 -3
View File
@@ -7,9 +7,9 @@ fn main() {
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
let enable_directory_upload = use_state(cx, || false);
let files_uploaded: &UseRef<Vec<String>> = use_ref(cx, Vec::new);
fn App() -> Element {
let enable_directory_upload = use_state(|| false);
let files_uploaded: &UseRef<Vec<String>> = use_ref(Vec::new);
cx.render(rsx! {
label {
+1 -1
View File
@@ -10,7 +10,7 @@ fn main() {
dioxus_desktop::launch_with_props(app, (), cfg);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx!(
div {
h1 { "drag a file here and check your console" }
+6 -6
View File
@@ -15,7 +15,7 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
render! {
Router::<Route> {}
}
@@ -36,7 +36,7 @@ enum Route {
}
#[component]
fn Footer(cx: Scope) -> Element {
fn Footer() -> Element {
render! {
div {
Outlet::<Route> { }
@@ -58,21 +58,21 @@ fn Footer(cx: Scope) -> Element {
}
#[component]
fn Home(cx: Scope) -> Element {
fn Home() -> Element {
render!("Home")
}
#[component]
fn Games(cx: Scope) -> Element {
fn Games() -> Element {
render!("Games")
}
#[component]
fn Play(cx: Scope) -> Element {
fn Play() -> Element {
render!("Play")
}
#[component]
fn Settings(cx: Scope) -> Element {
fn Settings() -> Element {
render!("Settings")
}
+1 -1
View File
@@ -9,7 +9,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
h1 { "Form" }
+4 -4
View File
@@ -31,9 +31,9 @@ impl Label {
}
}
fn app(cx: Scope) -> Element {
let items = use_ref(cx, Vec::new);
let selected = use_state(cx, || None);
fn app() -> Element {
let items = use_ref(Vec::new);
let selected = use_state(|| None);
cx.render(rsx! {
div { class: "container",
@@ -97,7 +97,7 @@ struct ActionButtonProps<'a> {
onclick: EventHandler<'a>,
}
fn ActionButton<'a>(cx: Scope<'a, ActionButtonProps<'a>>) -> Element {
fn ActionButton(props: ActionButtonProps) -> Element {
cx.render(rsx! {
div {
class: "col-sm-6 smallpad",
+1 -1
View File
@@ -6,7 +6,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
render! {
generic_child { data: 0 }
}
+1 -1
View File
@@ -13,7 +13,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
// This is discouraged
std::thread::sleep(std::time::Duration::from_millis(2_000));
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
render! {
div { "Hello, world!" }
}
+2 -2
View File
@@ -20,8 +20,8 @@ fn main() {
dioxus_desktop::launch_cfg(app, Config::new().with_prerendered(content));
}
fn app(cx: Scope) -> Element {
let val = use_state(cx, || 0);
fn app() -> Element {
let val = use_state(|| 0);
cx.render(rsx! {
div {
+6 -6
View File
@@ -5,22 +5,22 @@
use dioxus::prelude::*;
#[component]
fn Thing1<T>(cx: Scope, _a: T) -> Element {
fn Thing1<T>(_a: T) -> Element {
cx.render(rsx! { "" })
}
#[component]
fn Thing2(cx: Scope, _a: u32) -> Element<'a> {
fn Thing2(_a: u32) -> Element {
cx.render(rsx! { "" })
}
#[component]
fn Thing3<'a, T>(cx: Scope<'a>, _a: &'a T) -> Element<'a> {
fn Thing3<'a, T>(cx: Scope<'a>, _a: &'a T) -> Element {
cx.render(rsx! { "" })
}
#[component]
fn Thing4<'a>(cx: Scope<'a>, _a: &'a u32) -> Element<'a> {
fn Thing4<'a>(cx: Scope<'a>, _a: &'a u32) -> Element {
cx.render(rsx! { "" })
}
@@ -29,8 +29,8 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
let state = use_state(cx, || 1);
fn App() -> Element {
let state = use_state(|| 1);
cx.render(rsx! {
div {
+2 -2
View File
@@ -34,7 +34,7 @@ const FIELDS: &[(&str, &str)] = &[
("week", ""), // degrades to text most of the time
];
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div { margin_left: "30px",
{select_example(cx)},
@@ -136,7 +136,7 @@ fn app(cx: Scope) -> Element {
})
}
fn select_example(cx: Scope) -> Element {
fn select_example() -> Element {
cx.render(rsx! {
div {
select {
+4 -4
View File
@@ -6,7 +6,7 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
cx.render(rsx! (
div {
p {
@@ -38,7 +38,7 @@ enum Route {
}
#[component]
fn Header(cx: Scope) -> Element {
fn Header() -> Element {
render! {
h1 { "Your app here" }
ul {
@@ -50,11 +50,11 @@ fn Header(cx: Scope) -> Element {
}
#[component]
fn Home(cx: Scope) -> Element {
fn Home() -> Element {
render!(h1 { "Home" })
}
#[component]
fn Settings(cx: Scope) -> Element {
fn Settings() -> Element {
render!(h1 { "Settings" })
}
+1 -1
View File
@@ -7,7 +7,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
let onsubmit = move |evt: FormEvent| async move {
let resp = reqwest::Client::new()
.post("http://localhost:8080/login")
+1 -1
View File
@@ -59,7 +59,7 @@ pub fn main() -> Result<()> {
Ok(())
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
let items = cx.use_hook(|| vec![1, 2, 3]);
log::debug!("Hello from the app");
+2 -2
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
button {
@@ -18,7 +18,7 @@ fn app(cx: Scope) -> Element {
})
}
fn popup(cx: Scope) -> Element {
fn popup() -> Element {
cx.render(rsx! {
div { "This is a popup!" }
})
+1 -1
View File
@@ -10,7 +10,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
onclick: move |_| println!("clicked! top"),
+3 -3
View File
@@ -30,14 +30,14 @@ pub static DIOXUS_FRONT_ISSUER_URL: &str = env!("DIOXUS_FRONT_ISSUER_URL");
pub static DIOXUS_FRONT_CLIENT_ID: &str = env!("DIOXUS_FRONT_CLIENT_ID");
pub static DIOXUS_FRONT_URL: &str = env!("DIOXUS_FRONT_URL");
fn App(cx: Scope) -> Element {
fn App() -> Element {
use_init_atom_root(cx);
// Retrieve the value stored in the browser's storage
let stored_auth_token = LocalStorage::get(DIOXUS_FRONT_AUTH_TOKEN)
.ok()
.unwrap_or(AuthTokenState::default());
let fermi_auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN);
let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
if fermi_auth_token.read().is_none() {
*fermi_auth_token.write() = Some(stored_auth_token);
}
@@ -45,7 +45,7 @@ fn App(cx: Scope) -> Element {
let stored_auth_request = LocalStorage::get(DIOXUS_FRONT_AUTH_REQUEST)
.ok()
.unwrap_or(AuthRequestState::default());
let fermi_auth_request = use_atom_ref(cx, &FERMI_AUTH_REQUEST);
let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
if fermi_auth_request.read().is_none() {
*fermi_auth_request.write() = Some(stored_auth_request);
}
@@ -15,9 +15,9 @@ use openidconnect::{url::Url, OAuth2TokenResponse, TokenResponse};
#[component]
pub fn LogOut(cx: Scope<ClientProps>) -> Element {
let fermi_auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN);
let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
let fermi_auth_token_read = fermi_auth_token.read().clone();
let log_out_url_state = use_state(cx, || None::<Option<Result<Url, crate::errors::Error>>>);
let log_out_url_state = use_state(|| None::<Option<Result<Url, crate::errors::Error>>>);
cx.render(match fermi_auth_token_read {
Some(fermi_auth_token_read) => match fermi_auth_token_read.id_token.clone() {
Some(id_token) => match log_out_url_state.get() {
@@ -76,8 +76,8 @@ pub fn LogOut(cx: Scope<ClientProps>) -> Element {
#[component]
pub fn RefreshToken(cx: Scope<ClientProps>) -> Element {
let fermi_auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN);
let fermi_auth_request = use_atom_ref(cx, &FERMI_AUTH_REQUEST);
let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
let fermi_auth_token_read = fermi_auth_token.read().clone();
cx.render(match fermi_auth_token_read {
Some(fermi_auth_client_read) => match fermi_auth_client_read.refresh_token {
@@ -128,9 +128,9 @@ pub fn RefreshToken(cx: Scope<ClientProps>) -> Element {
}
#[component]
pub fn LoadClient(cx: Scope) -> Element {
let init_client_future = use_future(cx, (), |_| async move { init_oidc_client().await });
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(cx, &FERMI_CLIENT);
pub fn LoadClient() -> Element {
let init_client_future = use_future((), |_| async move { init_oidc_client().await });
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(&FERMI_CLIENT);
cx.render(match init_client_future.value() {
Some(client_props) => match client_props {
Ok((client_id, client)) => {
@@ -162,10 +162,10 @@ pub fn LoadClient(cx: Scope) -> Element {
}
#[component]
pub fn AuthHeader(cx: Scope) -> Element {
let auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN);
let fermi_auth_request = use_atom_ref(cx, &FERMI_AUTH_REQUEST);
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(cx, &FERMI_CLIENT);
pub fn AuthHeader() -> Element {
let auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(&FERMI_CLIENT);
let client = fermi_client.read().oidc_client.clone();
let auth_request_read = fermi_auth_request.read().clone();
let auth_token_read = auth_token.read().clone();
@@ -1,5 +1,5 @@
use dioxus::prelude::*;
pub fn Home(cx: Scope) -> Element {
pub fn Home() -> Element {
render! { div { "Hello world" } }
}
@@ -10,11 +10,11 @@ use fermi::*;
use openidconnect::{OAuth2TokenResponse, TokenResponse};
#[component]
pub fn Login(cx: Scope, query_string: String) -> Element {
let fermi_client = use_atom_ref(cx, &FERMI_CLIENT);
let fermi_auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN);
pub fn Login(query_string: String) -> Element {
let fermi_client = use_atom_ref(&FERMI_CLIENT);
let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
let home_url: NavigationTarget<Route> = DIOXUS_FRONT_URL.parse().unwrap();
let fermi_auth_request = use_atom_ref(cx, &FERMI_AUTH_REQUEST);
let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
let client = fermi_client.read().oidc_client.clone();
let auth_token_read = fermi_auth_token.read().clone();
cx.render(match (client, auth_token_read) {
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
#[component]
pub fn NotFound(cx: Scope, route: Vec<String>) -> Element {
pub fn NotFound(route: Vec<String>) -> Element {
render! {
div{
{route.join("")}
+1 -1
View File
@@ -10,7 +10,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
Button {
a: "asd".to_string(),
+1 -1
View File
@@ -5,7 +5,7 @@ fn main() {
dioxus_desktop::launch_cfg(app, make_config());
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
width: "100%",
+7 -7
View File
@@ -37,8 +37,8 @@ fn main() {
const STYLE: &str = include_str!("./assets/calculator.css");
fn app(cx: Scope) -> Element {
let state = use_ref(cx, Calculator::new);
fn app() -> Element {
let state = use_ref(Calculator::new);
cx.render(rsx! {
style { {STYLE} }
@@ -121,13 +121,13 @@ fn app(cx: Scope) -> Element {
}
#[derive(Props)]
struct CalculatorKeyProps<'a> {
name: &'a str,
onclick: EventHandler<'a, MouseEvent>,
children: Element<'a>,
struct CalculatorKeyProps {
name: String,
onclick: EventHandler<MouseEvent>,
children: Element,
}
fn CalculatorKey<'a>(cx: Scope<'a, CalculatorKeyProps<'a>>) -> Element {
fn CalculatorKey(props: CalculatorKeyProps) -> Element {
cx.render(rsx! {
button {
class: "calculator-key {cx.props.name}",
+2 -2
View File
@@ -14,8 +14,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let state = use_state(cx, PlayerState::new);
fn app() -> Element {
let state = use_state(PlayerState::new);
cx.render(rsx!(
div {
+3 -3
View File
@@ -63,7 +63,7 @@ impl FromQuery for ManualBlogQuerySegments {
}
#[component]
fn BlogPost(cx: Scope, query_params: ManualBlogQuerySegments) -> Element {
fn BlogPost(query_params: ManualBlogQuerySegments) -> Element {
render! {
div{"This is your blogpost with a query segment:"}
div{ "{query_params:?}" }
@@ -71,7 +71,7 @@ fn BlogPost(cx: Scope, query_params: ManualBlogQuerySegments) -> Element {
}
#[component]
fn AutomaticBlogPost(cx: Scope, name: String, surname: String) -> Element {
fn AutomaticBlogPost(name: String, surname: String) -> Element {
render! {
div{"This is your blogpost with a query segment:"}
div{ "name={name}&surname={surname}" }
@@ -79,7 +79,7 @@ fn AutomaticBlogPost(cx: Scope, name: String, surname: String) -> Element {
}
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
render! { Router::<Route>{} }
}
+3 -3
View File
@@ -25,10 +25,10 @@ fn main() {
);
}
fn app(cx: Scope) -> Element {
let div_element: &UseRef<Option<Rc<MountedData>>> = use_ref(cx, || None);
fn app() -> Element {
let div_element: &UseRef<Option<Rc<MountedData>>> = use_ref(|| None);
let dimentions = use_ref(cx, Rect::zero);
let dimentions = use_ref(Rect::zero);
cx.render(rsx!(
div {
+2 -2
View File
@@ -8,8 +8,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let mut count = use_state(cx, || 0);
fn app() -> Element {
let mut count = use_state(|| 0);
cx.render(rsx! {
h1 { "High-Five counter: {count}" }
+7 -7
View File
@@ -36,14 +36,14 @@ enum Route {
// ANCHOR_END: router
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
render! {
Router::<Route> {}
}
}
#[component]
fn NavBar(cx: Scope) -> Element {
fn NavBar() -> Element {
render! {
nav {
ul {
@@ -56,14 +56,14 @@ fn NavBar(cx: Scope) -> Element {
}
#[component]
fn Home(cx: Scope) -> Element {
fn Home() -> Element {
render! {
h1 { "Welcome to the Dioxus Blog!" }
}
}
#[component]
fn Blog(cx: Scope) -> Element {
fn Blog() -> Element {
render! {
h1 { "Blog" }
Outlet::<Route> {}
@@ -71,7 +71,7 @@ fn Blog(cx: Scope) -> Element {
}
#[component]
fn BlogList(cx: Scope) -> Element {
fn BlogList() -> Element {
render! {
h2 { "Choose a post" }
ul {
@@ -92,14 +92,14 @@ fn BlogList(cx: Scope) -> Element {
}
#[component]
fn BlogPost(cx: Scope, name: String) -> Element {
fn BlogPost(name: String) -> Element {
render! {
h2 { "Blog Post: {name}"}
}
}
#[component]
fn PageNotFound(cx: Scope, route: Vec<String>) -> Element {
fn PageNotFound(route: Vec<String>) -> Element {
render! {
h1 { "Page not found" }
p { "We are terribly sorry, but the page you requested doesn't exist." }
+4 -4
View File
@@ -12,15 +12,15 @@ fn main() {
renderer.render(&vdom);
}
fn example(cx: Scope) -> Element {
let items = use_state(cx, || {
fn example() -> Element {
let items = use_state(|| {
vec![Thing {
a: "asd".to_string(),
b: 10,
}]
});
let things = use_ref(cx, || {
let things = use_ref(|| {
vec![Thing {
a: "asd".to_string(),
b: 10,
@@ -28,7 +28,7 @@ fn example(cx: Scope) -> Element {
});
let things_list = things.read();
let mything = use_ref(cx, || Some(String::from("asd")));
let mything = use_ref(|| Some(String::from("asd")));
let mything_read = mything.read();
cx.render(rsx!(
+8 -8
View File
@@ -49,7 +49,7 @@ use baller::Baller;
use dioxus::prelude::*;
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
let formatting = "formatting!";
let formatting_tuple = ("a", "b");
let lazy_fmt = format_args!("lazily formatted text");
@@ -205,7 +205,7 @@ fn App(cx: Scope) -> Element {
// helper functions
// Anything that implements IntoVnode can be dropped directly into Rsx
{helper(cx, "hello world!")}
{helper("hello world!")}
// Strings can be supplied directly
{String::from("Hello world!")}
@@ -223,7 +223,7 @@ fn format_dollars(dollars: u32, cents: u32) -> String {
format!("${dollars}.{cents:02}")
}
fn helper<'a>(cx: &'a ScopeState, text: &'a str) -> Element<'a> {
fn helper<'a>(cx: &'a ScopeState, text: &'a str) -> Element {
cx.render(rsx! {
p { "{text}" }
})
@@ -233,7 +233,7 @@ fn helper<'a>(cx: &'a ScopeState, text: &'a str) -> Element<'a> {
// This will likely be deprecated/removed in a future update that will introduce a more polished linting system,
// something like Clippy.
#[component(no_case_check)]
fn lowercase_helper(cx: Scope) -> Element {
fn lowercase_helper() -> Element {
cx.render(rsx! {
"asd"
})
@@ -254,7 +254,7 @@ mod baller {
// This will likely be deprecated/removed in a future update that will introduce a more polished linting system,
// something like Clippy.
#[component(no_case_check)]
pub fn lowercase_component(cx: Scope) -> Element {
pub fn lowercase_component() -> Element {
cx.render(rsx! { "look ma, no uppercase" })
}
}
@@ -263,12 +263,12 @@ mod baller {
pub struct TallerProps<'a> {
/// Fields are documented and accessible in rsx!
a: &'static str,
children: Element<'a>,
children: Element,
}
/// Documention for this component is visible within the rsx macro
#[component]
pub fn Taller<'a>(cx: Scope<'a, TallerProps<'a>>) -> Element {
pub fn Taller(props: TallerProps -> Element {
cx.render(rsx! {
{&cx.props.children}
})
@@ -297,7 +297,7 @@ fn WithInline<'a>(cx: Scope<'a>, text: &'a str) -> Element {
}
#[component]
fn Label<T>(cx: Scope, text: T) -> Element
fn Label<T>(text: T) -> Element
where
T: Display,
{
+2 -2
View File
@@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let header_element = use_ref(cx, || None);
fn app() -> Element {
let header_element = use_ref(|| None);
cx.render(rsx!(
div {
+6 -6
View File
@@ -27,8 +27,8 @@ impl CoolData {
#[component]
#[rustfmt::skip]
pub fn App(cx: Scope) -> Element {
use_shared_state_provider(cx, || CoolData::new(HashMap::from([
pub fn App() -> Element {
use_shared_state_provider(|| CoolData::new(HashMap::from([
(0, "Hello, World!".to_string()),
(1, "Dioxus is amazing!".to_string())
])));
@@ -50,8 +50,8 @@ pub fn App(cx: Scope) -> Element {
}
#[component]
fn DataEditor(cx: Scope, id: usize) -> Element {
let data = use_shared_state::<CoolData>(cx)?;
fn DataEditor(id: usize) -> Element {
let data = use_shared_state::<CoolData>()?;
render! {
p {
@@ -61,8 +61,8 @@ fn DataEditor(cx: Scope, id: usize) -> Element {
}
#[component]
fn DataView(cx: Scope, id: usize) -> Element {
let data = use_shared_state::<CoolData>(cx)?;
fn DataView(id: usize) -> Element {
let data = use_shared_state::<CoolData>()?;
render! {
input {
+3 -3
View File
@@ -5,10 +5,10 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let toggled = use_state(cx, || false);
fn app() -> Element {
let toggled = use_state(|| false);
use_global_shortcut(cx, "ctrl+s", {
use_global_shortcut("ctrl+s", {
to_owned![toggled];
move || toggled.modify(|t| !*t)
});
+2 -2
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
let a = 123;
let b = 456;
let c = 789;
@@ -30,7 +30,7 @@ fn Component<'a>(
a: i32,
b: i32,
c: i32,
children: Element<'a>,
children: Element,
onclick: EventHandler<'a, ()>,
) -> Element {
render! {
+5 -5
View File
@@ -5,14 +5,14 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let running = dioxus_signals::use_signal(cx, || true);
let mut count = dioxus_signals::use_signal(cx, || 0);
let saved_values = dioxus_signals::use_signal(cx, || vec![0.to_string()]);
fn app() -> Element {
let running = dioxus_signals::use_signal(|| true);
let mut count = dioxus_signals::use_signal(|| 0);
let saved_values = dioxus_signals::use_signal(|| vec![0.to_string()]);
// Signals can be used in async functions without an explicit clone since they're 'static and Copy
// Signals are backed by a runtime that is designed to deeply integrate with Dioxus apps
use_future!(cx, || async move {
use_future!(|| async move {
loop {
if running.value() {
count += 1;
+6 -6
View File
@@ -13,7 +13,7 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
render! {
Router::<Route> {}
}
@@ -38,7 +38,7 @@ enum Route {
}
#[component]
fn NavBar(cx: Scope) -> Element {
fn NavBar() -> Element {
render! {
h1 { "Your app here" }
ul {
@@ -53,19 +53,19 @@ fn NavBar(cx: Scope) -> Element {
}
#[component]
fn Home(cx: Scope) -> Element {
fn Home() -> Element {
log::debug!("rendering home {:?}", cx.scope_id());
render! { h1 { "Home" } }
}
#[component]
fn BlogList(cx: Scope) -> Element {
fn BlogList() -> Element {
log::debug!("rendering blog list {:?}", cx.scope_id());
render! { div { "Blog List" } }
}
#[component]
fn BlogPost(cx: Scope, post: String) -> Element {
fn BlogPost(post: String) -> Element {
log::debug!("rendering blog post {}", post);
render! {
@@ -77,6 +77,6 @@ fn BlogPost(cx: Scope, post: String) -> Element {
}
#[component]
fn Oranges(cx: Scope) -> Element {
fn Oranges() -> Element {
render!("Oranges are not apples!")
}
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx!(
div {
// Use Map directly to lazily pull elements
+3 -3
View File
@@ -13,12 +13,12 @@ enum Route {
}
#[component]
fn Homepage(cx: Scope) -> Element {
fn Homepage() -> Element {
render! { h1 { "Welcome home" } }
}
#[component]
fn Blog(cx: Scope, id: String) -> Element {
fn Blog(id: String) -> Element {
render! {
h1 { "How to make: " }
p { "{id}" }
@@ -26,7 +26,7 @@ fn Blog(cx: Scope, id: String) -> Element {
}
#[component]
fn Nav(cx: Scope) -> Element {
fn Nav() -> Element {
render! {
nav {
li { Link { to: Route::Homepage { }, "Go home" } }
+2 -2
View File
@@ -8,7 +8,7 @@ fn main() {
println!("{}", html);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
render! {
Component {
width: "10px",
@@ -21,7 +21,7 @@ fn app(cx: Scope) -> Element {
}
#[component]
fn Component<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
fn Component(props: Props -> Element {
render! {
audio { ..cx.props.attributes, "1: {cx.props.extra_data}\n2: {cx.props.extra_data2}" }
}
+1 -1
View File
@@ -30,7 +30,7 @@ fn main() {
println!("{file}");
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx!(
div {
h1 { "Title" }
+3 -3
View File
@@ -7,10 +7,10 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let count = use_signal(cx, || 10);
fn app() -> Element {
let count = use_signal(|| 10);
use_future(cx, (), |_| async move {
use_future((), |_| async move {
let mut stream = some_stream();
while let Some(second) = stream.next().await {
+3 -3
View File
@@ -31,7 +31,7 @@ struct DogApi {
message: String,
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
h1 {"Dogs are very important"}
@@ -52,8 +52,8 @@ fn app(cx: Scope) -> Element {
/// This component will re-render when the future has finished
/// Suspense is achieved my moving the future into only the component that
/// actually renders the data.
fn Doggo(cx: Scope) -> Element {
let fut = use_future(cx, (), |_| async move {
fn Doggo() -> Element {
let fut = use_future((), |_| async move {
reqwest::get("https://dog.ceo/api/breeds/image/random/")
.await
.unwrap()
+3 -3
View File
@@ -6,8 +6,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let val = use_state(cx, || 5);
fn app() -> Element {
let val = use_state(|| 5);
cx.render(rsx! {
div {
@@ -58,7 +58,7 @@ const UNHELD_COLOR: &str = "#ddd";
// A six-sided die (D6) with dots.
#[allow(non_snake_case)]
pub fn Die<'a>(cx: Scope<'a, DieProps<'a>>) -> Element {
pub fn Die(props: DieProps -> Element {
let &DieProps { value, keep, .. } = cx.props;
let active_dots = &DOTS_FOR_VALUE[(value - 1) as usize];
+1 -1
View File
@@ -1,6 +1,6 @@
use dioxus::prelude::*;
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx!( svg {
width: "200",
height: "250",
+3 -3
View File
@@ -11,7 +11,7 @@ fn main() {
dioxus_web::launch(app);
}
pub fn app(cx: Scope) -> Element {
pub fn app() -> Element {
let grey_background = true;
cx.render(rsx!(
div {
@@ -78,7 +78,7 @@ pub fn app(cx: Scope) -> Element {
))
}
pub fn StacksIcon(cx: Scope) -> Element {
pub fn StacksIcon() -> Element {
cx.render(rsx!(
svg {
fill: "none",
@@ -93,7 +93,7 @@ pub fn StacksIcon(cx: Scope) -> Element {
))
}
pub fn RightArrowIcon(cx: Scope) -> Element {
pub fn RightArrowIcon() -> Element {
cx.render(rsx!(
svg {
fill: "none",
+3 -3
View File
@@ -9,10 +9,10 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let count = use_state(cx, || 0);
fn app() -> Element {
let count = use_state(|| 0);
use_future(cx, (), move |_| {
use_future((), move |_| {
let mut count = count.clone();
async move {
loop {
+2 -2
View File
@@ -6,8 +6,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let model = use_state(cx, || String::from("asd"));
fn app() -> Element {
let model = use_state(|| String::from("asd"));
println!("{model}");
+9 -9
View File
@@ -22,8 +22,8 @@ pub struct TodoItem {
}
pub fn app(cx: Scope<()>) -> Element {
let todos = use_state(cx, im_rc::HashMap::<u32, TodoItem>::default);
let filter = use_state(cx, || FilterState::All);
let todos = use_state(im_rc::HashMap::<u32, TodoItem>::default);
let filter = use_state(|| FilterState::All);
// Filter the todos based on the filter state
let mut filtered_todos = todos
@@ -94,9 +94,9 @@ pub struct TodoHeaderProps<'a> {
todos: &'a UseState<im_rc::HashMap<u32, TodoItem>>,
}
pub fn TodoHeader<'a>(cx: Scope<'a, TodoHeaderProps<'a>>) -> Element {
let draft = use_state(cx, || "".to_string());
let todo_id = use_state(cx, || 0);
pub fn TodoHeader(props: TodoHeaderProps -> Element {
let draft = use_state(|| "".to_string());
let todo_id = use_state(|| 0);
cx.render(rsx! {
header { class: "header",
@@ -137,8 +137,8 @@ pub struct TodoEntryProps<'a> {
id: u32,
}
pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
let is_editing = use_state(cx, || false);
pub fn TodoEntry(props: TodoEntryProps -> Element {
let is_editing = use_state(|| false);
let todos = cx.props.todos.get();
let todo = &todos[&cx.props.id];
@@ -199,7 +199,7 @@ pub struct ListFooterProps<'a> {
filter: &'a UseState<FilterState>,
}
pub fn ListFooter<'a>(cx: Scope<'a, ListFooterProps<'a>>) -> Element {
pub fn ListFooter(props: ListFooterProps -> Element {
let active_todo_count = cx.props.active_todo_count;
let active_todo_text = cx.props.active_todo_text;
@@ -245,7 +245,7 @@ pub fn ListFooter<'a>(cx: Scope<'a, ListFooterProps<'a>>) -> Element {
})
}
pub fn PageFooter(cx: Scope) -> Element {
pub fn PageFooter() -> Element {
cx.render(rsx! {
footer { class: "info",
p { "Double-click to edit a todo" }
+2 -2
View File
@@ -29,8 +29,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
use_asset_handler(cx, "videos", move |request, responder| {
fn app() -> Element {
use_asset_handler("videos", move |request, responder| {
// Using dioxus::spawn works, but is slower than a dedicated thread
tokio::task::spawn(async move {
let video_file = PathBuf::from(VIDEO_PATH);
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
web-component {
"my-prop": "5%",
+4 -4
View File
@@ -11,16 +11,16 @@ fn main() {
dioxus_desktop::launch_cfg(app, cfg);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
let window = dioxus_desktop::use_window(cx);
// if you want to make window fullscreen, you need close the resizable.
// window.set_fullscreen(true);
// window.set_resizable(false);
let fullscreen = use_state(cx, || false);
let always_on_top = use_state(cx, || false);
let decorations = use_state(cx, || false);
let fullscreen = use_state(|| false);
let always_on_top = use_state(|| false);
let decorations = use_state(|| false);
cx.render(rsx!(
link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" }
+3 -3
View File
@@ -10,10 +10,10 @@ fn main() {
dioxus_desktop::launch_cfg(app, cfg);
}
fn app(cx: Scope) -> Element {
let focused = use_state(cx, || false);
fn app() -> Element {
let focused = use_state(|| false);
use_wry_event_handler(cx, {
use_wry_event_handler({
to_owned![focused];
move |event, _| {
if let WryEvent::WindowEvent {
+2 -2
View File
@@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let level = use_state(cx, || 1.0);
fn app() -> Element {
let level = use_state(|| 1.0);
cx.render(rsx! {
input {
+2 -4
View File
@@ -8,10 +8,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let contents = use_state(cx, || {
String::from("<script>alert(\"hello world\")</script>")
});
fn app() -> Element {
let contents = use_state(|| String::from("<script>alert(\"hello world\")</script>"));
cx.render(rsx! {
div {