Skip to content

Commit

Permalink
Refactor EventView and EventList to remove eventHistory dependency, s…
Browse files Browse the repository at this point in the history
…implifying event handling
  • Loading branch information
kasianov-mikhail committed Nov 29, 2024
1 parent 048a7b9 commit a62bee1
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 28 deletions.
14 changes: 0 additions & 14 deletions Sources/Scout/UI/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions Sources/Scout/UI/EventList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -74,7 +73,7 @@ struct EventList: View {
}

NavigationLink {
EventView(event: event, showHistory: true)
EventView(event: event)
} label: {
EmptyView()
}
Expand Down
13 changes: 2 additions & 11 deletions Sources/Scout/UI/EventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -33,10 +27,7 @@ struct EventView: View {
}

StatSection(eventName: event.name)

if showHistory {
HistorySection(event: event)
}
HistorySection(event: event)
}
.onAppear {
tint.value = color
Expand Down Expand Up @@ -223,7 +214,7 @@ extension EventView {
userID: UUID(),
sessionID: UUID()
)
EventView(event: event, showHistory: true)
EventView(event: event)
}
.environmentObject(Tint())
.environmentObject(DatabaseController())
Expand Down
1 change: 0 additions & 1 deletion Sources/Scout/UI/HistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct HistoryView: View {

EventList(provider: provider)
.frame(maxHeight: .infinity)
.environment(\.eventHistory, false)
}
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Expand Down

0 comments on commit a62bee1

Please sign in to comment.