Skip to content

Commit

Permalink
Use getTitle in NetworkInspectorView
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed May 19, 2024
1 parent 67f3690 commit 8ca0147
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
7 changes: 0 additions & 7 deletions Sources/PulseUI/Extensions/Pulse+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ extension NetworkTaskEntity: Identifiable {
}

extension NetworkTaskEntity {
var title: String {
if let taskDescription, !taskDescription.isEmpty {
return taskDescription
}
return url.flatMap(URL.init(string:))?.lastPathComponent ?? "Request"
}

var requestFileViewerContext: FileViewerViewModel.Context {
FileViewerViewModel.Context(
contentType: originalRequest?.contentType,
Expand Down
11 changes: 9 additions & 2 deletions Sources/PulseUI/Features/Console/Views/ConsoleEntityCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ private struct _ConsoleTaskCell: View {
@State private var shareItems: ShareItems?
@State private var sharedTask: NetworkTaskEntity?
@Environment(\.store) private var store
@EnvironmentObject private var environment: ConsoleEnvironment

var body: some View {
#if os(iOS) || os(visionOS)
let cell = ConsoleTaskCell(task: task, isDisclosureNeeded: true)
.background(NavigationLink("", destination: NetworkInspectorView(task: task)).opacity(0))
.background(NavigationLink("", destination: inspector).opacity(0))
#elseif os(macOS)
let cell = ConsoleTaskCell(task: task)
.tag(ConsoleSelectedItem.entity(task.objectID))
#else
let cell = NavigationLink(destination: NetworkInspectorView(task: task)) {
let cell = NavigationLink(destination: inspector) {
ConsoleTaskCell(task: task)
}
#endif
Expand Down Expand Up @@ -121,4 +122,10 @@ private struct _ConsoleTaskCell: View {
cell
#endif
}

private var inspector: some View {
// We don't own NavigationView, so we have to inject the dependencies
NetworkInspectorView(task: task)
.injecting(environment)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import Pulse
import CoreData

@available(iOS 15, macOS 13, *)
@available(macOS 13, *)
struct ConsoleEntityDetailsRouterView: View {
let selection: ConsoleSelectedItem

Expand Down
12 changes: 10 additions & 2 deletions Sources/PulseUI/Features/Inspector/NetworkInspectorView-ios.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct NetworkInspectorView: View {

@State private var shareItems: ShareItems?
@ObservedObject private var settings: UserSettings = .shared
@EnvironmentObject private var environment: ConsoleEnvironment
@Environment(\.store) private var store

var body: some View {
Expand All @@ -31,10 +32,17 @@ struct NetworkInspectorView: View {
.safeAreaInset(edge: .bottom) {
OpenOnMacOverlay(entity: task)
}
.inlineNavigationTitle(task.title)
.inlineNavigationTitle(title ?? "")
.sheet(item: $shareItems, content: ShareView.init)
}


private var title: String? {
guard let title = environment.delegate.getTitle(for: task) else {
return nil
}
return URL(string: title)?.lastPathComponent ?? title
}

@ViewBuilder
private var contents: some View {
Section { NetworkInspectorView.makeHeaderView(task: task, store: store) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct ConsoleSearchResultView: View {
var limit: Int = 4
var isSeparatorNeeded = false

@EnvironmentObject private var environment: ConsoleEnvironment

var body: some View {
ConsoleEntityCell(entity: viewModel.entity)
#if os(macOS)
Expand All @@ -26,7 +28,7 @@ struct ConsoleSearchResultView: View {
makeCell(for: item)
.tag(ConsoleSelectedItem.occurrence(viewModel.entity.objectID, item))
#else
NavigationLink(destination: ConsoleSearchResultView.makeDestination(for: item, entity: viewModel.entity)) {
NavigationLink(destination: ConsoleSearchResultView.makeDestination(for: item, entity: viewModel.entity).injecting(environment)) {
makeCell(for: item)
}
#endif
Expand All @@ -40,7 +42,7 @@ struct ConsoleSearchResultView: View {
.padding(.leading, 16)
.padding(.bottom, 8)
#else
NavigationLink(destination: ConsoleSearchResultDetailsView(viewModel: viewModel)) {
NavigationLink(destination: ConsoleSearchResultDetailsView(viewModel: viewModel).injecting(environment)) {
Text("Total Results: ")
.font(ConsoleConstants.fontBody) +
Text(total)
Expand Down

0 comments on commit 8ca0147

Please sign in to comment.