build out enable delete option but cant use b/c list view is not a list

re-arrange the content view
This commit is contained in:
Trey t
2022-01-29 11:22:59 -06:00
parent 423be2a30c
commit 2aa59a084a
4 changed files with 89 additions and 70 deletions

View File

@@ -12,6 +12,7 @@ class UserDefaultsStore {
case savedOnboardingData case savedOnboardingData
case needsOnboarding case needsOnboarding
case useCloudKit case useCloudKit
case deleteEnable
} }
static func getOnboarding() -> OnboardingData { static func getOnboarding() -> OnboardingData {

View File

@@ -12,6 +12,7 @@ import Charts
struct ContentView: View { struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext @Environment(\.managedObjectContext) private var viewContext
@AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true @AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
@State private var showingSheet = false @State private var showingSheet = false
@State private var showTodayInput = true @State private var showTodayInput = true
@@ -155,30 +156,7 @@ struct ContentView: View {
ForEach(months.sorted(by: { ForEach(months.sorted(by: {
$0.key > $1.key $0.key > $1.key
}), id: \.key) { month, entries in }), id: \.key) { month, entries in
Section(header: monthListView(month: month, year: year, entries: entries)
HStack{
Text(monthName(fromMonthInt: month))
.font(.title2)
.foregroundColor(Color(UIColor.label))
Text(String(year))
.font(.title2)
.foregroundColor(Color(UIColor.label))
}) {
// for reach all entries
ForEach(entries.sorted(by: {
return $0.forDate! > $1.forDate!
}), id: \.self) { entry in
entryListView(entry: entry)
.onTapGesture(perform: {
selectedEntry = entry
showUpdateEntryAlert = true
})
}.onDelete(perform: { offsets in
withAnimation {
viewModel.delete(offsets: offsets, inMonth: month, inYear: year)
}
})
}
} }
} }
} }
@@ -194,6 +172,36 @@ struct ContentView: View {
} }
} }
private func monthListView(month: Int, year: Int, entries: [MoodEntry]) -> some View {
Section(header:
HStack{
Text(monthName(fromMonthInt: month))
.font(.title2)
.foregroundColor(Color(UIColor.label))
Text(String(year))
.font(.title2)
.foregroundColor(Color(UIColor.label))
}) {
// for reach all entries
ForEach(entries.sorted(by: {
return $0.forDate! > $1.forDate!
}), id: \.self) { entry in
entryListView(entry: entry)
.onTapGesture(perform: {
selectedEntry = entry
showUpdateEntryAlert = true
})
}
// if deleteEnabled {
// .onDelete(perform: { offsets in
// withAnimation {
// viewModel.delete(offsets: offsets, inMonth: month, inYear: year)
// }
// })
// }
}
}
private func entryListView(entry: MoodEntry) -> some View { private func entryListView(entry: MoodEntry) -> some View {
HStack { HStack {
entry.mood.icon entry.mood.icon
@@ -274,40 +282,34 @@ struct ContentView: View {
} }
private var mainView: some View { private var mainView: some View {
ZStack { VStack {
BGView().equatable() settingsButtonView
if viewModel.hasNoData {
VStack{ Spacer()
settingsButtonView emptyView
.padding(.top, 50) Spacer()
} else {
if viewModel.hasNoData { ZStack {
Spacer() VStack {
emptyView headerView
Spacer() Spacer()
} else {
ZStack {
VStack {
headerView
Spacer()
}
.opacity(headerOpacity)
VStack {
SmallRollUpHeaderView(fakeData: false, backDays: 30)
.padding([.leading, .trailing])
Spacer()
}
.opacity(1 - headerOpacity)
listView
.padding([.leading, .trailing])
.padding(.top, headerHeight+10)
.padding(.bottom, 60)
} }
.opacity(headerOpacity)
VStack {
SmallRollUpHeaderView(fakeData: false, backDays: 30)
.padding([.leading, .trailing])
Spacer()
}
.opacity(1 - headerOpacity)
} }
.frame(height: headerHeight + 20)
listView
.padding([.leading, .trailing])
} }
} }.background(
BGView().equatable()
)
} }
} }

View File

@@ -21,26 +21,28 @@ struct SettingsView: View {
@ObservedObject var syncMonitor = SyncMonitor.shared @ObservedObject var syncMonitor = SyncMonitor.shared
@AppStorage(UserDefaultsStore.Keys.useCloudKit.rawValue, store: GroupUserDefaults.groupDefaults) private var useCloudKit = false @AppStorage(UserDefaultsStore.Keys.useCloudKit.rawValue, store: GroupUserDefaults.groupDefaults) private var useCloudKit = false
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
var body: some View { var body: some View {
ZStack { ZStack {
Color(UIColor.secondarySystemBackground) Color(UIColor.secondarySystemBackground)
VStack { VStack {
closeButtonView Group {
.padding() closeButtonView
cloudKitEnable .padding()
addTestDataCell cloudKitEnable
clearDB addTestDataCell
changeIcon clearDB
showOnboardingButton changeIcon
whyBackgroundMode showOnboardingButton
specialThanksCell whyBackgroundMode
specialThanksCell
if useCloudKit { if useCloudKit {
cloudKitStatus cloudKitStatus
}
} }
Spacer() Spacer()
} }
.padding() .padding()
@@ -230,6 +232,19 @@ struct SettingsView: View {
.fixedSize(horizontal: false, vertical: true) .fixedSize(horizontal: false, vertical: true)
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
} }
private var canDelete: some View {
ZStack {
Color(UIColor.systemBackground)
VStack {
Toggle(String(localized: "settings_use_delete_enable"),
isOn: $deleteEnabled)
.padding()
}
}
.fixedSize(horizontal: false, vertical: true)
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
}
} }
struct SettingsView_Previews: PreviewProvider { struct SettingsView_Previews: PreviewProvider {

View File

@@ -54,6 +54,7 @@
"settings_view_show_onboarding" = "Show onboarding"; "settings_view_show_onboarding" = "Show onboarding";
"settings_use_cloudkit_title" = "Use CloudKit"; "settings_use_cloudkit_title" = "Use CloudKit";
"settings_use_cloudkit_body" = "CloudKit fucking sucks"; "settings_use_cloudkit_body" = "CloudKit fucking sucks";
"settings_use_delete_enable" = "Allow deletion of entry";
"mood_value_great" = "Great"; "mood_value_great" = "Great";
"mood_value_good" = "Good"; "mood_value_good" = "Good";