Handy/src-tauri/src/commands/history.rs
Han Pham 9185b3db08
feat: delete a single audio entry (#119)
* feat: delete a single audio entry

* fix(HistorySetting): remove unnecessary loading state
2025-09-19 12:30:50 -07:00

51 lines
1.3 KiB
Rust

use crate::managers::history::{HistoryEntry, HistoryManager};
use std::sync::Arc;
use tauri::{AppHandle, State};
#[tauri::command]
pub async fn get_history_entries(
_app: AppHandle,
history_manager: State<'_, Arc<HistoryManager>>,
) -> Result<Vec<HistoryEntry>, String> {
history_manager
.get_history_entries()
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
pub async fn toggle_history_entry_saved(
_app: AppHandle,
history_manager: State<'_, Arc<HistoryManager>>,
id: i64,
) -> Result<(), String> {
history_manager
.toggle_saved_status(id)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
pub async fn get_audio_file_path(
_app: AppHandle,
history_manager: State<'_, Arc<HistoryManager>>,
file_name: String,
) -> Result<String, String> {
let path = history_manager.get_audio_file_path(&file_name);
path.to_str()
.ok_or_else(|| "Invalid file path".to_string())
.map(|s| s.to_string())
}
#[tauri::command]
pub async fn delete_history_entry(
_app: AppHandle,
history_manager: State<'_, Arc<HistoryManager>>,
id: i64,
) -> Result<(), String> {
history_manager
.as_ref()
.delete_entry(id)
.await
.map_err(|e| e.to_string())
}