add UI for (un)follow

Signed-off-by: kernelkind <kernelkind@gmail.com>
Co-authored-by: Jakub Gladysz <jakub.gladysz@protonmail.com>
Co-authored-by: William Casarin <jb55@jb55.com>
This commit is contained in:
kernelkind
2025-07-05 14:27:00 -04:00
parent a883ac8c34
commit 7b9db55a05

View File

@@ -4,6 +4,7 @@ pub use edit::EditProfileView;
use egui::{vec2, Color32, CornerRadius, Layout, Rect, RichText, ScrollArea, Sense, Stroke}; use egui::{vec2, Color32, CornerRadius, Layout, Rect, RichText, ScrollArea, Sense, Stroke};
use enostr::Pubkey; use enostr::Pubkey;
use nostrdb::{ProfileRecord, Transaction}; use nostrdb::{ProfileRecord, Transaction};
use notedeck_ui::profile::follow_button;
use tracing::error; use tracing::error;
use crate::{ use crate::{
@@ -11,8 +12,8 @@ use crate::{
ui::timeline::{tabs_ui, TimelineTabView}, ui::timeline::{tabs_ui, TimelineTabView},
}; };
use notedeck::{ use notedeck::{
name::get_display_name, profile::get_profile_url, Accounts, MuteFun, NoteAction, NoteContext, name::get_display_name, profile::get_profile_url, Accounts, IsFollowing, MuteFun, NoteAction,
NotedeckTextStyle, NoteContext, NotedeckTextStyle,
}; };
use notedeck_ui::{ use notedeck_ui::{
app_images, app_images,
@@ -81,8 +82,8 @@ impl<'a, 'd> ProfileView<'a, 'd> {
.ndb .ndb
.get_profile_by_pubkey(&txn, self.pubkey.bytes()) .get_profile_by_pubkey(&txn, self.pubkey.bytes())
{ {
if self.profile_body(ui, profile) { if let Some(profile_view_action) = self.profile_body(ui, profile) {
action = Some(ProfileViewAction::EditProfile); action = Some(profile_view_action);
} }
} }
let profile_timeline = self let profile_timeline = self
@@ -133,8 +134,12 @@ impl<'a, 'd> ProfileView<'a, 'd> {
output.inner output.inner
} }
fn profile_body(&mut self, ui: &mut egui::Ui, profile: ProfileRecord<'_>) -> bool { fn profile_body(
let mut action = false; &mut self,
ui: &mut egui::Ui,
profile: ProfileRecord<'_>,
) -> Option<ProfileViewAction> {
let mut action = None;
ui.vertical(|ui| { ui.vertical(|ui| {
banner( banner(
ui, ui,
@@ -171,13 +176,49 @@ impl<'a, 'd> ProfileView<'a, 'd> {
ui.ctx().copy_text(to_copy) ui.ctx().copy_text(to_copy)
} }
if self.accounts.contains_full_kp(self.pubkey) { ui.with_layout(Layout::right_to_left(egui::Align::RIGHT), |ui| {
ui.with_layout(Layout::right_to_left(egui::Align::Max), |ui| { ui.add_space(24.0);
if ui.add(edit_profile_button()).clicked() {
action = true; let target_key = self.pubkey;
let selected = self.accounts.get_selected_account();
let profile_type = if selected.key.secret_key.is_none() {
ProfileType::ReadOnly
} else if &selected.key.pubkey == self.pubkey {
ProfileType::MyProfile
} else {
ProfileType::Followable(selected.is_following(target_key))
};
match profile_type {
ProfileType::MyProfile => {
if ui.add(edit_profile_button()).clicked() {
action = Some(ProfileViewAction::EditProfile);
}
} }
}); ProfileType::Followable(is_following) => {
} let follow_button = ui.add(follow_button(is_following));
if follow_button.clicked() {
action = match is_following {
IsFollowing::Unknown => {
// don't do anything, we don't have contact list
None
}
IsFollowing::Yes => {
Some(ProfileViewAction::Unfollow(target_key.to_owned()))
}
IsFollowing::No => {
Some(ProfileViewAction::Follow(target_key.to_owned()))
}
};
}
}
ProfileType::ReadOnly => {}
}
});
}); });
ui.add_space(18.0); ui.add_space(18.0);
@@ -217,6 +258,12 @@ impl<'a, 'd> ProfileView<'a, 'd> {
} }
} }
enum ProfileType {
MyProfile,
ReadOnly,
Followable(IsFollowing),
}
fn handle_link(ui: &mut egui::Ui, website_url: &str) { fn handle_link(ui: &mut egui::Ui, website_url: &str) {
let img = if ui.visuals().dark_mode { let img = if ui.visuals().dark_mode {
app_images::link_image() app_images::link_image()