Fix automatic translation request handling
This commit is contained in:
@@ -10367,16 +10367,12 @@ impl BdsApp {
|
||||
}
|
||||
}
|
||||
|
||||
let request = ai::OneShotRequest {
|
||||
operation: ai::OneShotOperation::TranslatePost {
|
||||
target_language: target_language.to_string(),
|
||||
},
|
||||
content: json!({
|
||||
"title": state.title,
|
||||
"excerpt": state.excerpt,
|
||||
"content": state.content,
|
||||
}),
|
||||
};
|
||||
let request = ai::post_translation_request(
|
||||
&state.title,
|
||||
Some(&state.excerpt),
|
||||
&state.content,
|
||||
target_language,
|
||||
);
|
||||
if let Some(editor) = self.post_editors.get_mut(post_id) {
|
||||
editor.ai_activity = Some(t(self.ui_locale, "editor.translate"));
|
||||
}
|
||||
@@ -10513,16 +10509,12 @@ impl BdsApp {
|
||||
{
|
||||
editor.language = state.canonical_language.clone();
|
||||
}
|
||||
let request = ai::OneShotRequest {
|
||||
operation: ai::OneShotOperation::TranslateMedia {
|
||||
target_language: target_language.to_string(),
|
||||
},
|
||||
content: json!({
|
||||
"title": state.title,
|
||||
"alt": state.alt,
|
||||
"caption": state.caption,
|
||||
}),
|
||||
};
|
||||
let request = ai::media_translation_request(
|
||||
Some(&state.title),
|
||||
Some(&state.alt),
|
||||
Some(&state.caption),
|
||||
target_language,
|
||||
);
|
||||
if let Some(editor) = self.media_editors.get_mut(media_id) {
|
||||
editor.ai_activity = Some(t(self.ui_locale, "editor.translate"));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/// Toast notification state.
|
||||
///
|
||||
/// Toasts are ephemeral, auto-dismissing messages shown at the top of
|
||||
/// the workspace. Each toast has a severity level, a message, and a
|
||||
/// monotonically increasing id used for targeted dismissal.
|
||||
/// Toasts are messages shown at the top of the workspace. Errors remain until
|
||||
/// dismissed; other levels expire automatically.
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
static NEXT_TOAST_ID: AtomicU64 = AtomicU64::new(1);
|
||||
@@ -45,6 +44,9 @@ impl Toast {
|
||||
|
||||
/// Whether this toast has exceeded its display duration.
|
||||
pub fn is_expired(&self) -> bool {
|
||||
if self.level == ToastLevel::Error {
|
||||
return false;
|
||||
}
|
||||
let now = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
@@ -69,4 +71,11 @@ mod tests {
|
||||
let t = Toast::new(ToastLevel::Info, "test".into());
|
||||
assert!(!t.is_expired());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_toast_never_expires_automatically() {
|
||||
let mut toast = Toast::new(ToastLevel::Error, "important".into());
|
||||
toast.created_at = 0;
|
||||
assert!(!toast.is_expired());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user