add new column type: hashtag

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2024-11-21 20:15:26 -05:00
parent 679a5afdeb
commit 792abf11d7
4 changed files with 79 additions and 18 deletions

View File

@@ -113,6 +113,7 @@ impl Route {
AddColumnRoute::ExternalNotification => {
"Add External Notifications Column".to_owned()
}
AddColumnRoute::Hashtag => "Add Hashtag Column".to_owned(),
},
Route::Support => "Damus Support".to_owned(),
};

View File

@@ -40,6 +40,8 @@ pub enum TimelineKind {
/// Generic filter
Generic,
Hashtag(String),
}
impl Display for TimelineKind {
@@ -50,6 +52,7 @@ impl Display for TimelineKind {
TimelineKind::Notifications(_) => f.write_str("Notifications"),
TimelineKind::Profile(_) => f.write_str("Profile"),
TimelineKind::Universe => f.write_str("Universe"),
TimelineKind::Hashtag(_) => f.write_str("Hashtag"),
}
}
}
@@ -126,6 +129,19 @@ impl TimelineKind {
))
}
TimelineKind::Hashtag(hashtag) => {
let filter = Filter::new()
.kinds([1])
.limit(filter::default_limit())
.tags([hashtag.clone()], 't')
.build();
Some(Timeline::new(
TimelineKind::Hashtag(hashtag),
FilterState::ready(vec![filter]),
))
}
TimelineKind::List(ListKind::Contact(pk_src)) => {
let pk = match &pk_src {
PubkeySource::DeckAuthor => default_user?,
@@ -186,6 +202,7 @@ impl TimelineKind {
},
TimelineKind::Universe => "Universe".to_owned(),
TimelineKind::Generic => "Custom Filter".to_owned(),
TimelineKind::Hashtag(hashtag) => format!("#{}", hashtag),
}
}
}

View File

@@ -24,6 +24,7 @@ pub enum AddColumnResponse {
Timeline(Timeline),
UndecidedNotification,
ExternalNotification,
Hashtag,
}
pub enum NotificationColumnType {
@@ -38,6 +39,8 @@ enum AddColumnOption {
ExternalNotification,
Notification(PubkeySource),
Home(PubkeySource),
UndecidedHashtag,
Hashtag(String),
}
#[derive(Clone, Copy, Eq, PartialEq, Debug, Serialize, Deserialize)]
@@ -45,6 +48,7 @@ pub enum AddColumnRoute {
Base,
UndecidedNotification,
ExternalNotification,
Hashtag,
}
impl AddColumnOption {
@@ -69,6 +73,10 @@ impl AddColumnOption {
.map(AddColumnResponse::Timeline)
}
AddColumnOption::ExternalNotification => Some(AddColumnResponse::ExternalNotification),
AddColumnOption::UndecidedHashtag => Some(AddColumnResponse::Hashtag),
AddColumnOption::Hashtag(hashtag) => TimelineKind::Hashtag(hashtag)
.into_timeline(ndb, None)
.map(AddColumnResponse::Timeline),
}
}
}
@@ -292,6 +300,12 @@ impl<'a> AddColumnView<'a> {
icon: egui::include_image!("../../assets/icons/notifications_icon_dark_4x.png"),
option: AddColumnOption::UndecidedNotification,
});
vec.push(ColumnOptionData {
title: "Hashtag",
description: "Stay up to date with a certain hashtag",
icon: egui::include_image!("../../assets/icons/notifications_icon_dark_4x.png"),
option: AddColumnOption::UndecidedHashtag,
});
vec
}
@@ -338,25 +352,16 @@ pub fn render_add_column_routes(
col: usize,
route: &AddColumnRoute,
) {
let mut add_column_view = AddColumnView::new(
&mut app.view_state.id_state_map,
&app.ndb,
app.accounts.get_selected_account(),
);
let resp = match route {
AddColumnRoute::Base => AddColumnView::new(
&mut app.view_state.id_state_map,
&app.ndb,
app.accounts.get_selected_account(),
)
.ui(ui),
AddColumnRoute::UndecidedNotification => AddColumnView::new(
&mut app.view_state.id_state_map,
&app.ndb,
app.accounts.get_selected_account(),
)
.notifications_ui(ui),
AddColumnRoute::ExternalNotification => AddColumnView::new(
&mut app.view_state.id_state_map,
&app.ndb,
app.accounts.get_selected_account(),
)
.external_notification_ui(ui),
AddColumnRoute::Base => add_column_view.ui(ui),
AddColumnRoute::UndecidedNotification => add_column_view.notifications_ui(ui),
AddColumnRoute::ExternalNotification => add_column_view.external_notification_ui(ui),
AddColumnRoute::Hashtag => hashtag_ui(ui, &app.ndb, &mut app.view_state.id_string_map),
};
if let Some(resp) = resp {
@@ -382,10 +387,47 @@ pub fn render_add_column_routes(
crate::route::Route::AddColumn(AddColumnRoute::ExternalNotification),
);
}
AddColumnResponse::Hashtag => {
app.columns_mut()
.column_mut(col)
.router_mut()
.route_to(crate::route::Route::AddColumn(AddColumnRoute::Hashtag));
}
};
}
}
pub fn hashtag_ui(
ui: &mut Ui,
ndb: &Ndb,
id_string_map: &mut HashMap<Id, String>,
) -> Option<AddColumnResponse> {
padding(16.0, ui, |ui| {
let id = ui.id().with("hashtag");
let text_buffer = id_string_map.entry(id).or_default();
let text_edit = egui::TextEdit::singleline(text_buffer)
.hint_text(
RichText::new("Enter the desired hashtag here")
.text_style(NotedeckTextStyle::Body.text_style()),
)
.vertical_align(Align::Center)
.desired_width(f32::INFINITY)
.min_size(Vec2::new(0.0, 40.0))
.margin(Margin::same(12.0));
ui.add(text_edit);
if ui.button("Add").clicked() {
let resp = AddColumnOption::Hashtag(text_buffer.to_owned()).take_as_response(ndb, None);
id_string_map.remove(&id);
resp
} else {
None
}
})
.inner
}
mod preview {
use crate::{
test_data,

View File

@@ -7,6 +7,7 @@ use crate::login_manager::AcquireKeyState;
pub struct ViewState {
pub login: AcquireKeyState,
pub id_state_map: HashMap<egui::Id, AcquireKeyState>,
pub id_string_map: HashMap<egui::Id, String>,
}
impl ViewState {