Skip to content

Commit

Permalink
fix: Refactor Bookmarks View
Browse files Browse the repository at this point in the history
Refactoring bookmarks view to display actions when accounts are present.

Fixes #2.
  • Loading branch information
vkhitrin committed Oct 18, 2024
1 parent 5b09d06 commit d849e51
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
2 changes: 2 additions & 0 deletions i18n/en/cosmicding.ftl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
about = About
account = Account
accounts = Accounts
accounts-with-count = Accounts ({$count})
add-account = Add Account
add-bookmark = Add Bookmark
added-account = Added account {$acc}
Expand All @@ -10,6 +11,7 @@ app-title = cosmicding
appearance = Appearance
archived = Archived
bookmarks = Bookmarks
bookmarks-with-count = Bookmarks ({$count})
cancel = Cancel
dark = Dark
description = Description
Expand Down
30 changes: 14 additions & 16 deletions src/pages/accounts.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::app::Message;
use crate::fl;
use crate::models::account::Account;
use cosmic::iced::Length;
use cosmic::{
cosmic_theme,
iced::{self, Alignment},
theme,
widget::{self},
Apply, Command, Element,
cosmic_theme,
theme,
};
use crate::fl;
use crate::models::account::Account;
use iced::alignment::{Horizontal, Vertical};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -75,7 +75,10 @@ impl AccountsView {
.spacing(spacing.space_xxs)
.push(widget::text(item.display_name.clone()))
.push(widget::horizontal_space(Length::Fill))
.push(widget::button::link(item.instance.clone()).on_press(AccountsMessage::OpenExternalURL(item.instance.clone())))
.push(
widget::button::link(item.instance.clone())
.on_press(AccountsMessage::OpenExternalURL(item.instance.clone())),
)
.padding([
spacing.space_xxxs,
spacing.space_xxs,
Expand Down Expand Up @@ -126,7 +129,10 @@ impl AccountsView {
widget::container(
widget::column::with_children(vec![widget::row::with_capacity(2)
.align_items(Alignment::Center)
.push(widget::text::title3(fl!("accounts")))
.push(widget::text::title3(fl!(
"accounts-with-count",
count = self.accounts.len()
)))
.spacing(spacing.space_xxs)
.padding([
spacing.space_none,
Expand Down Expand Up @@ -192,11 +198,7 @@ pub fn add_account<'a>(account: Account) -> Element<'a, Message> {
let api_key_widget_text_input =
widget::secure_input("Token", account.api_token.clone(), None, true)
.on_input(Message::SetAccountAPIKey);
let tls_widget_checkbox = widget::checkbox(
fl!("tls"),
account.tls,
Message::SetAccountTLS,
);
let tls_widget_checkbox = widget::checkbox(fl!("tls"), account.tls, Message::SetAccountTLS);
let buttons_widget_container = widget::container(
widget::button::text(fl!("save"))
.style(widget::button::Style::Standard)
Expand Down Expand Up @@ -232,11 +234,7 @@ pub fn edit_account<'a>(account: Account) -> Element<'a, Message> {
let api_key_widget_text_input =
widget::secure_input("Token", account.api_token.clone(), None, true)
.on_input(Message::SetAccountAPIKey);
let tls_widget_checkbox = widget::checkbox(
fl!("tls"),
account.tls,
Message::SetAccountTLS,
);
let tls_widget_checkbox = widget::checkbox(fl!("tls"), account.tls, Message::SetAccountTLS);
let buttons_widget_container = widget::container(
widget::button::text(fl!("save"))
.style(widget::button::Style::Standard)
Expand Down
28 changes: 13 additions & 15 deletions src/pages/bookmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,17 @@ impl Default for BookmarksView {
impl BookmarksView {
pub fn view<'a>(&'a self) -> Element<'a, BookmarksMessage> {
let spacing = theme::active().cosmic().spacing;
let mut action_button = widget::button::text(fl!("add-bookmark"))
.style(widget::button::Style::Standard)
.on_press(BookmarksMessage::AddBookmark);
let mut page_title_text = widget::text::title3(fl!("no-bookmarks"));
if self.bookmarks.is_empty() && self.query_placeholder.is_empty() {
if self.accounts.is_empty() {
page_title_text = widget::text::title3(fl!("no-accounts"));
action_button = widget::button::text(fl!("open-accounts-page"))
.style(widget::button::Style::Standard)
.on_press(BookmarksMessage::OpenAccountsPage);
}
if self.accounts.is_empty() {
let container = widget::container(
widget::column::with_children(vec![
widget::icon::from_name("web-browser-symbolic")
.size(64)
.into(),
page_title_text.into(),
action_button.into(),
widget::text::title3(fl!("no-accounts")).into(),
widget::button::text(fl!("open-accounts-page"))
.style(widget::button::Style::Standard)
.on_press(BookmarksMessage::OpenAccountsPage)
.into(),
])
.spacing(20)
.align_items(Alignment::Center),
Expand Down Expand Up @@ -193,7 +186,10 @@ impl BookmarksView {
widget::container(
widget::column::with_children(vec![widget::row::with_capacity(3)
.align_items(Alignment::Center)
.push(widget::text::title3(fl!("bookmarks")))
.push(widget::text::title3(fl!(
"bookmarks-with-count",
count = self.bookmarks.len()
)))
.spacing(spacing.space_xxs)
.padding([
spacing.space_none,
Expand Down Expand Up @@ -231,7 +227,9 @@ impl BookmarksView {
commands.push(Command::perform(async {}, |_| Message::OpenAccountsPage));
}
BookmarksMessage::RefreshBookmarks => {
commands.push(Command::perform(async {}, |_| Message::StartRefreshBookmarksForAllAccounts));
commands.push(Command::perform(async {}, |_| {
Message::StartRefreshBookmarksForAllAccounts
}));
}
BookmarksMessage::AddBookmark => {
commands.push(Command::perform(async {}, |_| Message::AddBookmarkForm));
Expand Down

0 comments on commit d849e51

Please sign in to comment.