weather_app.rs 1.6 KB

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