Skip to content

Commit

Permalink
Merge pull request #68 from DeveloperAcademy-POSTECH/feat/#42
Browse files Browse the repository at this point in the history
Feat/#42 SettingView DataBinding
  • Loading branch information
teabag759 authored May 23, 2024
2 parents 4aa8910 + 418990a commit 80f85e2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
version = "1.7">
version = "1.8">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
1 change: 1 addition & 0 deletions MC2-Team3-Pilling/Extentsion/model+extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extension Config{
dateFormatter.dateFormat = format
return dateFormatter.string(from: date)
}

static func StringToDate(dateString: String,format:String) -> Date? {

let dateFormatter = DateFormatter()
Expand Down
4 changes: 4 additions & 0 deletions MC2-Team3-Pilling/View/MedicineSheetView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import SwiftUI
import SwiftData

struct MedicineSheetView: View {
@State private var searchText = ""
Expand All @@ -8,6 +9,7 @@ struct MedicineSheetView: View {

@Environment(\.presentationMode) var presentationMode
@Binding var selectedPill: PillInfo?
@Query var user:[UserInfo]

// let BirthControlNames = [
// "쎄스콘정", "미뉴렛정", "에이리스정", "머시론정",
Expand All @@ -28,9 +30,11 @@ struct MedicineSheetView: View {
List(filteredBirthControl) { pill in
Button(action: {
selectedPill = pill

print(pill.pillName)

if selectedPill == pill {
user.first?.curPill?.pillInfo=selectedPill!
self.presentationMode.wrappedValue.dismiss()
}

Expand Down
33 changes: 25 additions & 8 deletions MC2-Team3-Pilling/View/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@
//

import SwiftUI
import SwiftData

struct SettingView: View {
@State private var selectedAlarmTime = Date.now
@Environment(\.modelContext) private var modelContext
@Query var user:[UserInfo]

@State private var selectedAlarmTime = Date()
@State private var isSoundOn = false
// @State private var selectedPill = 0
// @State private var selectedPill = 0
@Binding var selectedPill: PillInfo?
@State private var isShowingPills = false
@Binding var showingMedicineSheet: Bool





// let pills = [(name: "야즈", type: "24일/4일"), (name: "머쉬론", type: "21일/7일")]

var body: some View {
NavigationStack {
Form {
Expand All @@ -40,7 +39,7 @@ struct SettingView: View {

NavigationLink(destination: MedicineSheetView(showingMedicineSheet: $showingMedicineSheet, selectedPill: $selectedPill)) {
HStack {
Text("Select Pill")
Text("약 선택")
Spacer()
if let pill = selectedPill {
Text(pill.pillName)
Expand All @@ -55,11 +54,29 @@ struct SettingView: View {

Section("알림") {
DatePicker("시간", selection: $selectedAlarmTime, displayedComponents: .hourAndMinute)
.onChange(of: selectedAlarmTime) { oldValue, newValue in
let newValueToString = Config.DateToString(date: newValue, format: Hourformat)
user.first?.scheduleTime = newValueToString
print(newValueToString)
}

Toggle("알람", isOn: $isSoundOn)
.onChange(of: isSoundOn) { oldValue, newValueAlarm in
user.first?.isAlarm = newValueAlarm
}
// Optional, unWrapped

}
}
.onAppear{
if let userInfo = user.first {
selectedPill = userInfo.curPill?.pillInfo
selectedAlarmTime = Config.StringToDate(dateString: userInfo.scheduleTime, format: Hourformat)!
// selectedAlarmTime = Config.DateToString(date: selectedAlarmTime, format: Hourformat)
isSoundOn = userInfo.isAlarm
}

}
.navigationTitle("Settings")
// .sheet(isPresented: $isShowingPills, content: {
// Text("Pills")
Expand Down

0 comments on commit 80f85e2

Please sign in to comment.