Add tag status indicator for home timeline

This commit is contained in:
Thomas Ricouard 2023-12-04 09:52:18 +01:00
parent bfc2994cfb
commit 76219f553b
6 changed files with 53 additions and 19 deletions

View File

@ -25,6 +25,10 @@ private struct IsStatusFocused: EnvironmentKey {
static let defaultValue: Bool = false
}
private struct IsHomeTimeline: EnvironmentKey {
static let defaultValue: Bool = false
}
private struct IndentationLevel: EnvironmentKey {
static let defaultValue: UInt = 0
}
@ -64,4 +68,9 @@ public extension EnvironmentValues {
get { self[IndentationLevel.self] }
set { self[IndentationLevel.self] = newValue }
}
var isHomeTimeline: Bool {
get { self[IsHomeTimeline.self] }
set { self[IsHomeTimeline.self] = newValue }
}
}

View File

@ -0,0 +1,19 @@
import Foundation
public struct Application: Codable, Identifiable, Hashable, Equatable, Sendable {
public var id: String {
name
}
public let name: String
public let website: URL?
}
public extension Application {
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
name = try values.decodeIfPresent(String.self, forKey: .name) ?? ""
website = try? values.decodeIfPresent(URL.self, forKey: .website)
}
}

View File

@ -1,23 +1,5 @@
import Foundation
public struct Application: Codable, Identifiable, Hashable, Equatable {
public var id: String {
name
}
public let name: String
public let website: URL?
}
public extension Application {
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
name = try values.decodeIfPresent(String.self, forKey: .name) ?? ""
website = try? values.decodeIfPresent(URL.self, forKey: .website)
}
}
public enum Visibility: String, Codable, CaseIterable, Hashable, Equatable, Sendable {
case pub = "public"
case unlisted
@ -269,7 +251,6 @@ public final class ReblogStatus: AnyStatus, Codable, Identifiable, Equatable, Ha
}
}
extension Application: Sendable {}
extension StatusViewId: Sendable {}
// Every property in Status is immutable.

View File

@ -16,6 +16,7 @@ public struct StatusRowView: View {
@Environment(\.accessibilityVoiceOverEnabled) private var accessibilityVoiceOverEnabled
@Environment(\.isStatusFocused) private var isFocused
@Environment(\.indentationLevel) private var indentationLevel
@Environment(\.isHomeTimeline) private var isHomeTimeline
@Environment(QuickLook.self) private var quickLook
@Environment(Theme.self) private var theme
@ -76,6 +77,9 @@ public struct StatusRowView: View {
if !isCompact, theme.avatarPosition == .top {
StatusRowReblogView(viewModel: viewModel)
StatusRowReplyView(viewModel: viewModel)
if isHomeTimeline {
StatusRowTagView(viewModel: viewModel)
}
}
VStack(alignment: .leading, spacing: 8) {
if !isCompact {

View File

@ -0,0 +1,20 @@
import DesignSystem
import SwiftUI
import Env
struct StatusRowTagView: View {
@Environment(CurrentAccount.self) private var currentAccount
let viewModel: StatusRowViewModel
var body: some View {
Group {
if let tag = viewModel.finalStatus.content.links.first(where: { $0.type == .hashtag}),
currentAccount.tags.contains(where: { $0.name.lowercased() == tag.title.lowercased() }) {
Text("#\(tag.title)")
}
}
.font(.scaledFootnote)
.foregroundColor(.gray)
.fontWeight(.semibold)
}
}

View File

@ -53,6 +53,7 @@ public struct TimelineView: View {
StatusesListView(fetcher: viewModel, client: client, routerPath: routerPath, isRemote: true)
default:
StatusesListView(fetcher: viewModel, client: client, routerPath: routerPath)
.environment(\.isHomeTimeline, timeline == .home)
}
}
.id(client.id)