Library import asks for a location to file the cards under

After picking a file, Import cards… asks where the cards are kept,
pre-filled with the file's name (a ManaBox export is named after its
binder). A location is set on every imported card, replacing any it had,
as Add Cards does; blank leaves locations alone. It's applied inside the
import's single transaction.
This commit is contained in:
2026-10-17 21:58:44 -05:00
parent 1641d9aa47
commit 4b651b5108
6 changed files with 149 additions and 19 deletions

View File

@@ -441,11 +441,16 @@ pub struct LibraryImportProgress {
pub total: usize,
}
/// Import a card list (plain text or a ManaBox export) into the library.
/// Import a card list (plain text or a ManaBox export) into the library,
/// filing every imported card under `location` unless it's blank.
/// Runs on a blocking thread so the UI stays responsive, emitting
/// `library-import-progress` as it goes.
#[tauri::command]
pub async fn import_library_cards(app: AppHandle, path: String) -> Res<LibraryImportResult> {
pub async fn import_library_cards(
app: AppHandle,
path: String,
location: Option<String>,
) -> Res<LibraryImportResult> {
crate::sync::blocking(move || {
let text = std::fs::read_to_string(&path).map_err(|e| e.to_string())?;
let s = crate::sync::lock(&app);
@@ -453,7 +458,7 @@ pub async fn import_library_cards(app: AppHandle, path: String) -> Res<LibraryIm
let mut last_percent = None;
let (added, unresolved) = s
.catalog()?
.import_card_list(&text, |done, total| {
.import_card_list(&text, location.as_deref().unwrap_or(""), |done, total| {
let percent = (done * 100).checked_div(total).unwrap_or(100);
if last_percent != Some(percent) {
last_percent = Some(percent);