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,7 +12,8 @@ import Charts
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@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 showTodayInput = true
@State private var selectedEntry: MoodEntry?
@@ -155,30 +156,7 @@ struct ContentView: View {
ForEach(months.sorted(by: {
$0.key > $1.key
}), id: \.key) { month, entries in
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
})
}.onDelete(perform: { offsets in
withAnimation {
viewModel.delete(offsets: offsets, inMonth: month, inYear: year)
}
})
}
monthListView(month: month, year: year, entries: entries)
}
}
}
@@ -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 {
HStack {
entry.mood.icon
@@ -274,40 +282,34 @@ struct ContentView: View {
}
private var mainView: some View {
ZStack {
BGView().equatable()
VStack{
settingsButtonView
.padding(.top, 50)
if viewModel.hasNoData {
Spacer()
emptyView
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)
VStack {
settingsButtonView
if viewModel.hasNoData {
Spacer()
emptyView
Spacer()
} else {
ZStack {
VStack {
headerView
Spacer()
}
.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
@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 {
ZStack {
Color(UIColor.secondarySystemBackground)
VStack {
closeButtonView
.padding()
cloudKitEnable
addTestDataCell
clearDB
changeIcon
showOnboardingButton
whyBackgroundMode
specialThanksCell
if useCloudKit {
cloudKitStatus
Group {
closeButtonView
.padding()
cloudKitEnable
addTestDataCell
clearDB
changeIcon
showOnboardingButton
whyBackgroundMode
specialThanksCell
if useCloudKit {
cloudKitStatus
}
}
Spacer()
}
.padding()
@@ -230,6 +232,19 @@ struct SettingsView: View {
.fixedSize(horizontal: false, vertical: true)
.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 {