Hold config state from the generated schedule; avoids desync issues when changing configs and re-exporting data without generating new schedule
This commit is contained in:
@@ -22,6 +22,7 @@ pub mod workload;
|
|||||||
struct AppState {
|
struct AppState {
|
||||||
schedule: Mutex<MonthlySchedule>,
|
schedule: Mutex<MonthlySchedule>,
|
||||||
tracker: Mutex<WorkloadTracker>,
|
tracker: Mutex<WorkloadTracker>,
|
||||||
|
config: Mutex<UserConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// argument to this must be the rota state including all
|
/// argument to this must be the rota state including all
|
||||||
@@ -34,8 +35,8 @@ fn generate(
|
|||||||
) -> Result<MonthlySchedule, String> {
|
) -> Result<MonthlySchedule, String> {
|
||||||
let mut schedule = MonthlySchedule::new();
|
let mut schedule = MonthlySchedule::new();
|
||||||
let mut tracker = WorkloadTracker::default();
|
let mut tracker = WorkloadTracker::default();
|
||||||
let scheduler =
|
let config = UserConfig::try_from(config).map_err(|e| e.to_string())?;
|
||||||
Scheduler::new_with_config(UserConfig::try_from(config).map_err(|e| e.to_string())?);
|
let scheduler = Scheduler::new_with_config(config.clone());
|
||||||
|
|
||||||
scheduler
|
scheduler
|
||||||
.run(&mut schedule, &mut tracker)
|
.run(&mut schedule, &mut tracker)
|
||||||
@@ -49,21 +50,20 @@ fn generate(
|
|||||||
|
|
||||||
let mut internal_schedule = state.schedule.lock().unwrap();
|
let mut internal_schedule = state.schedule.lock().unwrap();
|
||||||
let mut internal_tracker = state.tracker.lock().unwrap();
|
let mut internal_tracker = state.tracker.lock().unwrap();
|
||||||
|
let mut internal_config = state.config.lock().unwrap();
|
||||||
|
|
||||||
*internal_schedule = schedule.clone();
|
*internal_schedule = schedule.clone();
|
||||||
*internal_tracker = tracker.clone();
|
*internal_tracker = tracker.clone();
|
||||||
|
*internal_config = config.clone();
|
||||||
|
|
||||||
Ok(schedule)
|
Ok(schedule)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn export(config: UserConfigDTO, state: tauri::State<'_, AppState>) -> Result<(), String> {
|
fn export(state: tauri::State<'_, AppState>) -> Result<(), String> {
|
||||||
let config = UserConfig::try_from(config)
|
|
||||||
.inspect_err(|e| error!("{e}"))
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
|
|
||||||
let schedule = state.schedule.lock().unwrap();
|
let schedule = state.schedule.lock().unwrap();
|
||||||
let tracker = state.tracker.lock().unwrap();
|
let tracker = state.tracker.lock().unwrap();
|
||||||
|
let config = state.config.lock().unwrap();
|
||||||
|
|
||||||
schedule
|
schedule
|
||||||
.export(FileType::Docx, &config, &tracker)
|
.export(FileType::Docx, &config, &tracker)
|
||||||
@@ -88,6 +88,7 @@ pub fn run() {
|
|||||||
.manage(AppState {
|
.manage(AppState {
|
||||||
schedule: Mutex::new(MonthlySchedule::new()),
|
schedule: Mutex::new(MonthlySchedule::new()),
|
||||||
tracker: Mutex::new(WorkloadTracker::default()),
|
tracker: Mutex::new(WorkloadTracker::default()),
|
||||||
|
config: Mutex::new(UserConfig::default()),
|
||||||
})
|
})
|
||||||
.plugin(
|
.plugin(
|
||||||
tauri_plugin_log::Builder::new()
|
tauri_plugin_log::Builder::new()
|
||||||
|
|||||||
@@ -48,11 +48,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function export_file() {
|
async function export_file() {
|
||||||
let config = rota.toDTO();
|
|
||||||
let schedule = rota.solution;
|
let schedule = rota.solution;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await invoke("export", { config, schedule });
|
await invoke("export", { schedule });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user