fix issue with two votes on the same date

fix issue with header not showing correct vote date
split logic for Persistence into different files
create class that deals with voting time, existing votes, and what should be shown based on that
This commit is contained in:
Trey t
2022-02-17 14:46:11 -06:00
parent f0ed56fe94
commit 675e44bca9
12 changed files with 547 additions and 427 deletions

View File

@@ -25,7 +25,7 @@ struct AddMoodHeaderView: View {
Color(theme.currentTheme.secondaryBGColor)
VStack {
Text(self.getTitle())
Text(ShowBasedOnVoteLogics.getVotingTitle())
.font(.title)
.foregroundColor(Color(UIColor.label))
.padding()
@@ -56,48 +56,8 @@ struct AddMoodHeaderView: View {
.frame(minWidth: 0, maxWidth: .infinity)
}
private func getTitle() -> String {
//if this is being shown we're missing an entry
// voting time is noon
// vote for current day
// today at 11 am -> How as yesterday
// today at 1 pm -> How is today
// vote for previous day
// today at 11 am -> How as 2 days ago
// today at 1 pm -> How was yesterday
let latestVoteUnLocked = UserDefaultsStore.getOnboarding().ableToVoteBasedOnCurentTime()
let inputDay = UserDefaultsStore.getOnboarding().inputDay
switch (latestVoteUnLocked, inputDay) {
case (true, .Previous):
return "how was yesterday"
case (true, .Today):
return "how is today"
case (false, .Previous):
return "how was two days ago"
case (false, .Today):
return "how as yesterday"
}
}
private func addItem(withMood mood: Mood) {
let latestVoteUnLocked = UserDefaultsStore.getOnboarding().ableToVoteBasedOnCurentTime()
let inputDay = UserDefaultsStore.getOnboarding().inputDay
var date: Date?
switch (latestVoteUnLocked, inputDay) {
case (true, .Previous):
date = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
case (true, .Today):
date = Date()
case (false, .Previous):
date = Calendar.current.date(byAdding: .day, value: -2, to: Date())!
case (false, .Today):
date = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
}
if let date = date {
if let date = ShowBasedOnVoteLogics.dateForHeaderVote() {
addItemHeaderClosure(mood, date)
}
}

View File

@@ -91,8 +91,7 @@ struct ContentView: View {
}
if let selectedEntry = selectedEntry,
deleteEnabled,
selectedEntry.mood != .missing {
deleteEnabled{
Button(String(localized: "content_view_delete_entry"), action: {
viewModel.update(entry: selectedEntry, toMood: Mood.missing)
showUpdateEntryAlert = false
@@ -140,7 +139,11 @@ struct ContentView: View {
return ""
}
let components = Calendar.current.dateComponents([.day, .month, .year], from: entry.forDate!)
guard let forDate = entry.forDate else {
return ""
}
let components = Calendar.current.dateComponents([.day, .month, .year], from: forDate)
// let day = components.day!
let month = components.month!
let year = components.year!
@@ -178,7 +181,7 @@ struct ContentView: View {
private var headerView: some View {
VStack {
if viewModel.shouldShowVotingHeader() {
if ShowBasedOnVoteLogics.isMissingCurrentVote() {
AddMoodHeaderView(addItemHeaderClosure: { (mood, date) in
withAnimation {
viewModel.add(mood: mood, forDate: date, entryType: .header)