diff --git a/Mlem/App/Enums/Interaction/PostBarConfiguration.swift b/Mlem/App/Enums/Interaction/PostBarConfiguration.swift index e7d7ed05f..32dba0122 100644 --- a/Mlem/App/Enums/Interaction/PostBarConfiguration.swift +++ b/Mlem/App/Enums/Interaction/PostBarConfiguration.swift @@ -64,6 +64,7 @@ struct PostBarConfiguration: InteractionBarConfiguration { case upvote case downvote case comment + case saved var appearance: MockReadoutAppearance { switch self { @@ -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: "") } } diff --git a/Mlem/App/Utility/Extensions/Content Models/Interactable1Providing+Extensions.swift b/Mlem/App/Utility/Extensions/Content Models/Interactable1Providing+Extensions.swift index 392b785ec..2f8d90c7b 100644 --- a/Mlem/App/Utility/Extensions/Content Models/Interactable1Providing+Extensions.swift +++ b/Mlem/App/Utility/Extensions/Content Models/Interactable1Providing+Extensions.swift @@ -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 + ) + } } diff --git a/Mlem/App/Utility/Extensions/Content Models/Post1Providing+Extensions.swift b/Mlem/App/Utility/Extensions/Content Models/Post1Providing+Extensions.swift index b052b13c0..b615f282a 100644 --- a/Mlem/App/Utility/Extensions/Content Models/Post1Providing+Extensions.swift +++ b/Mlem/App/Utility/Extensions/Content Models/Post1Providing+Extensions.swift @@ -227,6 +227,7 @@ extension Post1Providing { case .upvote: upvoteReadout case .downvote: downvoteReadout case .comment: commentReadout + case .saved: savedReadout } } diff --git a/Mlem/App/Views/Root/Tabs/Feeds/Feed Posts/CompactPostView.swift b/Mlem/App/Views/Root/Tabs/Feeds/Feed Posts/CompactPostView.swift index 9439d1ad8..26b47a201 100644 --- a/Mlem/App/Views/Root/Tabs/Feeds/Feed Posts/CompactPostView.swift +++ b/Mlem/App/Views/Root/Tabs/Feeds/Feed Posts/CompactPostView.swift @@ -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) diff --git a/Mlem/App/Views/Shared/InfoStackView.swift b/Mlem/App/Views/Shared/InfoStackView.swift index 4526574c2..7e274839d 100644 --- a/Mlem/App/Views/Shared/InfoStackView.swift +++ b/Mlem/App/Views/Shared/InfoStackView.swift @@ -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 }