Skip to content

Commit

Permalink
Move Shared code
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Aug 4, 2024
1 parent 9d95735 commit aa4e0a0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
32 changes: 0 additions & 32 deletions Sources/PulseUI/Extensions/Pulse+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,6 @@ enum LoggerEntity {
}
}

extension NetworkTaskEntity {
var requestFileViewerContext: FileViewerViewModel.Context {
FileViewerViewModel.Context(
contentType: originalRequest?.contentType,
originalSize: requestBodySize,
metadata: metadata,
isResponse: false,
error: nil
)
}

var responseFileViewerContext: FileViewerViewModel.Context {
FileViewerViewModel.Context(
contentType: response?.contentType,
originalSize: responseBodySize,
metadata: metadata,
isResponse: true,
error: decodingError
)
}

/// - 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? {
let state = self.state
if state == .pending && self.session != store.session.id {
return nil
}
return state
}
}

extension LoggerMessageEntity {
var logLevel: LoggerStore.Level {
LoggerStore.Level(rawValue: level) ?? .debug
Expand Down
32 changes: 32 additions & 0 deletions Sources/PulseUI/Features/FileViewer/FileViewerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,35 @@ final class FileViewerViewModel: ObservableObject {
return nil
}
}

extension NetworkTaskEntity {
var requestFileViewerContext: FileViewerViewModel.Context {
FileViewerViewModel.Context(
contentType: originalRequest?.contentType,
originalSize: requestBodySize,
metadata: metadata,
isResponse: false,
error: nil
)
}

var responseFileViewerContext: FileViewerViewModel.Context {
FileViewerViewModel.Context(
contentType: response?.contentType,
originalSize: responseBodySize,
metadata: metadata,
isResponse: true,
error: decodingError
)
}

/// - 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? {
let state = self.state
if state == .pending && self.session != store.session.id {
return nil
}
return state
}
}

0 comments on commit aa4e0a0

Please sign in to comment.