Skip to content

Commit

Permalink
fix: Toast On Refresh Failures
Browse files Browse the repository at this point in the history
Resolves #36.
  • Loading branch information
vkhitrin committed Feb 8, 2025
1 parent d1109a5 commit b0420c5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
2 changes: 2 additions & 0 deletions i18n/en/cosmicding.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ edit-bookmark = Edit Bookmark
enabled-public-sharing = Public bookmarks sharing enabled
enabled-sharing = Bookmarks sharing enabled
failed = failed
failed-refreshing-accounts = Failed refreshing some accounts ({$accounts})
failed-refreshing-bookmarks-for-account = Failed refreshing account {$account}
failed-to-find-linkding-api-endpoint = Failed to find linkding API endpoint
failed-to-parse-response = Failed to parse response
file = File
Expand Down
2 changes: 2 additions & 0 deletions i18n/sv/cosmicding.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ edit-bookmark = Redigera bokmärke
enabled-public-sharing = Delning av offentliga bokmärken har aktiverats
enabled-sharing = Bokmärkesdelning har aktiverats
failed = misslyckades
failed-refreshing-accounts = Misslyckades att uppdatera vissa konton ({$accounts})
failed-refreshing-bookmarks-for-account = Misslyckades att uppdatera konto {$account}
failed-to-find-linkding-api-endpoint = Det gick inte att hitta linkding API-slutpunkt
failed-to-parse-response = Misslyckades att tolka svar
file = Fil
Expand Down
56 changes: 43 additions & 13 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,12 @@ impl Application for Cosmicding {
}
}
Message::DoneRefreshBookmarksForAllAccounts(remote_responses) => {
let mut failed_accounts: Vec<String> = Vec::new();
if let Some(ref mut database) = &mut self.bookmarks_cursor.database {
for response in remote_responses {
if response.successful == false {
failed_accounts.push(response.account.display_name.clone());
}
block_on(async {
db::SqliteDatabase::aggregate_bookmarks_for_acount(
database,
Expand All @@ -682,11 +686,22 @@ impl Application for Cosmicding {
commands.push(self.update(Message::LoadAccounts));
commands.push(self.update(Message::LoadBookmarks));
self.state = ApplicationState::Normal;
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!("refreshed-bookmarks")))
.map(cosmic::app::Message::App),
);
if !failed_accounts.is_empty() {
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!(
"failed-refreshing-accounts",
accounts = failed_accounts.join(", ")
)))
.map(cosmic::app::Message::App),
);
} else {
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!("refreshed-bookmarks")))
.map(cosmic::app::Message::App),
);
}
}
}
Message::StartRefreshBookmarksForAccount(account) => {
Expand All @@ -713,8 +728,12 @@ impl Application for Cosmicding {
}
}
Message::DoneRefreshBookmarksForAccount(account, remote_responses) => {
let mut failure_refreshing = false;
if let Some(ref mut database) = &mut self.bookmarks_cursor.database {
for response in remote_responses {
if response.successful == false {
failure_refreshing = true;
}
block_on(async {
db::SqliteDatabase::aggregate_bookmarks_for_acount(
database,
Expand All @@ -729,14 +748,25 @@ impl Application for Cosmicding {
commands.push(self.update(Message::LoadAccounts));
commands.push(self.update(Message::LoadBookmarks));
self.state = ApplicationState::Normal;
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!(
"refreshed-bookmarks-for-account",
acc = account.display_name
)))
.map(cosmic::app::Message::App),
);
if failure_refreshing {
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!(
"failed-refreshing-bookmarks-for-account",
account = account.display_name
)))
.map(cosmic::app::Message::App),
);
} else {
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!(
"refreshed-bookmarks-for-account",
acc = account.display_name
)))
.map(cosmic::app::Message::App),
);
}
}
}
Message::StartRefreshAccountProfile(account) => {
Expand Down

0 comments on commit b0420c5

Please sign in to comment.