add new column type: hashtag
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -113,6 +113,7 @@ impl Route {
|
|||||||
AddColumnRoute::ExternalNotification => {
|
AddColumnRoute::ExternalNotification => {
|
||||||
"Add External Notifications Column".to_owned()
|
"Add External Notifications Column".to_owned()
|
||||||
}
|
}
|
||||||
|
AddColumnRoute::Hashtag => "Add Hashtag Column".to_owned(),
|
||||||
},
|
},
|
||||||
Route::Support => "Damus Support".to_owned(),
|
Route::Support => "Damus Support".to_owned(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ pub enum TimelineKind {
|
|||||||
|
|
||||||
/// Generic filter
|
/// Generic filter
|
||||||
Generic,
|
Generic,
|
||||||
|
|
||||||
|
Hashtag(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for TimelineKind {
|
impl Display for TimelineKind {
|
||||||
@@ -50,6 +52,7 @@ impl Display for TimelineKind {
|
|||||||
TimelineKind::Notifications(_) => f.write_str("Notifications"),
|
TimelineKind::Notifications(_) => f.write_str("Notifications"),
|
||||||
TimelineKind::Profile(_) => f.write_str("Profile"),
|
TimelineKind::Profile(_) => f.write_str("Profile"),
|
||||||
TimelineKind::Universe => f.write_str("Universe"),
|
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)) => {
|
TimelineKind::List(ListKind::Contact(pk_src)) => {
|
||||||
let pk = match &pk_src {
|
let pk = match &pk_src {
|
||||||
PubkeySource::DeckAuthor => default_user?,
|
PubkeySource::DeckAuthor => default_user?,
|
||||||
@@ -186,6 +202,7 @@ impl TimelineKind {
|
|||||||
},
|
},
|
||||||
TimelineKind::Universe => "Universe".to_owned(),
|
TimelineKind::Universe => "Universe".to_owned(),
|
||||||
TimelineKind::Generic => "Custom Filter".to_owned(),
|
TimelineKind::Generic => "Custom Filter".to_owned(),
|
||||||
|
TimelineKind::Hashtag(hashtag) => format!("#{}", hashtag),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ pub enum AddColumnResponse {
|
|||||||
Timeline(Timeline),
|
Timeline(Timeline),
|
||||||
UndecidedNotification,
|
UndecidedNotification,
|
||||||
ExternalNotification,
|
ExternalNotification,
|
||||||
|
Hashtag,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum NotificationColumnType {
|
pub enum NotificationColumnType {
|
||||||
@@ -38,6 +39,8 @@ enum AddColumnOption {
|
|||||||
ExternalNotification,
|
ExternalNotification,
|
||||||
Notification(PubkeySource),
|
Notification(PubkeySource),
|
||||||
Home(PubkeySource),
|
Home(PubkeySource),
|
||||||
|
UndecidedHashtag,
|
||||||
|
Hashtag(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||||
@@ -45,6 +48,7 @@ pub enum AddColumnRoute {
|
|||||||
Base,
|
Base,
|
||||||
UndecidedNotification,
|
UndecidedNotification,
|
||||||
ExternalNotification,
|
ExternalNotification,
|
||||||
|
Hashtag,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddColumnOption {
|
impl AddColumnOption {
|
||||||
@@ -69,6 +73,10 @@ impl AddColumnOption {
|
|||||||
.map(AddColumnResponse::Timeline)
|
.map(AddColumnResponse::Timeline)
|
||||||
}
|
}
|
||||||
AddColumnOption::ExternalNotification => Some(AddColumnResponse::ExternalNotification),
|
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"),
|
icon: egui::include_image!("../../assets/icons/notifications_icon_dark_4x.png"),
|
||||||
option: AddColumnOption::UndecidedNotification,
|
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
|
vec
|
||||||
}
|
}
|
||||||
@@ -338,25 +352,16 @@ pub fn render_add_column_routes(
|
|||||||
col: usize,
|
col: usize,
|
||||||
route: &AddColumnRoute,
|
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 {
|
let resp = match route {
|
||||||
AddColumnRoute::Base => AddColumnView::new(
|
AddColumnRoute::Base => add_column_view.ui(ui),
|
||||||
&mut app.view_state.id_state_map,
|
AddColumnRoute::UndecidedNotification => add_column_view.notifications_ui(ui),
|
||||||
&app.ndb,
|
AddColumnRoute::ExternalNotification => add_column_view.external_notification_ui(ui),
|
||||||
app.accounts.get_selected_account(),
|
AddColumnRoute::Hashtag => hashtag_ui(ui, &app.ndb, &mut app.view_state.id_string_map),
|
||||||
)
|
|
||||||
.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),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(resp) = resp {
|
if let Some(resp) = resp {
|
||||||
@@ -382,10 +387,47 @@ pub fn render_add_column_routes(
|
|||||||
crate::route::Route::AddColumn(AddColumnRoute::ExternalNotification),
|
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 {
|
mod preview {
|
||||||
use crate::{
|
use crate::{
|
||||||
test_data,
|
test_data,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::login_manager::AcquireKeyState;
|
|||||||
pub struct ViewState {
|
pub struct ViewState {
|
||||||
pub login: AcquireKeyState,
|
pub login: AcquireKeyState,
|
||||||
pub id_state_map: HashMap<egui::Id, AcquireKeyState>,
|
pub id_state_map: HashMap<egui::Id, AcquireKeyState>,
|
||||||
|
pub id_string_map: HashMap<egui::Id, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ViewState {
|
impl ViewState {
|
||||||
|
|||||||
Reference in New Issue
Block a user