1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
use async_channel::{Receiver, Sender};
use chrono::NaiveDate;
use rusqlite::Connection;
use std::rc::Rc;
use crate::{
app::{calendar, form, utils, App},
model::event::Event,
};
pub fn send(tx: Sender<Msg>, msg: Msg) {
utils::spawn(async move {
let _ = tx.send(msg).await;
})
}
pub enum Msg {
ShowAddForm { date: NaiveDate },
AddEvent { event: Event },
}
pub async fn event_handler(conn: Rc<Connection>, rx: Receiver<Msg>, tx: Sender<Msg>, mut app: App) {
while let Ok(msg) = rx.recv().await {
match msg {
Msg::ShowAddForm { date } => {
form::show(Rc::clone(&conn), tx.clone(), Rc::clone(&app.window), date).await;
}
Msg::AddEvent { event } => {
let date = event.date.clone();
app.events.push(event);
calendar::refresh_date(&app, date);
}
}
}
}
|