This commit is contained in:
Marco De Araujo 2025-12-24 14:59:20 -04:00
parent b130c4550d
commit 4f9ced3e29
3 changed files with 11 additions and 8 deletions

View file

@ -18,8 +18,8 @@ status = Status
error = Error error = Error
dashboard-header = Status Dashboard dashboard-header = Status Dashboard
never = Never never = Never
auto-update-failed = Automatic update failed auto-update-failed = Automatic update failed: {error}
update-fail = Failed to update data update-fail = Failed to update data: {error}
now = Now now = Now
uptime = Uptime uptime = Uptime
history = History history = History

View file

@ -1,6 +1,6 @@
use crate::api::{UptimeKumaClient, UptimeKumaEndpoints}; use crate::api::{UptimeKumaClient, UptimeKumaEndpoints};
use crate::core; use crate::core;
use crate::i18n::t; use crate::i18n::{t, t_with_args};
use crate::ui::{ use crate::ui::{
components::{render_header, render_monitor_list}, components::{render_header, render_monitor_list},
dashboard::model::DashboardViewState, dashboard::model::DashboardViewState,
@ -19,6 +19,7 @@ use ratatui::{
widgets::{Block, Borders, Padding, Paragraph}, widgets::{Block, Borders, Padding, Paragraph},
}; };
use std::collections::HashMap;
use std::{ use std::{
io, io,
time::{Duration, Instant}, time::{Duration, Instant},
@ -143,7 +144,9 @@ impl App {
fn update_if_needed(&mut self) -> io::Result<()> { fn update_if_needed(&mut self) -> io::Result<()> {
if self.last_update.elapsed() >= self.update_interval { if self.last_update.elapsed() >= self.update_interval {
if let Err(e) = self.refresh_data() { if let Err(e) = self.refresh_data() {
self.state.error_message = Some(t("auto-update-failed")); let mut error = HashMap::new();
error.insert("error", e.to_string());
self.state.error_message = Some(t_with_args("auto-update-failed", &error));
} }
self.last_update = Instant::now(); self.last_update = Instant::now();
} }
@ -155,7 +158,10 @@ impl App {
self.render(); self.render();
if let Err(e) = self.fetch_and_update_data() { if let Err(e) = self.fetch_and_update_data() {
self.state.error_message = Some(t("update-fail")) let mut error = HashMap::new();
error.insert("error", e.to_string());
self.state.error_message = Some(t_with_args("update-fail", &error))
} }
self.state.is_loading = false; self.state.is_loading = false;

View file

@ -26,7 +26,6 @@ pub struct DashboardViewState {
pub title: String, pub title: String,
pub descriptions: Option<String>, pub descriptions: Option<String>,
pub monitors: Vec<MonitorViewState>, pub monitors: Vec<MonitorViewState>,
pub selected_index: usize,
pub is_loading: bool, pub is_loading: bool,
pub error_message: Option<String>, pub error_message: Option<String>,
} }
@ -37,7 +36,6 @@ impl DashboardViewState {
title: t("loading").to_string(), title: t("loading").to_string(),
descriptions: None, descriptions: None,
monitors: Vec::new(), monitors: Vec::new(),
selected_index: 0,
is_loading: true, is_loading: true,
error_message: None, error_message: None,
} }
@ -91,7 +89,6 @@ impl DashboardViewState {
title: data.title, title: data.title,
descriptions: data.description, descriptions: data.description,
monitors, monitors,
selected_index: 0,
is_loading: false, is_loading: false,
error_message: None, error_message: None,
} }