Skip to content

Commit 9d27c0f

Browse files
committed
fix eventsview
1 parent a6072a9 commit 9d27c0f

File tree

7 files changed

+232
-168
lines changed

7 files changed

+232
-168
lines changed

assets/styling/timeline_view.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,30 @@
8989
font-style: italic;
9090
color: var(--text-color);
9191
}
92+
93+
.event-view-container {
94+
display: flex;
95+
flex-direction: column;
96+
gap: 1rem;
97+
}
98+
99+
.back-button {
100+
padding: 0.5rem 1rem;
101+
background-color: #f0f0f0;
102+
border: none;
103+
border-radius: 4px;
104+
cursor: pointer;
105+
}
106+
107+
.back-button:hover {
108+
background-color: #e0e0e0;
109+
}
110+
111+
.error-message {
112+
display: flex;
113+
flex-direction: column;
114+
align-items: center;
115+
gap: 1rem;
116+
padding: 2rem;
117+
text-align: center;
118+
}

src/components/timeline/central_panel.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::models::timeline::MyLifeApp;
21
use crate::components::timeline::events_view::EventView;
32
use crate::components::timeline::lifetime_view::LifetimeView;
3+
use crate::models::timeline::MyLifeApp;
44
use dioxus::prelude::*;
55
use uuid::Uuid;
66

@@ -9,8 +9,10 @@ pub fn CentralPanel() -> Element {
99
let mut app_state = use_context::<Signal<MyLifeApp>>();
1010

1111
let on_period_click = move |period_id: Uuid| {
12-
app_state.write().view = "EventView".to_string();
13-
app_state.write().selected_life_period = Some(period_id);
12+
app_state.with_mut(|state| {
13+
state.view = "EventView".to_string();
14+
state.selected_life_period = Some(period_id);
15+
});
1416
};
1517

1618
rsx! {
@@ -25,6 +27,7 @@ pub fn CentralPanel() -> Element {
2527
on_period_click: on_period_click
2628
}
2729
},
30+
2831
"EventView" => {
2932
if let Some(period_id) = app_state().selected_life_period {
3033
rsx! {

src/components/timeline/edit_legend_item.rs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::models::timeline::{LifePeriod, LifePeriodEvent, MyLifeApp, Yaml};
21
use crate::managers::timeline_manager::get_timeline_manager;
2+
use crate::models::timeline::{LifePeriod, LifePeriodEvent, MyLifeApp, Yaml};
33
use crate::utils::date_utils::is_valid_date;
44
use chrono::NaiveDate;
55
use dioxus::prelude::*;
@@ -10,15 +10,15 @@ fn is_valid_hex_color(color: &str) -> bool {
1010
color.len() == 7 && color.starts_with('#') && color[1..].chars().all(|c| c.is_ascii_hexdigit())
1111
}
1212

13-
1413
#[component]
1514
pub fn EditLegendItem() -> Element {
1615
let mut app_state = use_context::<Signal<MyLifeApp>>();
1716
let mut yaml_state = use_context::<Signal<Yaml>>();
1817
let mut color_input = use_signal(String::new);
1918
let mut date_error = use_signal(String::new);
2019
let mut current_date = use_signal(String::new);
21-
let mut pending_update = use_signal(|| None::<(Option<LifePeriod>, Option<(Uuid, LifePeriodEvent)>)>);
20+
let mut pending_update =
21+
use_signal(|| None::<(Option<LifePeriod>, Option<(Uuid, LifePeriodEvent)>)>);
2222

2323
let (min_date, max_date) = use_memo(move || {
2424
if let Some(item) = &app_state().item_state {
@@ -51,7 +51,7 @@ pub fn EditLegendItem() -> Element {
5151
})();
5252
use_effect(move || {
5353
to_owned![pending_update, yaml_state];
54-
54+
5555
spawn(async move {
5656
if let Some((period, event)) = pending_update() {
5757
// Handle period updates
@@ -61,50 +61,48 @@ pub fn EditLegendItem() -> Element {
6161
} else {
6262
get_timeline_manager().add_life_period(period).await
6363
};
64-
64+
6565
if let Err(e) = result {
6666
warn!("Failed to update/add life period: {}", e);
6767
}
6868
}
69-
69+
7070
// Handle event updates
7171
if let Some((period_id, event)) = event {
7272
let result = if event.id.is_some() {
7373
get_timeline_manager().update_event(period_id, event).await
7474
} else {
7575
get_timeline_manager().add_event(period_id, event).await
7676
};
77-
77+
7878
if let Err(e) = result {
7979
warn!("Failed to update/add event: {}", e);
8080
}
8181
}
82-
82+
8383
// Update the entire timeline
84-
if let Err(e) = get_timeline_manager()
85-
.update_timeline(&yaml_state())
86-
.await
87-
{
84+
if let Err(e) = get_timeline_manager().update_timeline(&yaml_state()).await {
8885
warn!("Failed to update timeline: {}", e);
8986
}
9087
}
9188
});
9289
});
93-
90+
9491
let update_yaml_item = move |_| {
95-
debug!("Attempting to update yaml item");
9692
if date_error().is_empty() {
9793
if let Some(item) = app_state().item_state {
9894
let new_yaml = yaml_state();
99-
95+
10096
if item.is_event {
10197
let mut new_yaml_event = new_yaml.clone();
10298
if let Some(period) = new_yaml_event
10399
.life_periods
104100
.iter_mut()
105101
.find(|p| p.id == Some(app_state().selected_life_period.unwrap()))
106102
{
107-
let event = if let Some(event) = period.events.iter_mut().find(|e| e.id == Some(item.id)) {
103+
let event = if let Some(event) =
104+
period.events.iter_mut().find(|e| e.id == Some(item.id))
105+
{
108106
event.name = item.name.clone();
109107
event.color = item.color.clone();
110108
event.start = item.start.clone();
@@ -120,9 +118,12 @@ pub fn EditLegendItem() -> Element {
120118
new_event
121119
};
122120
period.events.sort_by(|a, b| a.start.cmp(&b.start));
123-
121+
124122
// Queue the update
125-
pending_update.set(Some((None, Some((app_state().selected_life_period.unwrap(), event)))));
123+
pending_update.set(Some((
124+
None,
125+
Some((app_state().selected_life_period.unwrap(), event)),
126+
)));
126127
}
127128
yaml_state.set(new_yaml_event);
128129
} else {
@@ -147,8 +148,10 @@ pub fn EditLegendItem() -> Element {
147148
new_yaml_period.life_periods.push(new_period.clone());
148149
new_period
149150
};
150-
new_yaml_period.life_periods.sort_by(|a, b| a.start.cmp(&b.start));
151-
151+
new_yaml_period
152+
.life_periods
153+
.sort_by(|a, b| a.start.cmp(&b.start));
154+
152155
// Queue the update
153156
pending_update.set(Some((Some(period), None)));
154157
yaml_state.set(new_yaml_period);
@@ -159,7 +162,6 @@ pub fn EditLegendItem() -> Element {
159162
}
160163
};
161164

162-
163165
let close_modal = move |_| {
164166
app_state.write().item_state = None;
165167
app_state.write().temp_start_date = String::new();
@@ -177,7 +179,6 @@ pub fn EditLegendItem() -> Element {
177179

178180
let update_date = move |evt: Event<FormData>| {
179181
let new_date = evt.value().to_string();
180-
debug!("Updating date: {}", new_date);
181182
current_date.set(new_date.clone());
182183

183184
let is_event = app_state()
@@ -229,7 +230,6 @@ pub fn EditLegendItem() -> Element {
229230
}
230231
};
231232

232-
233233
let delete_item = move |_| {
234234
if let Some(item) = app_state().item_state {
235235
let mut new_yaml = yaml_state();
@@ -240,11 +240,11 @@ pub fn EditLegendItem() -> Element {
240240
.find(|p| p.id == Some(app_state().selected_life_period.unwrap()))
241241
{
242242
period.events.retain(|e| e.id != Some(item.id));
243-
243+
244244
// Clone required data for the async operation
245245
let period_id = app_state().selected_life_period.unwrap();
246246
let event_id = item.id;
247-
247+
248248
use_future(move || async move {
249249
if let Err(e) = get_timeline_manager()
250250
.delete_event(period_id, event_id)
@@ -256,15 +256,12 @@ pub fn EditLegendItem() -> Element {
256256
}
257257
} else {
258258
new_yaml.life_periods.retain(|p| p.id != Some(item.id));
259-
259+
260260
// Clone required data for the async operation
261261
let period_id = item.id;
262-
262+
263263
use_future(move || async move {
264-
if let Err(e) = get_timeline_manager()
265-
.delete_life_period(period_id)
266-
.await
267-
{
264+
if let Err(e) = get_timeline_manager().delete_life_period(period_id).await {
268265
warn!("Failed to delete life period: {}", e);
269266
}
270267
});

0 commit comments

Comments
 (0)