Skip to content

Commit

Permalink
feat: Add Refresh Bookmarks Menu Item
Browse files Browse the repository at this point in the history
  • Loading branch information
vkhitrin committed Oct 24, 2024
1 parent e6a8b3b commit 9644d5a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
1 change: 1 addition & 0 deletions i18n/en/cosmicding.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ open-accounts-page = Open Accounts Page
provided-url-is-not-valid = Provided URL is not valid
quit = Quit
refresh = Refresh
refresh-bookmarks = Refresh Bookmarks
refreshed-all-bookmarks = Refreshed all bookmarks
refreshed-bookmarks-for-account = Refreshed bookmarks for account {$acc}
remove = Remove
Expand Down
37 changes: 22 additions & 15 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ impl Application for Cosmicding {
vec![crate::menu::menu_bar(
&self.key_binds,
!self.accounts_view.accounts.is_empty(),
!self.bookmarks_view.bookmarks.is_empty(),
)]
}

Expand Down Expand Up @@ -517,21 +518,23 @@ impl Application for Cosmicding {
.map(cosmic::app::Message::App),
),
Message::StartRefreshBookmarksForAllAccounts => {
let message = |x: Vec<Bookmark>| {
cosmic::app::Message::App(Message::DoneRefreshBookmarksForAllAccounts(x))
};
if !self.accounts_view.accounts.is_empty() {
commands.push(Command::perform(
http::fetch_all_bookmarks_from_accounts(
self.accounts_view.accounts.clone(),
),
message,
));
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!("refreshed-all-bookmarks")))
.map(cosmic::app::Message::App),
);
if !self.bookmarks_view.bookmarks.is_empty() {
let message = |x: Vec<Bookmark>| {
cosmic::app::Message::App(Message::DoneRefreshBookmarksForAllAccounts(x))
};
if !self.accounts_view.accounts.is_empty() {
commands.push(Command::perform(
http::fetch_all_bookmarks_from_accounts(
self.accounts_view.accounts.clone(),
),
message,
));
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!("refreshed-all-bookmarks")))
.map(cosmic::app::Message::App),
);
}
}
}
Message::DoneRefreshBookmarksForAllAccounts(remote_bookmarks) => {
Expand Down Expand Up @@ -977,6 +980,8 @@ pub enum MenuAction {
About,
AddAccount,
AddBookmark,
Empty,
RefreshBookmarks,
Settings,
}

Expand All @@ -986,9 +991,11 @@ impl _MenuAction for MenuAction {
fn message(&self) -> Self::Message {
match self {
MenuAction::About => Message::ToggleContextPage(ContextPage::About),
MenuAction::Empty => Message::EmpptyMessage,
MenuAction::AddAccount => Message::AddAccount,
MenuAction::Settings => Message::ToggleContextPage(ContextPage::Settings),
MenuAction::AddBookmark => Message::AddBookmarkForm,
MenuAction::RefreshBookmarks => Message::StartRefreshBookmarksForAllAccounts,
}
}
}
1 change: 1 addition & 0 deletions src/key_binds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn key_binds() -> HashMap<KeyBind, MenuAction> {
bind!([Ctrl], Key::Character("i".into()), About);
bind!([Ctrl, Shift], Key::Character("n".into()), AddAccount);
bind!([Ctrl], Key::Character("n".into()), AddBookmark);
bind!([Ctrl], Key::Character("r".into()), RefreshBookmarks);

key_binds
}
11 changes: 9 additions & 2 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::{

pub fn menu_bar<'a>(
key_binds: &HashMap<KeyBind, MenuAction>,
accounts_enabled: bool,
accounts_present: bool,
bookmarks_present: bool,
) -> Element<'a, Message> {
MenuBar::new(vec![
Tree::with_children(
Expand All @@ -22,11 +23,17 @@ pub fn menu_bar<'a>(
key_binds,
vec![
Item::Button(fl!("add-account"), MenuAction::AddAccount),
if accounts_enabled {
if accounts_present {
Item::Button(fl!("add-bookmark"), MenuAction::AddBookmark)
} else {
Item::ButtonDisabled(fl!("add-bookmark"), MenuAction::AddBookmark)
},
Item::Divider,
if bookmarks_present {
Item::Button(fl!("refresh-bookmarks"), MenuAction::RefreshBookmarks)
} else {
Item::ButtonDisabled(fl!("refresh-bookmarks"), MenuAction::Empty)
},
],
),
),
Expand Down

0 comments on commit 9644d5a

Please sign in to comment.