Skip to content

Commit

Permalink
move application logic to package
Browse files Browse the repository at this point in the history
  • Loading branch information
vykut committed Dec 11, 2023
1 parent 2822471 commit 55e56c0
Show file tree
Hide file tree
Showing 33 changed files with 118 additions and 49 deletions.
34 changes: 34 additions & 0 deletions FoodSpec/App/AppFeature.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// AppFeature.swift
// FoodSpec
//
// Created by Victor Socaciu on 11/12/2023.
//

import Foundation
import ComposableArchitecture

@Reducer
struct AppFeature {
@ObservableState
struct State: Equatable {
var foodList: FoodListFeature.State = .init()
}

@CasePathable
enum Action {
case foodList(FoodListFeature.Action)
}

var body: some ReducerOf<Self> {
Scope(state: \.foodList, action: \.foodList) {
FoodListFeature()
}
Reduce { state, action in
switch action {
case .foodList:
return .none
}
}
}
}
32 changes: 32 additions & 0 deletions FoodSpec/App/FoodSpecApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// FoodSpecApp.swift
// FoodSpec
//
// Created by Victor Socaciu on 29/11/2023.
//

import SwiftUI
import SwiftData
import ComposableArchitecture

@main
struct FoodSpecApp: App {
@State var store = Store(
initialState: AppFeature.State(),
reducer: {
AppFeature()
._printChanges()
}
)

var body: some Scene {
WindowGroup {
FoodList(
store: store.scope(
state: \.foodList,
action: \.foodList
)
)
}
}
}
38 changes: 0 additions & 38 deletions FoodSpec/FoodSpecApp.swift

This file was deleted.

File renamed without changes.
8 changes: 8 additions & 0 deletions food-spec/Sources/API/Food+API.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// File.swift
//
//
// Created by Victor Socaciu on 11/12/2023.
//

import Foundation
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
//

import Foundation
import ComposableArchitecture
import Billboard
import Dependencies
import DependenciesMacros
@_exported import Billboard

@DependencyClient
struct BillboardClient {
public struct BillboardClient {
var getRandomBanners: () async throws -> AsyncThrowingStream<BillboardAd?, Error>
}

extension BillboardClient: DependencyKey {
static var liveValue: BillboardClient = .init(
public static var liveValue: BillboardClient = .init(
getRandomBanners: {
@Dependency(\.continuousClock) var continuousClock
let first = ActorIsolated(true)
Expand All @@ -30,11 +31,11 @@ extension BillboardClient: DependencyKey {
}
)

static var testValue: BillboardClient = .init()
public static var testValue: BillboardClient = .init()
}

extension DependencyValues {
var billboardClient: BillboardClient {
public var billboardClient: BillboardClient {
get { self[BillboardClient.self] }
set { self[BillboardClient.self] = newValue }
}
Expand Down
8 changes: 8 additions & 0 deletions food-spec/Sources/Database/Food+Database.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// File.swift
//
//
// Created by Victor Socaciu on 11/12/2023.
//

import Foundation
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import Charts
import Shared

struct EnergyBreakdownComparisonChart: View {
let foods: [Food]
Expand Down Expand Up @@ -93,11 +94,11 @@ Fat: \(breakdown.fatRatio.formatted(.percent.precision(.fractionLength(0...1))))
}

extension Energy: Plottable {
var primitivePlottable: Double {
public var primitivePlottable: Double {
value
}

init?(primitivePlottable: Double) {
public init?(primitivePlottable: Double) {
self = .kcal(primitivePlottable)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import Charts
import Shared

struct MacronutrientsComparisonChart: View {
let foods: [Food]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import Charts
import Shared

struct QuantityComparisonChart: View {
let foods: [Food]
Expand Down Expand Up @@ -69,11 +70,11 @@ struct QuantityComparisonChart: View {
}

extension Quantity: Plottable {
var primitivePlottable: Double {
public var primitivePlottable: Double {
value
}

init?(primitivePlottable: Double) {
public init?(primitivePlottable: Double) {
self = .grams(primitivePlottable)
}
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import Shared
import ComposableArchitecture

struct FoodComparison: View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import ComposableArchitecture
import Shared

@Reducer
struct FoodComparisonFeature {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import ComposableArchitecture
import Shared

struct FoodSelection: View {
@Bindable var store: StoreOf<FoodComparisonFeature>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import Charts
import Shared

struct EnergyBreakdownChart: View {
let food: Food
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import ComposableArchitecture
import Shared

struct FoodDetails: View {
@Bindable var store: StoreOf<FoodDetailsFeature>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import ComposableArchitecture
import Shared

@Reducer
struct FoodDetailsFeature {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftData
import ComposableArchitecture
import CoreSpotlight
import Billboard
import Shared

struct FoodList: View {
@Bindable var store: StoreOf<FoodListFeature>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import Foundation
import GRDB
import ComposableArchitecture
import Shared
import API

@Reducer
struct FoodListFeature {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import SwiftUI
import SwiftData
import Shared

struct FoodListRow: View {
let food: Food
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import ComposableArchitecture
import CoreSpotlight
import Database

@Reducer
struct SpotlightReducer {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// File.swift
//
//
// Created by Victor Socaciu on 11/12/2023.
//

import Foundation
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import Shared

struct EnergyCalculator {
struct EnergyBreakdown: Hashable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import CoreSpotlight
import ComposableArchitecture
import Shared

@DependencyClient
struct SpotlightClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import ComposableArchitecture
import XCTestDynamicOverlay
import Shared

public struct UserDefaultsClient {
public var bool: @Sendable (_ key: String) -> Bool
Expand Down

0 comments on commit 55e56c0

Please sign in to comment.