From a62bee154d19282bb7834a101e202a6ce09dd7fd Mon Sep 17 00:00:00 2001 From: Mikhail Kasianov <96941969+kasianov-mikhail@users.noreply.github.com> Date: Fri, 29 Nov 2024 19:29:08 +0300 Subject: [PATCH] Refactor EventView and EventList to remove eventHistory dependency, simplifying event handling --- Sources/Scout/UI/Event.swift | 14 -------------- Sources/Scout/UI/EventList.swift | 3 +-- Sources/Scout/UI/EventView.swift | 13 ++----------- Sources/Scout/UI/HistoryView.swift | 1 - 4 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Sources/Scout/UI/Event.swift b/Sources/Scout/UI/Event.swift index 6efc92f..17032ce 100644 --- a/Sources/Scout/UI/Event.swift +++ b/Sources/Scout/UI/Event.swift @@ -163,20 +163,6 @@ struct EventQuery { } } -// MARK: - EventQuery - -// TODO: Remove. Use the bool property directly. -struct EventHistory: EnvironmentKey { - static let defaultValue = true -} - -extension EnvironmentValues { - var eventHistory: Bool { - get { self[EventHistory.self] } - set { self[EventHistory.self] = newValue } - } -} - // MARK: - extension EventQuery: CustomStringConvertible { diff --git a/Sources/Scout/UI/EventList.swift b/Sources/Scout/UI/EventList.swift index cfa0b35..9b5dc4d 100644 --- a/Sources/Scout/UI/EventList.swift +++ b/Sources/Scout/UI/EventList.swift @@ -12,7 +12,6 @@ struct EventList: View { let timeline = Date() @ObservedObject var provider: EventProvider - @Environment(\.eventHistory) var showHistory: Bool @EnvironmentObject var database: DatabaseController let dateFormatter: RelativeDateTimeFormatter = { @@ -74,7 +73,7 @@ struct EventList: View { } NavigationLink { - EventView(event: event, showHistory: true) + EventView(event: event) } label: { EmptyView() } diff --git a/Sources/Scout/UI/EventView.swift b/Sources/Scout/UI/EventView.swift index a8433ed..945bf2f 100644 --- a/Sources/Scout/UI/EventView.swift +++ b/Sources/Scout/UI/EventView.swift @@ -10,15 +10,9 @@ import SwiftUI struct EventView: View { let event: Event - let showHistory: Bool @EnvironmentObject var tint: Tint - init(event: Event, showHistory: Bool) { - self.event = event - self.showHistory = showHistory - } - var body: some View { let color = event.level?.color @@ -33,10 +27,7 @@ struct EventView: View { } StatSection(eventName: event.name) - - if showHistory { - HistorySection(event: event) - } + HistorySection(event: event) } .onAppear { tint.value = color @@ -223,7 +214,7 @@ extension EventView { userID: UUID(), sessionID: UUID() ) - EventView(event: event, showHistory: true) + EventView(event: event) } .environmentObject(Tint()) .environmentObject(DatabaseController()) diff --git a/Sources/Scout/UI/HistoryView.swift b/Sources/Scout/UI/HistoryView.swift index e8bcc28..efc71a2 100644 --- a/Sources/Scout/UI/HistoryView.swift +++ b/Sources/Scout/UI/HistoryView.swift @@ -31,7 +31,6 @@ struct HistoryView: View { EventList(provider: provider) .frame(maxHeight: .infinity) - .environment(\.eventHistory, false) } .toolbar { ToolbarItem(placement: .topBarTrailing) {