profile: move the "Follow you" badge into the profile header
Move the "Follow you" badge into the profile header he profile header out-of-line with the often long and already space-constrained username/display name text Changelog-Changed: Move the "Follow you" badge into the profile header Closes: https://github.com/damus-io/damus/pull/1529 Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
f6f7d13f12
commit
b18a0c573e
@@ -71,18 +71,6 @@ func should_show_images(settings: UserSettingsStore, contacts: Contacts, ev: Nos
|
||||
return false
|
||||
}
|
||||
|
||||
extension View {
|
||||
func pubkey_context_menu(pubkey: Pubkey) -> some View {
|
||||
return self.contextMenu {
|
||||
Button {
|
||||
UIPasteboard.general.string = pubkey.npub
|
||||
} label: {
|
||||
Label(NSLocalizedString("Copy Account ID", comment: "Context menu option for copying the ID of the account that created the note."), image: "copy2")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func format_relative_time(_ created_at: UInt32) -> String
|
||||
{
|
||||
return time_ago_since(Date(timeIntervalSince1970: Double(created_at)))
|
||||
|
||||
@@ -87,7 +87,7 @@ struct NotificationsView: View {
|
||||
|
||||
var mystery: some View {
|
||||
VStack(spacing: 20) {
|
||||
Text("Wake up, \(Profile.displayName(profile: state.profiles.lookup(id: state.pubkey), pubkey: state.pubkey).display_name.truncate(maxLength: 50))", comment: "Text telling the user to wake up, where the argument is their display name.")
|
||||
Text("Wake up, \(Profile.displayName(profile: state.profiles.lookup(id: state.pubkey), pubkey: state.pubkey).displayName.truncate(maxLength: 50))", comment: "Text telling the user to wake up, where the argument is their display name.")
|
||||
Text("You are dreaming...", comment: "Text telling the user that they are dreaming.")
|
||||
}
|
||||
.id("what")
|
||||
|
||||
@@ -63,11 +63,11 @@ struct EventProfileName: View {
|
||||
Text(one)
|
||||
.font(.body.weight(.bold))
|
||||
|
||||
case .both(let both):
|
||||
Text(both.display_name)
|
||||
case .both(username: let username, displayName: let displayName):
|
||||
Text(verbatim: displayName)
|
||||
.font(.body.weight(.bold))
|
||||
|
||||
Text(verbatim: "@\(both.username)")
|
||||
Text(verbatim: username)
|
||||
.foregroundColor(.gray)
|
||||
.font(eventviewsize_to_font(size, font_size: damus_state.settings.font_size))
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//
|
||||
// FollowsYou.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-02-07.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct FollowsYou: View {
|
||||
|
||||
var body: some View {
|
||||
Text("Follows you", comment: "Text to indicate that a user is following your profile.")
|
||||
.padding([.leading, .trailing], 6.0)
|
||||
.padding([.top, .bottom], 2.0)
|
||||
.foregroundColor(.gray)
|
||||
.background {
|
||||
RoundedRectangle(cornerRadius: 5.0)
|
||||
.foregroundColor(DamusColors.adaptableGrey)
|
||||
}
|
||||
.font(.footnote)
|
||||
}
|
||||
}
|
||||
|
||||
struct FollowsYou_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
FollowsYou()
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ struct ProfileName: View {
|
||||
}
|
||||
|
||||
var name_choice: String {
|
||||
return prefix == "@" ? current_display_name.username.truncate(maxLength: 50) : current_display_name.display_name.truncate(maxLength: 50)
|
||||
return prefix == "@" ? current_display_name.username.truncate(maxLength: 50) : current_display_name.displayName.truncate(maxLength: 50)
|
||||
}
|
||||
|
||||
var onlyzapper: Bool {
|
||||
|
||||
@@ -7,10 +7,87 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
fileprivate struct KeyView: View {
|
||||
let pubkey: Pubkey
|
||||
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
|
||||
@State private var isCopied = false
|
||||
|
||||
func keyColor() -> Color {
|
||||
colorScheme == .light ? DamusColors.black : DamusColors.white
|
||||
}
|
||||
|
||||
private func copyPubkey(_ pubkey: String) {
|
||||
UIPasteboard.general.string = pubkey
|
||||
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
||||
withAnimation {
|
||||
isCopied = true
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
|
||||
withAnimation {
|
||||
isCopied = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func pubkey_context_menu(pubkey: Pubkey) -> some View {
|
||||
return self.contextMenu {
|
||||
Button {
|
||||
UIPasteboard.general.string = pubkey.npub
|
||||
} label: {
|
||||
Label(NSLocalizedString("Copy Account ID", comment: "Context menu option for copying the ID of the account that created the note."), image: "copy2")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let bech32 = pubkey.npub
|
||||
|
||||
HStack {
|
||||
Text(verbatim: "\(abbrev_pubkey(bech32, amount: 16))")
|
||||
.font(.footnote)
|
||||
.foregroundColor(keyColor())
|
||||
.padding(5)
|
||||
.padding([.leading, .trailing], 5)
|
||||
.background(RoundedRectangle(cornerRadius: 11).foregroundColor(DamusColors.adaptableGrey))
|
||||
|
||||
if isCopied {
|
||||
HStack {
|
||||
Image("check-circle")
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
Text(NSLocalizedString("Copied", comment: "Label indicating that a user's key was copied."))
|
||||
.font(.footnote)
|
||||
.layoutPriority(1)
|
||||
}
|
||||
.foregroundColor(DamusColors.green)
|
||||
} else {
|
||||
HStack {
|
||||
Button {
|
||||
copyPubkey(bech32)
|
||||
} label: {
|
||||
Label {
|
||||
Text("Public key", comment: "Label indicating that the text is a user's public account key.")
|
||||
} icon: {
|
||||
Image("copy2")
|
||||
.resizable()
|
||||
.contentShape(Rectangle())
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(width: 20, height: 20)
|
||||
}
|
||||
.labelStyle(IconOnlyLabelStyle())
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ProfileNameView: View {
|
||||
let pubkey: Pubkey
|
||||
let profile: Profile?
|
||||
let follows_you: Bool
|
||||
let damus: DamusState
|
||||
|
||||
var spacing: CGFloat { 10.0 }
|
||||
@@ -23,22 +100,15 @@ struct ProfileNameView: View {
|
||||
HStack(alignment: .center, spacing: spacing) {
|
||||
ProfileName(pubkey: pubkey, profile: profile, damus: damus)
|
||||
.font(.title3.weight(.bold))
|
||||
if follows_you {
|
||||
FollowsYou()
|
||||
}
|
||||
}
|
||||
case .both(let both):
|
||||
Text(both.display_name)
|
||||
case .both(username: _, displayName: let displayName):
|
||||
Text(displayName)
|
||||
.font(.title3.weight(.bold))
|
||||
|
||||
HStack(alignment: .center, spacing: spacing) {
|
||||
ProfileName(pubkey: pubkey, profile: profile, prefix: "@", damus: damus)
|
||||
.font(.callout)
|
||||
.foregroundColor(.gray)
|
||||
|
||||
if follows_you {
|
||||
FollowsYou()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +124,9 @@ struct ProfileNameView: View {
|
||||
struct ProfileNameView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack {
|
||||
ProfileNameView(pubkey: test_note.pubkey, profile: nil, follows_you: true, damus: test_damus_state())
|
||||
ProfileNameView(pubkey: test_note.pubkey, profile: nil, damus: test_damus_state())
|
||||
|
||||
ProfileNameView(pubkey: test_note.pubkey, profile: nil, follows_you: false, damus: test_damus_state())
|
||||
ProfileNameView(pubkey: test_note.pubkey, profile: nil, damus: test_damus_state())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,6 +255,18 @@ struct ProfileView: View {
|
||||
.profile_button_style(scheme: colorScheme)
|
||||
}
|
||||
}
|
||||
|
||||
private var followsYouBadge: some View {
|
||||
Text("Follows you", comment: "Text to indicate that a user is following your profile.")
|
||||
.padding([.leading, .trailing], 6.0)
|
||||
.padding([.top, .bottom], 2.0)
|
||||
.foregroundColor(.gray)
|
||||
.background {
|
||||
RoundedRectangle(cornerRadius: 5.0)
|
||||
.foregroundColor(DamusColors.adaptableGrey)
|
||||
}
|
||||
.font(.footnote)
|
||||
}
|
||||
|
||||
func actionSection(profile_data: Profile?) -> some View {
|
||||
return Group {
|
||||
@@ -310,12 +322,16 @@ struct ProfileView: View {
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
let follows_you = profile.pubkey != damus_state.pubkey && profile.follows(pubkey: damus_state.pubkey)
|
||||
if follows_you {
|
||||
followsYouBadge
|
||||
}
|
||||
|
||||
actionSection(profile_data: profile_data)
|
||||
}
|
||||
|
||||
let follows_you = profile.pubkey != damus_state.pubkey && profile.follows(pubkey: damus_state.pubkey)
|
||||
ProfileNameView(pubkey: profile.pubkey, profile: profile_data, follows_you: follows_you, damus: damus_state)
|
||||
|
||||
ProfileNameView(pubkey: profile.pubkey, profile: profile_data, damus: damus_state)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,72 +505,6 @@ struct ProfileView_Previews: PreviewProvider {
|
||||
}
|
||||
}
|
||||
|
||||
struct KeyView: View {
|
||||
let pubkey: Pubkey
|
||||
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
|
||||
@State private var isCopied = false
|
||||
|
||||
func keyColor() -> Color {
|
||||
colorScheme == .light ? DamusColors.black : DamusColors.white
|
||||
}
|
||||
|
||||
private func copyPubkey(_ pubkey: String) {
|
||||
UIPasteboard.general.string = pubkey
|
||||
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
||||
withAnimation {
|
||||
isCopied = true
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
|
||||
withAnimation {
|
||||
isCopied = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let bech32 = pubkey.npub
|
||||
|
||||
HStack {
|
||||
Text(verbatim: "\(abbrev_pubkey(bech32, amount: 16))")
|
||||
.font(.footnote)
|
||||
.foregroundColor(keyColor())
|
||||
.padding(5)
|
||||
.padding([.leading, .trailing], 5)
|
||||
.background(RoundedRectangle(cornerRadius: 11).foregroundColor(DamusColors.adaptableGrey))
|
||||
|
||||
if isCopied != true {
|
||||
Button {
|
||||
copyPubkey(bech32)
|
||||
} label: {
|
||||
Label {
|
||||
Text("Public key", comment: "Label indicating that the text is a user's public account key.")
|
||||
} icon: {
|
||||
Image("copy2")
|
||||
.resizable()
|
||||
.contentShape(Rectangle())
|
||||
.foregroundColor(.accentColor)
|
||||
.frame(width: 20, height: 20)
|
||||
}
|
||||
.labelStyle(IconOnlyLabelStyle())
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
}
|
||||
} else {
|
||||
HStack {
|
||||
Image("check-circle")
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
Text(NSLocalizedString("Copied", comment: "Label indicating that a user's key was copied."))
|
||||
.font(.footnote)
|
||||
.layoutPriority(1)
|
||||
}
|
||||
.foregroundColor(DamusColors.green)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func profile_button_style(scheme: ColorScheme) -> some View {
|
||||
self.symbolRenderingMode(.palette)
|
||||
|
||||
Reference in New Issue
Block a user