Import legacy data. Show welcome screen when no database is configured. #198

Merged
savanni merged 4 commits from fitnesstrax/legacy-importer into main 2024-02-19 21:45:39 +00:00
3 changed files with 9 additions and 17 deletions
Showing only changes of commit 55b6327d42 - Show all commits

View File

@ -96,18 +96,8 @@ impl App {
.unwrap() .unwrap()
} }
pub async fn get_record(&self, id: RecordId) -> Result<Option<Record<TraxRecord>>, AppError> { pub fn database_is_open(&self) -> bool {
let db = self.database.clone(); self.database.read().unwrap().is_some()
self.runtime
.spawn_blocking(move || {
if let Some(ref db) = *db.read().unwrap() {
Ok(db.get(&id))
} else {
Err(AppError::NoDatabase)
}
})
.await
.unwrap()
} }
} }

View File

@ -136,7 +136,6 @@ impl AppWindow {
s s
} }
#[allow(unused)]
fn show_welcome_view(&self) { fn show_welcome_view(&self) {
let view = View::Welcome(WelcomeView::new({ let view = View::Welcome(WelcomeView::new({
let s = self.clone(); let s = self.clone();
@ -177,9 +176,13 @@ impl AppWindow {
glib::spawn_future_local({ glib::spawn_future_local({
let s = self.clone(); let s = self.clone();
async move { async move {
if s.app.database_is_open() {
let end = Local::now().date_naive(); let end = Local::now().date_naive();
let start = end - Duration::days(7); let start = end - Duration::days(7);
s.show_historical_view(DayInterval { start, end }); s.show_historical_view(DayInterval { start, end });
} else {
s.show_welcome_view();
}
} }
}); });
} }

View File

@ -30,7 +30,6 @@ pub use welcome_view::WelcomeView;
pub enum View { pub enum View {
Placeholder(PlaceholderView), Placeholder(PlaceholderView),
#[allow(unused)]
Welcome(WelcomeView), Welcome(WelcomeView),
Historical(HistoricalView), Historical(HistoricalView),
} }