Skip to content

Commit

Permalink
status: support clickable status urls
Browse files Browse the repository at this point in the history
Changelog-Added: Add support for status URLs
  • Loading branch information
jb55 committed Aug 24, 2023
1 parent 981d500 commit 2c6999e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
6 changes: 2 additions & 4 deletions damus/Components/Status/UserStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import MediaPlayer
struct Song {
let started_playing: Date
let content: String


}

struct UserStatus {
let type: UserStatusType
let expires_at: Date?
let content: String
var content: String
let created_at: UInt32
let url: URL?
var url: URL?

func to_note(keypair: FullKeypair) -> NostrEvent? {
return make_user_status_note(status: self, keypair: keypair)
Expand Down
27 changes: 26 additions & 1 deletion damus/Components/Status/UserStatusSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,31 @@ struct UserStatusSheet: View {
let keypair: Keypair

@State var duration: StatusDuration = .never

@ObservedObject var status: UserStatusModel
@Environment(\.dismiss) var dismiss

var status_binding: Binding<String> {
Binding(get: {
status.general?.content ?? ""
}, set: { v in
status.general = UserStatus(type: .general, expires_at: duration.expiration, content: v, created_at: UInt32(Date.now.timeIntervalSince1970))
if let general = status.general {
status.general = UserStatus(type: .general, expires_at: duration.expiration, content: v, created_at: UInt32(Date.now.timeIntervalSince1970), url: general.url)
} else {
status.general = UserStatus(type: .general, expires_at: duration.expiration, content: v, created_at: UInt32(Date.now.timeIntervalSince1970), url: nil)
}
})
}

var url_binding: Binding<String> {
Binding(get: {
status.general?.url?.absoluteString ?? ""
}, set: { v in
if let general = status.general {
status.general = UserStatus(type: .general, expires_at: duration.expiration, content: general.content, created_at: UInt32(Date.now.timeIntervalSince1970), url: URL(string: v))
} else {
status.general = UserStatus(type: .general, expires_at: duration.expiration, content: "", created_at: UInt32(Date.now.timeIntervalSince1970), url: URL(string: v))
}
})
}

Expand All @@ -58,6 +75,14 @@ struct UserStatusSheet: View {
Text("📋 Working")
})

HStack {
Image("link")

TextField(text: url_binding, label: {
Text("https://example.com")
})
}

HStack {
Text("Clear status")

Expand Down
45 changes: 26 additions & 19 deletions damus/Components/Status/UserStatusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,45 @@ struct UserStatusView: View {

@Environment(\.openURL) var openURL

func Status(st: UserStatus, prefix: String = "") -> some View {
HStack {
Text(verbatim: "\(prefix)\(st.content)")
.lineLimit(1)
.foregroundColor(.gray)
.font(.callout.italic())
if st.url != nil {
Image("link")
.resizable()
.frame(width: 16, height: 16)
.foregroundColor(.gray)
}
}
.onTapGesture {
if let url = st.url {
openURL(url)
}
}
}

var body: some View {
VStack(alignment: .leading, spacing: 2) {
if show_general, let general = status.general {
Text(verbatim: "\(general.content)")
.lineLimit(1)
.foregroundColor(.gray)
.font(.callout.italic())
.onTapGesture {
if let url = general.url {
openURL(url)
}
}
Status(st: general)
}

if show_music, let playing = status.music {
Text(verbatim: "🎵\(playing.content)")
.lineLimit(1)
.foregroundColor(.gray)
.font(.callout.italic())
.onTapGesture {
if let url = playing.url {
openURL(url)
}
}
Status(st: playing, prefix: "🎵")
}
}

}
}

/*
struct UserStatusView_Previews: PreviewProvider {
static var previews: some View {
UserStatusView(status: .init(), show_general: true, show_music: true)
UserStatusView(status: UserStatus(type: .music, expires_at: nil, content: "Track - Artist", created_at: 0, url: URL(string: "spotify:search:abc")), show_general: true, show_music: true)
}
}
*/

0 comments on commit 2c6999e

Please sign in to comment.