weather_app.rs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //! Example: Weather App
  2. //! --------------------
  3. //!
  4. //!
  5. //!
  6. use dioxus::prelude::*;
  7. fn main() {
  8. dioxus::desktop::launch(app);
  9. }
  10. const ENDPOINT: &str = "https://api.openweathermap.org/data/2.5/weather";
  11. fn app(cx: Scope) -> Element {
  12. //
  13. let body = use_suspense(
  14. &cx,
  15. || async {
  16. todo!()
  17. // let content = reqwest::get(ENDPOINT)
  18. // .await
  19. // .unwrap()
  20. // .json::<serde_json::Value>()
  21. // .await
  22. // .unwrap();
  23. },
  24. |props| {
  25. //
  26. cx.render(rsx!(WeatherDisplay {}))
  27. },
  28. );
  29. cx.render(rsx! {
  30. div {
  31. {body}
  32. }
  33. })
  34. }
  35. #[derive(PartialEq, Props)]
  36. struct WeatherProps {}
  37. fn WeatherDisplay(cx: Scope<WeatherProps>) -> Element {
  38. cx.render(rsx!(
  39. div { class: "flex items-center justify-center flex-col",
  40. div { class: "flex items-center justify-center",
  41. div { class: "flex flex-col bg-white rounded p-4 w-full max-w-xs",
  42. div{ class: "font-bold text-xl",
  43. "Jon's awesome site!!"
  44. }
  45. div{ class: "text-sm text-gray-500",
  46. "He worked so hard on it :)"
  47. }
  48. div { class: "flex flex-row items-center justify-center mt-6",
  49. div { class: "font-medium text-6xl",
  50. "1337"
  51. }
  52. }
  53. div { class: "flex flex-row justify-between mt-6",
  54. "Legit made my own React"
  55. }
  56. }
  57. }
  58. }
  59. ))
  60. }