Skip to content

Commit

Permalink
show save icon in compact post (#1404)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews authored Oct 24, 2024
1 parent 5917ce3 commit a1e92de
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Mlem/App/Enums/Interaction/PostBarConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct PostBarConfiguration: InteractionBarConfiguration {
case upvote
case downvote
case comment
case saved

var appearance: MockReadoutAppearance {
switch self {
Expand All @@ -72,6 +73,7 @@ struct PostBarConfiguration: InteractionBarConfiguration {
case .upvote: .init(icon: Icons.upvoteSquare, label: "9")
case .downvote: .init(icon: Icons.downvoteSquare, label: "2")
case .comment: .init(icon: Icons.replies, label: "1")
case .saved: .init(icon: Icons.save, label: "")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,14 @@ extension Interactable1Providing {
valueColor: Palette.main.positive
)
}

var savedReadout: Readout {
let isOn = saved_ ?? false
return .init(
id: "saved\(uid)",
label: nil,
icon: isOn ? Icons.saveFill : Icons.save,
color: isOn ? Palette.main.save : nil
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ extension Post1Providing {
case .upvote: upvoteReadout
case .downvote: downvoteReadout
case .comment: commentReadout
case .saved: savedReadout
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct CompactPostView: View {
.font(.caption)
}

InfoStackView(post: post, readouts: [.created, .score, .comment], showColor: true)
InfoStackView(post: post, readouts: [.created, .score, .comment, post.saved_ ?? false ? .saved : nil], showColor: true)
}
.frame(maxWidth: .infinity)

Expand Down
7 changes: 5 additions & 2 deletions Mlem/App/Views/Shared/InfoStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ struct ReadoutView: View {
}

extension InfoStackView {
init(post: any Post1Providing, readouts: [PostBarConfiguration.ReadoutType], showColor: Bool) {
self.readouts = readouts.map { post.readout(type: $0) }
init(post: any Post1Providing, readouts: [PostBarConfiguration.ReadoutType?], showColor: Bool) {
self.readouts = readouts.compactMap {
if let readoutType = $0 { return post.readout(type: readoutType) }
return nil
}
self.showColor = showColor
}

Expand Down

0 comments on commit a1e92de

Please sign in to comment.