Skip to content

Commit

Permalink
Update the add log sheet (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevYeom authored Oct 13, 2024
1 parent 04f7b15 commit 4da67db
Show file tree
Hide file tree
Showing 5 changed files with 356 additions and 50 deletions.
15 changes: 15 additions & 0 deletions Sources/BadaApp/Logbook/LogbookAddReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct LogbookAddReducer: Reducer {
case setAirTemperature(Double?)
case setSurfaceTemperature(Double?)
case setBottomTemperature(Double?)
case setWeather(Weather)
case setFeeling(Feeling)
case setNotes(String)
}

Expand All @@ -42,6 +44,8 @@ struct LogbookAddReducer: Reducer {
var airTemperature: UnitValue.Temperature?
var surfaceTemperature: UnitValue.Temperature?
var bottomTemperature: UnitValue.Temperature?
var weather: Weather = .sunny
var feeling: Feeling = .good
var notes: String = ""
}

Expand All @@ -58,13 +62,18 @@ struct LogbookAddReducer: Reducer {
return .none
case let .setEntryTime(entryTime):
state.entryTime = entryTime
let interval = state.exitTime.timeIntervalSince(entryTime) / 60
state.bottomTime = .minute(interval)
return .none
case let .setExitTime(exitTime):
state.exitTime = exitTime
let interval = exitTime.timeIntervalSince(state.entryTime) / 60
state.bottomTime = .minute(interval)
return .none
case let .setBottomTime(bottomTime):
if let bottomTime {
state.bottomTime = .minute(bottomTime)
state.exitTime = state.entryTime.addingTimeInterval(bottomTime * 60)
} else {
state.bottomTime = nil
}
Expand Down Expand Up @@ -125,6 +134,12 @@ struct LogbookAddReducer: Reducer {
state.bottomTemperature = nil
}
return .none
case let .setWeather(weather):
state.weather = weather
return .none
case let .setFeeling(feeling):
state.feeling = feeling
return .none
case let .setNotes(notes):
state.notes = notes
return .none
Expand Down
127 changes: 103 additions & 24 deletions Sources/BadaApp/Logbook/LogbookAddSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

import BadaCore
import BadaUI
import BadaDomain
import BadaUI

struct LogbookAddSheet: View {
@Environment(\.dismiss) private var dismiss
Expand Down Expand Up @@ -152,6 +152,29 @@ struct LogbookAddSheet: View {
)
.focused($focusedField, equals: .averageWaterTemperature)
}
Section {
Picker(
"Weather",
selection: store.binding(\.weather, send: { .setWeather($0) })
) {
ForEach(Weather.allCases, id: \.self) { weather in
Label(
weather.description,
systemImage: weather.icon.rawValue
)
.tag(weather)
}
}
Picker(
"Feeling",
selection: store.binding(\.feeling, send: { .setFeeling($0) })
) {
ForEach(Feeling.allCases, id: \.self) { feeling in
Text(feeling.description)
.tag(feeling)
}
}
}
Section(header: Text("Notes")) {
TextEditor(
text: Binding(
Expand All @@ -167,13 +190,13 @@ struct LogbookAddSheet: View {
.frame(height: 100)
.autocorrectionDisabled()
#if os(iOS)
.textInputAutocapitalization(.never)
.textInputAutocapitalization(.never)
#endif
}
}
.navigationTitle("New log")
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
.navigationBarTitleDisplayMode(.inline)
#endif
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Expand All @@ -192,7 +215,7 @@ struct LogbookAddSheet: View {
}
}
#if os(macOS)
.padding()
.padding()
#endif
}
}
Expand All @@ -212,6 +235,7 @@ struct LogbookAddSheet: View {
private var doneButton: some View {
Button(action: tapDoneButton) {
Text("Done")
.fontWeight(.medium)
}
}

Expand Down Expand Up @@ -250,6 +274,33 @@ struct LogbookAddSheet: View {
}
}

extension LogbookAddSheet {
private enum Field: Int, CaseIterable {
case logNumber = 0
case bottomTime
case surfaceInterval
case entryAir
case exitAir
case maximumDepth
case averageDepth
case maximumWaterTemperature
case minimumWaterTemperature
case averageWaterTemperature

var previous: Field? {
guard let currentIndex = Field.allCases.firstIndex(of: self) else { return nil }
guard currentIndex > 0 else { return nil }
return Field.allCases[currentIndex - 1]
}

var next: Field? {
guard let currentIndex = Field.allCases.firstIndex(of: self) else { return nil }
guard currentIndex < Field.allCases.count - 1 else { return nil }
return Field.allCases[currentIndex + 1]
}
}
}

extension DiveStyle {
fileprivate static var allCases: [DiveStyle] {
[
Expand Down Expand Up @@ -278,29 +329,57 @@ extension DiveStyle {
}
}

extension LogbookAddSheet {
private enum Field: Int, CaseIterable {
case logNumber = 0
case bottomTime
case surfaceInterval
case entryAir
case exitAir
case maximumDepth
case averageDepth
case maximumWaterTemperature
case minimumWaterTemperature
case averageWaterTemperature
extension Weather {
fileprivate static var allCases: [Weather] {
[
.sunny,
.partlyCloudy,
.cloudy,
.windy,
.rainy,
.snowy,
]
}

var previous: Field? {
guard let currentIndex = Field.allCases.firstIndex(of: self) else { return nil }
guard currentIndex > 0 else { return nil }
return Field.allCases[currentIndex - 1]
fileprivate var description: String {
switch self {
case .sunny: return "Sunny"
case .partlyCloudy: return "Partly Cloudy"
case .cloudy: return "Cloudy"
case .windy: return "Windy"
case .rainy: return "Rainy"
case .snowy: return "Snowy"
}
}

var next: Field? {
guard let currentIndex = Field.allCases.firstIndex(of: self) else { return nil }
guard currentIndex < Field.allCases.count - 1 else { return nil }
return Field.allCases[currentIndex + 1]
fileprivate var icon: SystemImage {
switch self {
case .sunny: return .sunMax
case .partlyCloudy: return .cloudSun
case .cloudy: return .cloud
case .windy: return .wind
case .rainy: return .cloudRain
case .snowy: return .cloudSnow
}
}
}

extension Feeling {
fileprivate static var allCases: [Feeling] {
[
.amazing,
.good,
.average,
.poor,
]
}

fileprivate var description: String {
switch self {
case .amazing: return "😍 Amazing"
case .good: return "😆 Good"
case .average: return "😐 Average"
case .poor: return "😥 Poor"
}
}
}
52 changes: 26 additions & 26 deletions Sources/BadaUI/LabeledTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ where Format: ParseableFormatStyle, Format.FormatOutput == String {

package var body: some View {
#if os(iOS)
LabeledContent(label) {
LabeledContent(label) {
TextField(
value: value,
format: format,
prompt: Text(prompt),
label: { Text(label) }
)
.multilineTextAlignment(textAlignment)
.keyboardType(keyboardType.uiKeyboardType)
}
#else
TextField(
value: value,
format: format,
prompt: Text(prompt),
label: { Text(label) }
)
.multilineTextAlignment(textAlignment)
.keyboardType(keyboardType.uiKeyboardType)
}
#else
TextField(
value: value,
format: format,
prompt: Text(prompt),
label: { Text(label) }
)
.multilineTextAlignment(textAlignment)
#endif
}
}
Expand All @@ -72,22 +72,22 @@ extension LabeledTextField {
case asciiCapableNumberPad = 11

#if os(iOS)
var uiKeyboardType: UIKeyboardType {
switch self {
case .default: return .default
case .asciiCapable: return .asciiCapable
case .numbersAndPunctuation: return .numbersAndPunctuation
case .URL: return .URL
case .numberPad: return .numberPad
case .phonePad: return .phonePad
case .namePhonePad: return .namePhonePad
case .emailAddress: return .emailAddress
case .decimalPad: return .decimalPad
case .twitter: return .twitter
case .webSearch: return .webSearch
case .asciiCapableNumberPad: return .asciiCapableNumberPad
var uiKeyboardType: UIKeyboardType {
switch self {
case .default: return .default
case .asciiCapable: return .asciiCapable
case .numbersAndPunctuation: return .numbersAndPunctuation
case .URL: return .URL
case .numberPad: return .numberPad
case .phonePad: return .phonePad
case .namePhonePad: return .namePhonePad
case .emailAddress: return .emailAddress
case .decimalPad: return .decimalPad
case .twitter: return .twitter
case .webSearch: return .webSearch
case .asciiCapableNumberPad: return .asciiCapableNumberPad
}
}
}
#endif
}
}
6 changes: 6 additions & 0 deletions Sources/BadaUI/SystemImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ package enum SystemImage: String {
case plus = "plus"
case chevronUp = "chevron.up"
case chevronDown = "chevron.down"
case sunMax = "sun.max"
case cloud = "cloud"
case cloudSun = "cloud.sun"
case wind = "wind"
case cloudRain = "cloud.rain"
case cloudSnow = "cloud.snow"
}

extension Image {
Expand Down
Loading

0 comments on commit 4da67db

Please sign in to comment.