Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#73 #76

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions 2024-MC3-Team4-NewT.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
21353F612C6786570095CA6D /* BeachMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21353F602C6786570095CA6D /* BeachMapper.swift */; };
21353F632C6873380095CA6D /* OnboardingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21353F622C6873380095CA6D /* OnboardingView.swift */; };
21353F652C6A8A8B0095CA6D /* RecordItemView2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21353F642C6A8A8B0095CA6D /* RecordItemView2.swift */; };
213A4A742C605E3F00786C97 /* RecordReadView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213A4A732C605E3F00786C97 /* RecordReadView.swift */; };
213A4A762C60609600786C97 /* ChartHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213A4A752C60609600786C97 /* ChartHeaderView.swift */; };
21588AFD2C5C75E6003E3489 /* FirebaseSDView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21588AFC2C5C75E6003E3489 /* FirebaseSDView.swift */; };
Expand Down Expand Up @@ -76,6 +77,7 @@
/* Begin PBXFileReference section */
21353F602C6786570095CA6D /* BeachMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeachMapper.swift; sourceTree = "<group>"; };
21353F622C6873380095CA6D /* OnboardingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingView.swift; sourceTree = "<group>"; };
21353F642C6A8A8B0095CA6D /* RecordItemView2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordItemView2.swift; sourceTree = "<group>"; };
213A4A732C605E3F00786C97 /* RecordReadView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordReadView.swift; sourceTree = "<group>"; };
213A4A752C60609600786C97 /* ChartHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartHeaderView.swift; sourceTree = "<group>"; };
21588AFC2C5C75E6003E3489 /* FirebaseSDView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseSDView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -162,6 +164,7 @@
719EA9CC2C5A56730090BAB5 /* RecordChartView.swift */,
712B07632C631EC8001DC52C /* RecordItemView.swift */,
213A4A732C605E3F00786C97 /* RecordReadView.swift */,
21353F642C6A8A8B0095CA6D /* RecordItemView2.swift */,
);
path = RecordReadView;
sourceTree = "<group>";
Expand Down Expand Up @@ -493,6 +496,7 @@
719EA9C52C57729E0090BAB5 /* Font.swift in Sources */,
21588B082C5CC2CA003E3489 /* DateFormatterManager.swift in Sources */,
7159C18E2C60C549007300D6 /* RecordChartViewModel.swift in Sources */,
21353F652C6A8A8B0095CA6D /* RecordItemView2.swift in Sources */,
21588B142C600CAA003E3489 /* TabBarButton.swift in Sources */,
712B07642C631EC8001DC52C /* RecordItemView.swift in Sources */,
715BA4CC2C6111FF00477938 /* ModalView.swift in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions 2024-MC3-Team4-NewT/Resource/Utils/DateFormatterManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ class DateFormatterManager {
formatter.locale = Locale(identifier: "ko_kr")
return formatter.string(from: date)
}
func convertDateToString(date: Date) -> String {
return longDateFormatter.string(from: date)
}
}
11 changes: 1 addition & 10 deletions 2024-MC3-Team4-NewT/Source/View/MainView/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,7 @@ struct MainView: View {
.ignoresSafeArea(edges: .bottom)
.onAppear {
loadSelectedItem() // ๋ทฐ๊ฐ€ ๋‚˜ํƒ€๋‚  ๋•Œ UserDefaults์—์„œ ์„ ํƒ๋œ ํ•ญ๋ชฉ์„ ๋ถˆ๋Ÿฌ์˜ด
// for item in chartRow {
// if let aa = item.surfingRecordStartTime {
// print("\(aa):ํ†ต๊ณผ")
// } else {
// modelContext.delete(item)
// }
// }


// fbo.fetchFirebase(modelContext: modelContext, collectionName: mappedItem, chartRow: chartRow)

}
.onChange(of:isLocationChanged){
loadSelectedItem()
Expand Down
42 changes: 23 additions & 19 deletions 2024-MC3-Team4-NewT/Source/View/RecordReadView/CategoriesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,46 @@ struct CategoriesView: View {

var body: some View {
HStack{
ForEach(0..<5) { index in
Spacer()
.frame(width: 25)
ForEach(0..<2) { index in
Button {
viewModel.categories = index
viewModel.categoryIndex = index
} label: {
if (index == 0){
Text("์ „์ฒด")
}
else if (index == 1){
Text("ํ•€ ๊ณ ์ •")
}
else if (index == 2){
Text("๋‚ ์งœ ์„ ํƒ")
}
else if (index == 3){
HStack(spacing: 0){
Text("๋ณ„์  ")
Image(systemName: "chevron.down")
}
}
else{
HStack(spacing: 0){
Text("์ตœ์‹ ์ˆœ ")
Image(systemName: "chevron.down")
}
}
// else if (index == 2){
// Text("๋‚ ์งœ ์„ ํƒ")
// }
// else if (index == 3){
// HStack(spacing: 0){
// Text("๋ณ„์  ")
// Image(systemName: "chevron.down")
// }
// }
// else{
// HStack(spacing: 0){
// Text("์ตœ์‹ ์ˆœ ")
// Image(systemName: "chevron.down")
// }
// }
}.font(.Body2Medium)
.foregroundColor(viewModel.categories == index ? Color.white : Color.black)
.foregroundColor(viewModel.categoryIndex == index ? Color.white : Color.black)
.padding(.horizontal, 10)
.padding(.vertical, 6)
.background(viewModel.categories == index ? Color("surfBlue") : Color.white)
.background(viewModel.categoryIndex == index ? Color("surfBlue") : Color.white)
.cornerRadius(20)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(Color.black.opacity(0.15), lineWidth: 0.75)
)

}
Spacer()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct ModalView: View {
var body: some View {
ScrollView{
ForEach(surfingRecordOneData, id: \.id) { item in
if ( item.id == viewModel.isID) {
if ( item.id == viewModel.chartRowId) {
VStack(spacing: 0){
HStack{
Text(DateFormatterManager.shared.dateFormatter(from: item.surfingStartTime))
Expand Down Expand Up @@ -41,7 +41,7 @@ struct ModalView: View {
Text(viewModel.evaluationText(for: item.evaluationValue))
.font(.Body2Medium)
.foregroundColor(.black.opacity(0.7))

}
.padding(5)
.background(Color("backgroundSkyblue"))
Expand All @@ -59,7 +59,7 @@ struct ModalView: View {
RecordChartTestView(viewModel: viewModel, recordOne: item)

}.padding(.horizontal)
// .overlay(.yellow.opacity(0.3))
// .overlay(.yellow.opacity(0.3))
.padding(.vertical, 30)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ struct RecordChartTestView: View {
@Query(sort: \ChartRow.time) var chartRow: [ChartRow]
var recordOne: SurfingRecordOne
@EnvironmentObject var myObject: MyObservableObject
@State private var showAlert = false
@State private var selectedItem: ChartRow?

@State var kkk = false
var body: some View {
VStack(spacing: 0) {
let data = viewModel.filteredRecordChart(charts: chartRow, recordOne: recordOne)
Expand Down Expand Up @@ -44,24 +43,20 @@ struct RecordChartTestView: View {
if viewModel.isPinButton[recordOne.id] == true {
Button {
selectedItem = row
showAlert = true
viewModel.isChartPinButotn[row.id, default: false].toggle()
// print ("๊ณ ์ • row: \(row.id)")
if (viewModel.isChartPinButotn[row.id] == true && viewModel.isPinCounter < 3) {
viewModel.isPinCounter += 1
}
else if (viewModel.isChartPinButotn[row.id] == false) {
viewModel.isPinCounter -= 1
viewModel.isChartPinButotn[row.id] = false
}
else {
viewModel.isChartPinButotn[row.id] = false
}

viewModel.isChartPinButton[row.id, default: false].toggle()
viewModel.rowTime = row.time
viewModel.pinRecord = row.surfingRecordStartTime ?? Date()
viewModel.confirmPin(row.time, row.surfingRecordStartTime ?? Date())
viewModel.isRecord = true
if viewModel.isRecord == false {
kkk = true
}

} label: {
Image(systemName: "checkmark.circle.fill")
.frame(width: 20)
.foregroundColor(viewModel.isChartPinButotn[row.id] == true ? Color("surfBlue") : Color(.systemGroupedBackground))
.foregroundColor(viewModel.isChartPinButton[row.id] == true ? Color("surfBlue") : Color(.systemGroupedBackground))
}
}
Text(DateFormatterManager.shared.timeToHourFormatter(row.time))
Expand Down Expand Up @@ -103,26 +98,26 @@ struct RecordChartTestView: View {
.padding(.horizontal, 10)
}
}
.onAppear{
print ("****row: \(row.id)")
}

}
}
}

}
.alert(isPresented: $showAlert) {
.alert(isPresented: $kkk) {
Alert(
title: Text("์ฐจํŠธ๋ฅผ ๊ณ ์ •ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?"),
primaryButton: .default(Text("Yes"), action: {
if let item = selectedItem {
myObject.pinChart.append(item)
// DateFormatterManager.shared.dateFromString("1999-11-19 00:00:00")
// try? modelContext.save()
print("Selected index: \(index)")
}
}),
secondaryButton: .cancel(Text("No"))
primaryButton: .default(Text("๋„ค")) {
print("Pin saved.")
viewModel.savePinTime(viewModel.rowTime, viewModel.pinRecord)
viewModel.isChartPinButton[viewModel.chartRowId] = false
viewModel.isPinButton[viewModel.recordId] = false
},
secondaryButton: .cancel(Text("์ทจ์†Œ"))
)
}


}

}
103 changes: 88 additions & 15 deletions 2024-MC3-Team4-NewT/Source/View/RecordReadView/RecordChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ struct RecordChartView: View {
@Query private var surfingRecordOneData: [SurfingRecordOne]
@ObservedObject var viewModel = RecordChartViewModel()
@State var isLocationSelected = false
private let selectionKey = "selectionKey"
@State private var selectedItem: String = ""
@State private var mappedItem: String = ""
private let defaultItem = "ํฌํ•ญ ์›”ํฌํ•ด๋ณ€"
private let pinRecordKey = "pinRecord"


var body: some View {
NavigationStack {
ZStack {
Expand All @@ -16,7 +23,7 @@ struct RecordChartView: View {
VStack(spacing: 0) {
NavigationLink(destination: LocationView(isLocationSelected: $isLocationSelected)) {
HStack {
Text(viewModel.selectedItem ?? "ํฌํ•ญ ์‹ ํ•ญ๋งŒํ•ด๋ณ€A")
Text(selectedItem)
.font(.SubheadingSemiBold)
Image(systemName: "chevron.down")
Spacer()
Expand All @@ -28,24 +35,90 @@ struct RecordChartView: View {

CategoriesView(viewModel: viewModel)

Spacer().frame(height: 16)
Spacer()
.frame(height: 16)

ScrollView {
ForEach(surfingRecordOneData, id: \.id) { item in
RecordItemView(item: item, viewModel: viewModel)
.onAppear{
print("ํฐ ์ฐจํŠธ item.id \(item.id)")
}


if viewModel.categoryIndex == 0 {
// ์นดํ…Œ๊ณ ๋ฆฌ 0์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ
ScrollView {
ForEach(surfingRecordOneData, id: \.id) { item in
RecordItemView(item: item, viewModel: viewModel)
.onAppear{
print("ํฐ ์ฐจํŠธ item.id \(item.id)")
}
}
Spacer()
.frame(height: 60)
}
} else if viewModel.categoryIndex == 1 {
// pinRecord์— ์ €์žฅ๋œ ๊ฐ’๊ณผ ์ผ์น˜ํ•˜๋Š” surfingStartTime์„ ๊ฐ€์ง„ Record๋งŒ ํ‘œ์‹œ
ScrollView {
let pinnedRecords = getPinnedRecords()
ForEach(pinnedRecords, id: \.id) { item in
RecordItemView2(item: item, viewModel: viewModel)
}
Spacer()
.frame(height: 60)
}
Spacer()
.frame(height: 60)
}
}.padding(.top, 50)
}
.padding(.top, 50)
}
}
.onAppear{
aaa()
}
}

func aaa(){
if let savedItem = UserDefaults.standard.string(forKey: selectionKey) {
let components = savedItem.split(separator: " ", maxSplits: 1) // ์ฒซ ๋ฒˆ์งธ๋กœ๋งŒ ๋ถ„๋ฆฌ
if components.count == 2 {
let regionName = String(components[0])
let itemName = String(components[1])

selectedItem = itemName
// ๋งคํ•‘๋œ ๊ฐ’์ด ์กด์žฌํ•˜๋ฉด mappedItem์— ์ €์žฅ, ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๋นˆ ๋ฌธ์ž์—ด๋กœ ์ดˆ๊ธฐํ™”
if let mappedValue = beachToEnglishMap["\(itemName)"] {
mappedItem = mappedValue
} else {
mappedItem = ""
}
}

print("๋กœ๋“œ:\(selectedItem), ๋งคํ•‘๋œ ๊ฐ’:\(mappedItem)")
} else {
// UserDefaults์— ๊ฐ’์ด ์—†์œผ๋ฉด ๊ธฐ๋ณธ๊ฐ’ ์„ค์ •
selectedItem = defaultItem
if let defaultMappedValue = beachToEnglishMap[defaultItem] {
mappedItem = defaultMappedValue
} else {
mappedItem = ""
}
UserDefaults.standard.set(defaultItem, forKey: selectionKey) // ๊ธฐ๋ณธ๊ฐ’์„ UserDefaults์— ์ €์žฅ
}
}

// UserDefaults์—์„œ pinRecord๋ฅผ ๋ถˆ๋Ÿฌ์™€ ํ•„ํ„ฐ๋ง๋œ Record ๋ฐฐ์—ด ๋ฐ˜ํ™˜
func getPinnedRecords() -> [SurfingRecordOne] {
guard let pinnedStartTimesStrings = UserDefaults.standard.array(forKey: "pinRecord") as? [String] else {
return []
}

let pinnedStartTimes = pinnedStartTimesStrings.compactMap { DateFormatterManager.shared.longDateFormatter.date(from: $0) }

print("ํ•€์‹œ์ž‘:\(pinnedStartTimes)")
for item in surfingRecordOneData {
print("๋ฐ์ดํ„ฐ:\(item.surfingStartTime)")
}

let filteredRecords = surfingRecordOneData.filter { item in
pinnedStartTimes.contains { pinnedTime in
DateFormatterManager.shared.longDateFormatter.string(from: pinnedTime) == DateFormatterManager.shared.longDateFormatter.string(from: item.surfingStartTime)
}
}

return filteredRecords
}
}


}
Loading