Skip to content

Commit

Permalink
Make store optional in StatusLabelViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Aug 10, 2024
1 parent 6a2b74b commit f440bec
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct NetworkRequestStatusCellModel {
let isMock: Bool
fileprivate let duration: DurationViewModel?

init(task: NetworkTaskEntity, store: LoggerStore) {
init(task: NetworkTaskEntity, store: LoggerStore?) {
self.status = StatusLabelViewModel(task: task, store: store)
self.duration = DurationViewModel(task: task)
self.isMock = task.isMocked
Expand Down Expand Up @@ -135,7 +135,7 @@ struct NetworkRequestStatusCell_Previews: PreviewProvider {
NavigationView {
List {
ForEach(MockTask.allEntities, id: \.objectID) { task in
NetworkRequestStatusCell(viewModel: .init(task: task, store: .mock))
NetworkRequestStatusCell(viewModel: .init(task: task, store: LoggerStore.mock))
}
}
#if os(macOS)
Expand Down
4 changes: 2 additions & 2 deletions Sources/PulseUI/Helpers/FileViewModelContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ extension NetworkTaskEntity {

/// - returns `nil` if the task is an unknown state. It may happen if the
/// task is pending, but it's from the previous app run.
func state(in store: LoggerStore) -> NetworkTaskEntity.State? {
func state(in store: LoggerStore?) -> NetworkTaskEntity.State? {
let state = self.state
if state == .pending && self.session != store.session.id {
if state == .pending, let store, self.session != store.session.id {
return nil
}
return state
Expand Down
2 changes: 1 addition & 1 deletion Sources/PulseUI/Helpers/StatusLabelViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct StatusLabelViewModel {
let tint: Color
let title: String

init(task: NetworkTaskEntity, store: LoggerStore) {
init(task: NetworkTaskEntity, store: LoggerStore?) {
guard let state = task.state(in: store) else {
self.systemImage = "questionmark.diamond.fill"
self.tint = .secondary
Expand Down

0 comments on commit f440bec

Please sign in to comment.