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, |c| c);
  9. }
  10. const ENDPOINT: &str = "https://api.openweathermap.org/data/2.5/weather";
  11. static App: Component<()> = |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. |props| {
  24. //
  25. cx.render(rsx!(WeatherDisplay {}))
  26. },
  27. );
  28. cx.render(rsx! {
  29. div {
  30. {body}
  31. }
  32. })
  33. };
  34. #[derive(PartialEq, Props)]
  35. struct WeatherProps {}
  36. static WeatherDisplay: Component<WeatherProps> = |cx, props| {
  37. //
  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. };