Export json

This commit is contained in:
Emilia Allison 2025-11-22 23:07:29 -05:00
parent 068785b4c8
commit b171f39eaa
No known key found for this signature in database
GPG Key ID: FEC1CE6360EEC9A8
3 changed files with 23 additions and 1 deletions

View File

@ -14,6 +14,7 @@ eframe = { version = "0.33", default-features = false, features = [
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger = "0.11"

View File

@ -1,6 +1,8 @@
use std::ops::DerefMut;
use std::sync::Mutex;
use serde_json;
use eframe::egui::{self};
use plate_tool_lib::csv::{
records_to_csv, records_to_echo_client_csv, transfer_to_records, TransferRecord,
@ -160,7 +162,13 @@ impl eframe::App for PlateToolEframe {
save_file(bytes, Some("transfers.csv"));
}
}
if ui.button("Export as JSON").clicked() {}
if ui.button("Export as JSON").clicked() {
let data = serde_json::to_string_pretty(&self.main_state);
if let Ok(data) = data {
let bytes: &[u8] = data.as_bytes();
save_file(bytes, Some("plate_tool_state.json"));
}
}
});
ui.menu_button("Import", |ui| {
if ui.button("Import from JSON").clicked() {}

View File

@ -125,6 +125,19 @@ pub fn open_new_plate_modal(modal_state: &mut ModalState) {
}
}
pub fn open_new_plate_modal_with_default_type(
modal_state: &mut ModalState,
plate_type: plate_tool_lib::plate::PlateType,
) {
// Do not close another modal
if matches!(modal_state, ModalState::None) {
*modal_state = ModalState::NewPlate(NewPlateModalState {
plate_type: plate_type,
..Default::default()
});
}
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct EditPlateModalState {