Repos
Swift
2.5 KB86 lines Opens in site
Directory
Raw
Download
import SwiftUI
import DevPlaceSwiftSDK
struct PostFooterView: View {
let targetId: String
let authorId: String
let starCount: Int
let currentVote: Vote
let reactions: Reactions
let onReact: (String) -> Void
var onReply: (() -> Void)? = nil
var isReplying: Bool = false
var onEdit: (() -> Void)? = nil
var onDelete: (() -> Void)? = nil
@State private var isConfirmingDelete = false
var body: some View {
HStack(spacing: 12) {
VoteView(targetType: .post, targetId: targetId, count: starCount, currentVote: currentVote)
ReactionsBar(reactions: reactions, onReact: onReact)
Spacer(minLength: 0)
HStack(spacing: 24) {
if let onReply, !isReplying {
replyButton(onReply: onReply)
}
ReportButton(targetType: .post, targetId: targetId, authorId: authorId)
if let onEdit {
editButton(onEdit: onEdit)
}
if onDelete != nil {
deleteButton()
}
}
}
}
@ViewBuilder private func replyButton(onReply: @escaping () -> Void) -> some View {
Button {
onReply()
} label: {
Label("Reply to post", systemImage: "arrowshape.turn.up.left")
.labelStyle(.iconOnly)
}
.buttonStyle(.plain)
.foregroundStyle(Color.FG_1)
}
@ViewBuilder private func editButton(onEdit: @escaping () -> Void) -> some View {
Button {
onEdit()
} label: {
Label("Edit post", systemImage: "pencil")
.labelStyle(.iconOnly)
}
.buttonStyle(.plain)
.foregroundStyle(Color.FG_1)
}
@ViewBuilder private func deleteButton() -> some View {
Button {
isConfirmingDelete = true
} label: {
Label("Delete post", systemImage: "trash")
.labelStyle(.iconOnly)
}
.buttonStyle(.plain)
.foregroundStyle(Color.FG_1)
.confirmationDialog(
"Delete this post?",
isPresented: $isConfirmingDelete,
titleVisibility: .visible,
) {
Button("Delete", role: .destructive) {
onDelete?()
}
Button("Cancel", role: .cancel) {}
}
}
}