Status actions count

This commit is contained in:
Thomas Ricouard 2022-12-19 16:17:25 +01:00
parent 3850dab340
commit 103db56ea4
2 changed files with 59 additions and 24 deletions

View file

@ -7,6 +7,9 @@ public protocol AnyStatus {
var createdAt: String { get }
var mediaAttachments: [MediaAttachement] { get }
var mentions: [Mention] { get }
var repliesCount: Int { get }
var reblogsCount: Int { get }
var favouritesCount: Int { get }
}
public struct Status: AnyStatus, Codable, Identifiable {
@ -17,6 +20,9 @@ public struct Status: AnyStatus, Codable, Identifiable {
public let reblog: ReblogStatus?
public let mediaAttachments: [MediaAttachement]
public let mentions: [Mention]
public let repliesCount: Int
public let reblogsCount: Int
public let favouritesCount: Int
public static func placeholder() -> Status {
.init(id: UUID().uuidString,
@ -25,7 +31,10 @@ public struct Status: AnyStatus, Codable, Identifiable {
createdAt: "2022-12-16T10:20:54.000Z",
reblog: nil,
mediaAttachments: [],
mentions: [])
mentions: [],
repliesCount: 0,
reblogsCount: 0,
favouritesCount: 0)
}
public static func placeholders() -> [Status] {
@ -40,4 +49,7 @@ public struct ReblogStatus: AnyStatus, Codable, Identifiable {
public let createdAt: String
public let mediaAttachments: [MediaAttachement]
public let mentions: [Mention]
public let repliesCount: Int
public let reblogsCount: Int
public let favouritesCount: Int
}

View file

@ -5,31 +5,54 @@ import Routeur
struct StatusActionsView: View {
let status: Status
enum Actions: CaseIterable {
case respond, boost, favourite, share
var iconName: String {
switch self {
case .respond:
return "bubble.right"
case .boost:
return "arrow.left.arrow.right.circle"
case .favourite:
return "star"
case .share:
return "square.and.arrow.up"
}
}
func count(status: Status) -> Int? {
switch self {
case .respond:
return status.repliesCount
case .favourite:
return status.favouritesCount
case .boost:
return status.reblogsCount
case .share:
return nil
}
}
}
var body: some View {
HStack {
Button {
} label: {
Image(systemName: "bubble.right")
ForEach(Actions.allCases, id: \.self) { action in
Button {
} label: {
HStack(spacing: 2) {
Image(systemName: action.iconName)
if let count = action.count(status: status) {
Text("\(count)")
.font(.footnote)
}
}
}
if action != .share {
Spacer()
}
}
Spacer()
Button {
} label: {
Image(systemName: "arrow.left.arrow.right.circle")
}
Spacer()
Button {
} label: {
Image(systemName: "star")
}
Spacer()
Button {
} label: {
Image(systemName: "square.and.arrow.up")
}
}.tint(.black)
}.tint(.gray)
}
}