Skip to content

Commit

Permalink
Adds view for hashtags
Browse files Browse the repository at this point in the history
  • Loading branch information
sanpii committed Dec 19, 2024
1 parent 6cd7ade commit fb810a2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ version = "0.4"
features = ["std"]

[dependencies.todo-txt]
version = "4.0"
version = "4.1"
features = ["config", "extended"]

[build-dependencies]
Expand Down
1 change: 1 addition & 0 deletions resources/resource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<file>inbox.png</file>
<file>projects.png</file>
<file>search.png</file>
<file>tags.png</file>
<file compressed="true">style.css</file>
<file compressed="true">style_dark.css</file>
<file compressed="true">style_light.css</file>
Expand Down
Binary file added resources/tags.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 18 additions & 4 deletions src/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum Page {
Flag,
Done,
Search,
Tags,
}

impl From<u32> for Page {
Expand All @@ -30,10 +31,11 @@ impl From<u32> for Page {
0 => Page::Inbox,
1 => Page::Projects,
2 => Page::Contexts,
3 => Page::Agenda,
4 => Page::Flag,
5 => Page::Done,
6 => Page::Search,
3 => Page::Tags,
4 => Page::Agenda,
5 => Page::Flag,
6 => Page::Done,
7 => Page::Search,
_ => panic!("Invalid page {n}"),
}
}
Expand Down Expand Up @@ -67,6 +69,7 @@ pub struct Model {
logger: relm4::Controller<crate::logger::Model>,
projects: relm4::Controller<crate::widgets::tags::Model>,
search: relm4::Controller<crate::search::Model>,
tags: relm4::Controller<crate::widgets::tags::Model>,
}

impl Model {
Expand Down Expand Up @@ -120,6 +123,7 @@ impl Model {
Page::Flag => "flag",
Page::Done => "done",
Page::Search => "search",
Page::Tags => "tags",
};

let image = gtk::Image::from_icon_name(title);
Expand Down Expand Up @@ -250,6 +254,7 @@ impl Model {
self.flag.sender().emit(crate::flag::Msg::Update);
self.inbox.sender().emit(crate::inbox::Msg::Update);
self.search.sender().emit(crate::search::MsgInput::Update);
self.tags.sender().emit(crate::widgets::tags::MsgInput::Update);
}

fn watch(&self, sender: relm4::ComponentSender<Self>) {
Expand Down Expand Up @@ -348,6 +353,13 @@ impl relm4::Component for Model {
crate::widgets::task::MsgOutput::Edit(task) => Msg::Edit(task),
});

let tags = crate::widgets::tags::Model::builder()
.launch(crate::widgets::tags::Type::Hashtags)
.forward(sender.input_sender(), |output| match output {
crate::widgets::tags::MsgOutput::Complete(task) => Msg::Complete(task),
crate::widgets::tags::MsgOutput::Edit(task) => Msg::Edit(task),
});

let model = Self {
agenda,
config: init,
Expand All @@ -359,6 +371,7 @@ impl relm4::Component for Model {
logger,
projects,
search,
tags,
};

let widgets = view_output!();
Expand Down Expand Up @@ -468,6 +481,7 @@ impl relm4::Component for Model {
append_page: (model.inbox.widget(), None::<&gtk::Label>),
append_page: (model.projects.widget(), None::<&gtk::Label>),
append_page: (model.contexts.widget(), None::<&gtk::Label>),
append_page: (model.tags.widget(), None::<&gtk::Label>),
append_page: (model.agenda.widget(), None::<&gtk::Label>),
append_page: (model.flag.widget(), None::<&gtk::Label>),
append_page: (model.done.widget(), None::<&gtk::Label>),
Expand Down
2 changes: 1 addition & 1 deletion src/inbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Model {
.iter()
.filter(|x| {
!x.finished
&& x.projects().is_empty()
&& x.projects.is_empty()
&& (preferences.defered
|| x.threshold_date.is_none()
|| x.threshold_date.unwrap() <= today)
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Task {
})
.into_owned();

let regex = regex::Regex::new(r"(?P<space>^|[\s])(?P<tag>[\+@][\w\-\\]+)").unwrap();
let regex = regex::Regex::new(r"(?P<space>^|[\s])(?P<tag>[\+@#][\w\-\\]+)").unwrap();
subject = regex
.replace_all(&subject, "$space<b>$tag</b>")
.into_owned();
Expand Down
9 changes: 6 additions & 3 deletions src/widgets/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use relm4::ComponentController as _;
pub enum Type {
Projects,
Contexts,
Hashtags,
}

#[derive(Debug)]
Expand Down Expand Up @@ -32,6 +33,7 @@ impl Model {
let tags = match self.tag {
Type::Projects => list.projects(),
Type::Contexts => list.contexts(),
Type::Hashtags => list.hashtags(),
};

let tags = tags
Expand Down Expand Up @@ -78,7 +80,7 @@ impl Model {

(preferences.done || !x.finished)
&& !tags.is_empty()
&& Self::has_filter(tags, filters)
&& Self::has_filter(&tags, filters)
&& (preferences.defered
|| x.threshold_date.is_none()
|| x.threshold_date.unwrap() <= today)
Expand All @@ -92,8 +94,9 @@ impl Model {

fn tags<'a>(&self, task: &'a crate::tasks::Task) -> &'a [String] {
match self.tag {
Type::Projects => task.projects(),
Type::Contexts => task.contexts(),
Type::Projects => &task.projects,
Type::Contexts => &task.contexts,
Type::Hashtags => &task.hashtags,
}
}

Expand Down

0 comments on commit fb810a2

Please sign in to comment.