Skip to content

Commit

Permalink
feat: visual feedback for adding to anki
Browse files Browse the repository at this point in the history
  • Loading branch information
BrewingWeasel committed Aug 2, 2024
1 parent 1910c15 commit 8c2f134
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src-tauri/src/add_to_anki.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use reqwest::Client;
use serde_json::json;
use shared::Definition;
use shared::{Definition, ToasterPayload};
use std::{borrow::Cow, collections::HashMap};
use tauri::State;
use tauri::{State, Window};

use crate::{ankiconnect::AnkiResult, SakinyjeError, SakinyjeState};

Expand Down Expand Up @@ -101,8 +101,12 @@ pub struct ExportDetails<'a> {
}

#[tauri::command]
pub async fn add_to_anki(export_details: ExportDetails<'_>) -> Result<(), SakinyjeError> {
pub async fn add_to_anki(
export_details: ExportDetails<'_>,
window: Window,
) -> Result<(), SakinyjeError> {
log::debug!("Adding to anki using details {:?}", export_details);
let selected_word = export_details.word;
let args = get_json(export_details);
let client = Client::new();
let response = client
Expand All @@ -111,8 +115,14 @@ pub async fn add_to_anki(export_details: ExportDetails<'_>) -> Result<(), Sakiny
.send()
.await
.map_err(|_| SakinyjeError::AnkiNotAvailable)?;
std::convert::Into::<Result<(), SakinyjeError>>::into(
response.json::<AnkiResult<()>>().await?,
std::convert::Into::<Result<isize, SakinyjeError>>::into(
response.json::<AnkiResult<isize>>().await?,
)?;
window.emit(
"added_to_anki",
Some(ToasterPayload {
message: Some(&format!("Added {} to anki", selected_word)),
}),
)?;
log::debug!("Added to anki");
Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const toasters: Ref<Map<string, number | null>> = ref(
new Map([
["stanza_loading", null],
["refresh_anki", null],
["added_to_anki", null],
]),
);
Expand Down

0 comments on commit 8c2f134

Please sign in to comment.