Files
damus/damus/Features/Profile/Views/AboutView.swift
Daniel D’Aquino fc1eb326e8 Render profile bios
Note: This brings us closer to feature parity with the master branch, so there
is no changelog item to be added

Closes: https://github.com/damus-io/damus/issues/3156
Changelog-None
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2025-08-11 16:40:01 -07:00

62 lines
2.0 KiB
Swift

//
// AboutView.swift
// damus
//
// Created by William Casarin on 2023-06-18.
//
import SwiftUI
struct AboutView: View {
let state: DamusState
let about: String
let max_about_length: Int
let text_alignment: NSTextAlignment
@State var show_full_about: Bool = false
@State private var about_string: AttributedString? = nil
init(state: DamusState, about: String, max_about_length: Int? = nil, text_alignment: NSTextAlignment? = nil) {
self.state = state
self.about = about
self.max_about_length = max_about_length ?? 280
self.text_alignment = text_alignment ?? .natural
}
var body: some View {
Group {
if let about_string {
let truncated_about = show_full_about ? about_string : about_string.truncateOrNil(maxLength: max_about_length)
SelectableText(damus_state: state, event: nil, attributedString: truncated_about ?? about_string, textAlignment: self.text_alignment, size: .subheadline)
if truncated_about != nil {
if show_full_about {
Button(NSLocalizedString("Show less", comment: "Button to show less of a long profile description.")) {
show_full_about = false
}
.font(.footnote)
} else {
Button(NSLocalizedString("Show more", comment: "Button to show more of a long profile description.")) {
show_full_about = true
}
.font(.footnote)
}
}
} else {
Text(verbatim: "")
.font(.subheadline)
}
}
.onAppear {
guard let blocks = try? NdbBlockGroup.parse(content: about) else { return }
self.about_string = render_blocks(blocks: blocks, profiles: state.profiles).content.attributed
}
}
}
/*
#Preview {
AboutView()
}
*/