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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user