refactor: LOW cleanups — dedup secure_flag, remove vestigial social_query,
drop PersistedImportSession, rename LoginQuery→LoginCommand, own DeleteAccountDeps, PersonId via uuid_id! macro, rename SortDirection→ ReviewSortBy, TUI fs::read→Command, generic PaginatedResponse<T>
This commit is contained in:
@@ -248,6 +248,8 @@ pub enum Action {
|
||||
ReviewCreateFailed(String),
|
||||
ReviewDeleted(Uuid),
|
||||
ReviewDeleteFailed(String),
|
||||
FileRead(String),
|
||||
FileReadFailed(String),
|
||||
BulkItemDone {
|
||||
index: usize,
|
||||
error: Option<String>,
|
||||
@@ -265,6 +267,7 @@ pub enum Command {
|
||||
SaveConfig(String),
|
||||
SaveToken(String),
|
||||
ClearToken,
|
||||
ReadFile { path: String },
|
||||
}
|
||||
|
||||
// Matches the export CSV column order:
|
||||
@@ -863,22 +866,34 @@ pub fn update(app: &mut App, action: Action) -> Vec<Command> {
|
||||
&& m.bulk_import.stage == BulkImportStage::EnterPath
|
||||
{
|
||||
let path = m.bulk_import.file_path.trim().to_string();
|
||||
match std::fs::read_to_string(&path) {
|
||||
Ok(content) => {
|
||||
m.bulk_import.parsed = parse_csv(&content);
|
||||
m.bulk_import.stage = BulkImportStage::Preview;
|
||||
}
|
||||
Err(e) => {
|
||||
app.status = Some(StatusMsg {
|
||||
text: format!("Cannot read file: {e}"),
|
||||
is_error: true,
|
||||
});
|
||||
}
|
||||
if path.is_empty() {
|
||||
app.status = Some(StatusMsg {
|
||||
text: "File path required".into(),
|
||||
is_error: true,
|
||||
});
|
||||
return vec![];
|
||||
}
|
||||
return vec![Command::ReadFile { path }];
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
|
||||
Action::FileRead(content) => {
|
||||
if let Screen::Main(m) = &mut app.screen {
|
||||
m.bulk_import.parsed = parse_csv(&content);
|
||||
m.bulk_import.stage = BulkImportStage::Preview;
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
|
||||
Action::FileReadFailed(msg) => {
|
||||
app.status = Some(StatusMsg {
|
||||
text: format!("Cannot read file: {msg}"),
|
||||
is_error: true,
|
||||
});
|
||||
vec![]
|
||||
}
|
||||
|
||||
Action::BulkImportAll => {
|
||||
if let Screen::Main(m) = &mut app.screen
|
||||
&& m.tab == Tab::BulkImport
|
||||
|
||||
@@ -220,6 +220,21 @@ fn handle_command(cmd: Command, app: &App, client: &Arc<ApiClient>, tx: &mpsc::S
|
||||
});
|
||||
}
|
||||
|
||||
Command::ReadFile { path } => {
|
||||
let tx = tx.clone();
|
||||
tokio::spawn(async move {
|
||||
let action =
|
||||
match tokio::task::spawn_blocking(move || std::fs::read_to_string(&path))
|
||||
.await
|
||||
.unwrap_or_else(|e| Err(std::io::Error::other(e)))
|
||||
{
|
||||
Ok(content) => Action::FileRead(content),
|
||||
Err(e) => Action::FileReadFailed(e.to_string()),
|
||||
};
|
||||
let _ = tx.send(action).await;
|
||||
});
|
||||
}
|
||||
|
||||
Command::ImportNext(index) => {
|
||||
let Some(token) = app.token.clone() else {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user