Skip to content

Commit

Permalink
Merge pull request #4 from ski-u/run-swiftformat
Browse files Browse the repository at this point in the history
Run SwiftFormat
  • Loading branch information
ski-u authored Aug 19, 2024
2 parents 2a73671 + bf9c762 commit e00ceb8
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 69 deletions.
14 changes: 7 additions & 7 deletions Features/Sources/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import XCTestDynamicOverlay

public struct APIClient: Sendable {
public var apod: @Sendable () async throws -> AstronomyPicture

public init(
apod: @escaping @Sendable () async throws -> AstronomyPicture
) {
Expand All @@ -19,28 +19,28 @@ extension APIClient: TestDependencyKey {
)
}

extension DependencyValues {
public var apiClient: APIClient {
public extension DependencyValues {
var apiClient: APIClient {
get { self[APIClient.self] }
set { self[APIClient.self] = newValue }
}
}

extension APIClient: DependencyKey {
private(set) public static var apiKey: APIKey?
public private(set) static var apiKey: APIKey?

public static let liveValue = APIClient(
apod: {
var components = URLComponents(string: "https://api.nasa.gov/planetary/apod")!
components.queryItems = [
URLQueryItem(name: "api_key", value: apiKey?.rawValue),
]

let (data, _) = try await URLSession.shared.data(from: components.url!)
return try JSONDecoder().decode(AstronomyPicture.self, from: data)
}
)

public static func setAPIKey(_ key: APIKey) {
apiKey = key
}
Expand Down
10 changes: 5 additions & 5 deletions Features/Sources/AppFeature/AppReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ public struct AppReducer {
public struct State: Equatable {
var settings = Settings.State()
var today = TodayReducer.State()

public init() {}
}

public enum Action {
case settings(Settings.Action)
case today(TodayReducer.Action)
}

public init() {}

public var body: some ReducerOf<Self> {
Scope(state: \.settings, action: \.settings) {
Settings()
}

Scope(state: \.today, action: \.today) {
TodayReducer()
}
Expand Down
16 changes: 8 additions & 8 deletions Features/Sources/AppFeature/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import Today

public struct AppView: View {
var store: StoreOf<AppReducer>

public init(store: StoreOf<AppReducer>) {
self.store = store
}

public var body: some View {
TabView {
NavigationStack {
Expand All @@ -21,14 +21,14 @@ public struct AppView: View {
Text("Today")
}
}

SettingsView(store: store.scope(state: \.settings, action: \.settings))
.tabItem {
VStack {
Image(systemName: "gear")
Text("Settings")
.tabItem {
VStack {
Image(systemName: "gear")
Text("Settings")
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion Features/Sources/Models/APIKey.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public struct APIKey: RawRepresentable, Equatable {
public var rawValue: String

public init(rawValue: String) {
self.rawValue = rawValue
}
Expand Down
2 changes: 1 addition & 1 deletion Features/Sources/Models/AstronomyPicture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public struct AstronomyPicture: Decodable, Equatable, Sendable {
public var mediaType: String
public var title: String
public var url: String

public init(
copyright: String? = nil,
date: String,
Expand Down
12 changes: 6 additions & 6 deletions Features/Sources/Settings/APIKey/APIKeySetting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ public struct APIKeySetting {
public struct State: Equatable {
var apiKeyInput: APIKey
var initialAPIKey: APIKey

var isEdited: Bool {
apiKeyInput != initialAPIKey
}

public init(
apiKeyInput: APIKey = APIClient.apiKey ?? .init(rawValue: "")
) {
self.apiKeyInput = apiKeyInput
initialAPIKey = apiKeyInput
}
}

public enum Action: Equatable {
case setAPIKeyInput(String)
case updateButtonTapped
}

public init() {}

public func reduce(into state: inout State, action: Action) -> Effect<Action> {
switch action {
case let .setAPIKeyInput(input):
state.apiKeyInput = .init(rawValue: input)
return .none

case .updateButtonTapped:
// TODO: Persist API key
APIClient.setAPIKey(state.apiKeyInput)
Expand Down
6 changes: 3 additions & 3 deletions Features/Sources/Settings/APIKey/APIKeySettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import SwiftUI
struct APIKeySettingView: View {
let store: StoreOf<APIKeySetting>
@ObservedObject private var viewStore: ViewStoreOf<APIKeySetting>

init(store: StoreOf<APIKeySetting>) {
self.store = store
viewStore = .init(store, observe: { $0 })
}

var body: some View {
List {
Section(footer: link) {
Expand All @@ -34,7 +34,7 @@ struct APIKeySettingView: View {
}
}
}

private var link: some View {
VStack(alignment: .leading, spacing: 4) {
Text("You can generate your API key on:")
Expand Down
14 changes: 7 additions & 7 deletions Features/Sources/Settings/Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ public struct Settings {
public enum Path {
case apiKeySetting(APIKeySetting)
}

@ObservableState
public struct State: Equatable {
var path = StackState<Path.State>()

public init() {}
}

public enum Action {
case path(StackActionOf<Path>)
case popToRoot
}

public var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
Expand All @@ -27,18 +27,18 @@ public struct Settings {
case let .element(id: id, action: .apiKeySetting(.updateButtonTapped)):
state.path.pop(from: id)
return .none

default:
return .none
}

case .popToRoot:
state.path.removeAll()
return .none
}
}
.forEach(\.path, action: \.path)
}

public init() {}
}
10 changes: 5 additions & 5 deletions Features/Sources/Settings/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import SwiftUI

public struct SettingsView: View {
@Bindable var store: StoreOf<Settings>

public init(store: StoreOf<Settings>) {
self.store = store
}

public var body: some View {
NavigationStack(path: $store.scope(state: \.path, action: \.path)) {
List {
Expand All @@ -28,14 +28,14 @@ public struct SettingsView: View {
.padding(.trailing, 8)

Text("API Key")

Spacer()

Text(APIClient.apiKey?.rawValue ?? "None")
.foregroundStyle(Color.secondary)
}
}

NavigationLink {
LanguageView()
} label: {
Expand Down
16 changes: 8 additions & 8 deletions Features/Sources/Today/TodayReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public struct TodayReducer {
var error: TextState?
var isLoading = false
var picture: AstronomyPicture?

public init(
error: TextState? = nil,
isLoading: Bool = false,
Expand All @@ -20,18 +20,18 @@ public struct TodayReducer {
self.picture = picture
}
}

public enum Action: Equatable {
case fetch
case response(TaskResult<AstronomyPicture>)
}

public init() {}

@Dependency(\.apiClient) private var client

private enum CancelID { case fetch }

public func reduce(into state: inout State, action: Action) -> Effect<Action> {
switch action {
case .fetch:
Expand All @@ -48,12 +48,12 @@ public struct TodayReducer {
)
}
.cancellable(id: CancelID.fetch, cancelInFlight: true)

case let .response(.success(picture)):
state.isLoading = false
state.picture = picture
return .none

case let .response(.failure(error)):
state.error = .init(error.localizedDescription)
state.isLoading = false
Expand Down
8 changes: 4 additions & 4 deletions Features/Sources/Today/TodayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import SwiftUI
public struct TodayView: View {
let store: StoreOf<TodayReducer>
@ObservedObject private var viewStore: ViewStoreOf<TodayReducer>

@State private var isPresentedFullScreenImage = false

public init(store: StoreOf<TodayReducer>) {
self.store = store
viewStore = .init(store, observe: { $0 })
Expand All @@ -30,10 +30,10 @@ public struct TodayView: View {
}
.navigationTitle("Today")
}

@ViewBuilder
private var content: some View {
Section (
Section(
header: Group {
if let picture = viewStore.picture {
switch picture.mediaTypeEnum {
Expand Down
8 changes: 4 additions & 4 deletions Features/Sources/Today/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import WebKit

struct WebView: UIViewRepresentable {
let url: URL
func makeUIView(context: Context) -> WKWebView {

func makeUIView(context _: Context) -> WKWebView {
let webView = WKWebView()
webView.load(URLRequest(url: url))
return webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {}

func updateUIView(_: WKWebView, context _: Context) {}
}

struct WebView_Previews: PreviewProvider {
Expand Down
2 changes: 1 addition & 1 deletion Features/Tests/ModelsTests/ModelsTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import XCTest
@testable import Models
import XCTest

final class ModelsTests: XCTestCase {}
Loading

0 comments on commit e00ceb8

Please sign in to comment.