Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CommonModel/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
name: "Model",
platforms: [
.iOS(.v17),
.watchOS(.v6)
.watchOS(.v10)
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
Expand Down
19 changes: 8 additions & 11 deletions CommonModel/Sources/CommonModel/RoundModel.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
//
// File.swift
//
// RoundModel.swift
//
//
// Created by Satoshi Komatsu on 2024/04/13.
//

import Foundation

public final class RoundModel: NSObject {
public struct RoundModel: Equatable {
public let type: RoundType
public var counts: [Int: Int] = [:]
// public var totalScore: Int {
// return counts.reduce(0) {
// $0 + $1.count
// }
// }
public var totalScore: Int {
counts.values.reduce(0, +)
}

public init(type: RoundType) {
self.type = type
}
}

// FIXME: This cound be replaced with Int, but use struct just for further updates
// FIXME: This could be replaced with Int, but use struct just for further updates
public struct CountModel: Equatable, Identifiable {
public var id: UUID = UUID()
var count: Int
// var per: Int
public var count: Int

public init(count: Int) {
self.count = count
Expand Down
12 changes: 6 additions & 6 deletions WhitePanda Watch App/Models/WatchConnecter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ final class WatchConnecter: NSObject {
static let shared: WatchConnecter = .init()
private let session: WCSession

private var isGmaeStartedContinuation: AsyncStream<Bool>.Continuation?
var isGmaeStartedStream: AsyncStream<Bool> {
private var isGameStartedContinuation: AsyncStream<Bool>.Continuation?
private(set) lazy var isGameStartedStream: AsyncStream<Bool> = {
AsyncStream { continuation in
self.isGmaeStartedContinuation = continuation
self.isGameStartedContinuation = continuation
}
}
}()

override init() {
self.session = WCSession.default
Expand All @@ -43,8 +43,8 @@ extension WatchConnecter: WCSessionDelegate {
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
print("========Message")
print(message)
if let isGmaeStarted = message["isGameStarted"] as? Bool {
isGmaeStartedContinuation?.yield(isGmaeStarted)
if let isGameStarted = message["isGameStarted"] as? Bool {
isGameStartedContinuation?.yield(isGameStarted)
replyHandler(["GameStarted": true])
}
}
Expand Down
42 changes: 0 additions & 42 deletions WhitePanda Watch App/Scenes/Counter/CounterReducer.swift

This file was deleted.

16 changes: 6 additions & 10 deletions WhitePanda Watch App/Scenes/Counter/CounterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,37 @@
//

import SwiftUI
import ComposableArchitecture

struct CounterView: View {

@Bindable var store: StoreOf<Counter>
@State var viewModel = CounterViewModel()

var body: some View {
VStack {
Text("\(store.count)")
Text("\(viewModel.count)")
.font(.title)
.fontWeight(.semibold)

Spacer()

VStack {
Button(action: {
store.send(.incrementButtonTapped)
viewModel.increment()
}, label: {
Text("+")
.font(.title2)
})

HStack {
Button(action: {
store.send(.decrementButtonTapped)
viewModel.decrement()
}, label: {
Text("-")
.font(.title3)
})

Button(action: {
store.send(.resetButtonTapped)
viewModel.reset()
}, label: {
Text("Reset")
})
Expand All @@ -49,8 +48,5 @@ struct CounterView: View {
}

#Preview {
CounterView(
store: Store(initialState: Counter.State()) {
Counter()
})
CounterView()
}
28 changes: 28 additions & 0 deletions WhitePanda Watch App/Scenes/Counter/CounterViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// CounterViewModel.swift
// WhitePanda Watch App
//
// Created by satoshi on 2024/04/01.
//

import Foundation
import Observation

@Observable
final class CounterViewModel {
var count = 0

func increment() {
count += 1
}

func decrement() {
if count > 0 {
count -= 1
}
}

func reset() {
count = 0
}
}
58 changes: 0 additions & 58 deletions WhitePanda Watch App/Scenes/Initial/InitialReducer.swift

This file was deleted.

27 changes: 12 additions & 15 deletions WhitePanda Watch App/Scenes/Initial/InitialView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,36 @@
//

import SwiftUI
import ComposableArchitecture

struct InitialView: View {

@Bindable var store: StoreOf<InitialFeature>
@State var viewModel = InitialViewModel()

var body: some View {
VStack {
Text("To start a new round,\n open your iPhone and set up!")
.multilineTextAlignment(.center)

Button(action: {
store.send(.createFreeButtonTapped)
viewModel.createFreeButtonTapped()
}, label: {
Text("Or free count mode")
})
}
.navigationDestination(item: $store.scope(state: \.counterState, action: \.createFree), destination: { store in
CounterView(store: store)
})
.navigationDestination(item: $store.scope(state: \.roundState, action: \.roundStart), destination: { store in
RoundView(store: store)
})
.navigationDestination(isPresented: $viewModel.showCounter) {
CounterView()
}
.navigationDestination(isPresented: $viewModel.showRound) {
RoundView()
}
.onAppear {
store.send(.onAppear)
viewModel.onAppear()
}
}
}

#Preview {
InitialView(
store: Store(initialState: InitialFeature.State()) {
InitialFeature(watchConnecter: .init())
}
)
NavigationStack {
InitialView()
}
}
33 changes: 33 additions & 0 deletions WhitePanda Watch App/Scenes/Initial/InitialViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// InitialViewModel.swift
// WhitePanda Watch App
//
// Created by satoshi on 2024/04/08.
//

import Foundation
import Observation

@Observable
final class InitialViewModel {
var showCounter = false
var showRound = false

private let watchConnecter: WatchConnecter

init(watchConnecter: WatchConnecter = .shared) {
self.watchConnecter = watchConnecter
}

func onAppear() {
Task { @MainActor in
for await _ in watchConnecter.isGameStartedStream {
showRound = true
}
}
}

func createFreeButtonTapped() {
showCounter = true
}
}
Loading