ui: truncate visible media URL
The URL shown to the user before they click the 'Load Media' button can take up a large portion of the screen, and doesn't offer any value to the user. This patch features a naive approach to truncate the URL to be a certain number of characters if it is greater than the specified value. Right now the maximum number of characters is set to 80. Closes: https://github.com/damus-io/damus/issues/1950 Lightning-address: kernelkind@getalby.com Signed-off-by: kernelkind <kernelkind@gmail.com> Link: 20240130183525.50446-1-kernelkind@gmail.com Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
5f9477d55b
commit
86e9ee16a0
@@ -7,6 +7,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
fileprivate let MAX_CHAR_URL = 80
|
||||
|
||||
private func remove_damus_uri_prefix(_ s: String) -> String {
|
||||
var uri = s.replacingOccurrences(of: "https://damus.io/r/", with: "")
|
||||
uri = uri.replacingOccurrences(of: "https://damus.io/", with: "")
|
||||
@@ -32,3 +34,12 @@ func remove_nostr_uri_prefix(_ s: String) -> String {
|
||||
|
||||
return uri
|
||||
}
|
||||
|
||||
func abbreviateURL(_ url: URL) -> String {
|
||||
let urlString = url.absoluteString
|
||||
|
||||
if urlString.count > MAX_CHAR_URL {
|
||||
return String(urlString.prefix(MAX_CHAR_URL)) + "..."
|
||||
}
|
||||
return urlString
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ struct NoteContentView: View {
|
||||
.frame(height: 1)
|
||||
switch artifacts.media[index] {
|
||||
case .image(let url), .video(let url):
|
||||
Text(url.absoluteString)
|
||||
Text(abbreviateURL(url))
|
||||
.font(eventviewsize_to_font(size, font_size: damus_state.settings.font_size))
|
||||
.foregroundStyle(DamusColors.neutral6)
|
||||
.multilineTextAlignment(.leading)
|
||||
|
||||
Reference in New Issue
Block a user