1
0

crm.rs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. Tiny CRM: A port of the Yew CRM example to Dioxus.
  3. */
  4. use dioxus::prelude::*;
  5. fn main() {
  6. dioxus::desktop::launch(app);
  7. }
  8. #[derive(Clone, Debug, Default)]
  9. pub struct Client {
  10. pub first_name: String,
  11. pub last_name: String,
  12. pub description: String,
  13. }
  14. fn app(cx: Scope) -> Element {
  15. let clients = use_ref(&cx, || vec![] as Vec<Client>);
  16. let firstname = use_state(&cx, String::new);
  17. let lastname = use_state(&cx, String::new);
  18. let description = use_state(&cx, String::new);
  19. cx.render(rsx!(
  20. body {
  21. margin_left: "35%",
  22. link {
  23. rel: "stylesheet",
  24. href: "https://unpkg.com/purecss@2.0.6/build/pure-min.css",
  25. integrity: "sha384-Uu6IeWbM+gzNVXJcM9XV3SohHtmWE+3VGi496jvgX1jyvDTXfdK+rfZc8C1Aehk5",
  26. crossorigin: "anonymous",
  27. }
  28. h1 {"Dioxus CRM Example"}
  29. Router {
  30. Route { to: "/",
  31. div { class: "crm",
  32. h2 { margin_bottom: "10px", "List of clients" }
  33. div { class: "clients", margin_left: "10px",
  34. clients.read().iter().map(|client| rsx!(
  35. div { class: "client", style: "margin-bottom: 50px",
  36. p { "First Name: {client.first_name}" }
  37. p { "Last Name: {client.last_name}" }
  38. p {"Description: {client.description}"}
  39. })
  40. )
  41. }
  42. Link { to: "/new", class: "pure-button pure-button-primary", "Add New" }
  43. Link { to: "/new", class: "pure-button", "Settings" }
  44. }
  45. }
  46. Route { to: "/new",
  47. div { class: "crm",
  48. h2 { margin_bottom: "10px", "Add new client" }
  49. form { class: "pure-form",
  50. input {
  51. class: "new-client firstname",
  52. placeholder: "First name",
  53. value: "{firstname}",
  54. oninput: move |e| firstname.set(e.value.clone())
  55. }
  56. input {
  57. class: "new-client lastname",
  58. placeholder: "Last name",
  59. value: "{lastname}",
  60. oninput: move |e| lastname.set(e.value.clone())
  61. }
  62. textarea {
  63. class: "new-client description",
  64. placeholder: "Description",
  65. value: "{description}",
  66. oninput: move |e| description.set(e.value.clone())
  67. }
  68. }
  69. button {
  70. class: "pure-button pure-button-primary",
  71. onclick: move |_| {
  72. clients.write().push(Client {
  73. description: description.to_string(),
  74. first_name: firstname.to_string(),
  75. last_name: lastname.to_string(),
  76. });
  77. description.set(String::new());
  78. firstname.set(String::new());
  79. lastname.set(String::new());
  80. },
  81. "Add New"
  82. }
  83. Link { to: "/", class: "pure-button", "Go Back" }
  84. }
  85. }
  86. Route { to: "/settings",
  87. div {
  88. h2 { margin_bottom: "10px", "Settings" }
  89. button {
  90. background: "rgb(202, 60, 60)",
  91. class: "pure-button pure-button-primary",
  92. onclick: move |_| clients.write().clear(),
  93. "Remove all clients"
  94. }
  95. Link { to: "/", class: "pure-button pure-button-primary", "Go Back" }
  96. }
  97. }
  98. }
  99. }
  100. ))
  101. }