Fixed bug with new number of group on not current week
This commit is contained in:
@ -38,26 +38,22 @@ struct MonthTabView: View {
|
||||
.tabViewStyle(.page(indexDisplayMode: .never))
|
||||
}
|
||||
.onAppear(perform: {
|
||||
vm.updateSelectedDayIndex()
|
||||
if monthSlider.isEmpty {
|
||||
let currentMonth = Date().fetchMonth(vm.selectedDay)
|
||||
|
||||
if let firstDate = currentMonth.first?.week[0].date {
|
||||
monthSlider.append(firstDate.createPreviousMonth())
|
||||
}
|
||||
|
||||
monthSlider.append(currentMonth)
|
||||
|
||||
if let lastDate = currentMonth.last?.week[6].date {
|
||||
monthSlider.append(lastDate.createNextMonth())
|
||||
}
|
||||
}
|
||||
updateMonthScreenViewForNewGroup()
|
||||
})
|
||||
.onChange(of: currentMonthIndex, initial: false) { oldValue, newValue in
|
||||
if newValue == 0 || newValue == (monthSlider.count - 1) {
|
||||
createMonth = true
|
||||
}
|
||||
}
|
||||
.onChange(of: vm.isNewGroup, initial: false) { oldValue, newValue in
|
||||
if newValue {
|
||||
monthSlider.removeAll()
|
||||
currentMonthIndex = 1
|
||||
updateMonthScreenViewForNewGroup()
|
||||
print(52)
|
||||
vm.isNewGroup = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
@ -96,7 +92,7 @@ struct MonthTabView: View {
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
vm.week -= 5
|
||||
vm.fetchWeekSchedule("")
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
|
||||
if let lastDate = monthSlider[currentMonthIndex].last?.week[6].date,
|
||||
@ -107,7 +103,26 @@ struct MonthTabView: View {
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
vm.week += 5
|
||||
vm.fetchWeekSchedule("")
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension MonthTabView {
|
||||
func updateMonthScreenViewForNewGroup() {
|
||||
vm.updateSelectedDayIndex()
|
||||
if monthSlider.isEmpty {
|
||||
let currentMonth = Date().fetchMonth(vm.selectedDay)
|
||||
|
||||
if let firstDate = currentMonth.first?.week[0].date {
|
||||
monthSlider.append(firstDate.createPreviousMonth())
|
||||
}
|
||||
|
||||
monthSlider.append(currentMonth)
|
||||
|
||||
if let lastDate = currentMonth.last?.week[6].date {
|
||||
monthSlider.append(lastDate.createNextMonth())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,26 +27,41 @@ struct WeekTabView: View {
|
||||
.frame(height: 90)
|
||||
}
|
||||
.onAppear(perform: {
|
||||
vm.updateSelectedDayIndex()
|
||||
if weekSlider.isEmpty {
|
||||
let currentWeek = Date().fetchWeek(vm.selectedDay)
|
||||
|
||||
if let firstDate = currentWeek.first?.date {
|
||||
weekSlider.append(firstDate.createPrevioustWeek())
|
||||
}
|
||||
|
||||
weekSlider.append(currentWeek)
|
||||
|
||||
if let lastDate = currentWeek.last?.date {
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
}
|
||||
}
|
||||
updateWeekScreenViewForNewGroup()
|
||||
})
|
||||
.onChange(of: currentWeekIndex, initial: false) { oldValue, newValue in
|
||||
if newValue == 0 || newValue == (weekSlider.count - 1) {
|
||||
createWeek = true
|
||||
}
|
||||
}
|
||||
.onChange(of: vm.isNewGroup, initial: false) { oldValue, newValue in
|
||||
if newValue {
|
||||
weekSlider.removeAll()
|
||||
currentWeekIndex = 1
|
||||
updateWeekScreenViewForNewGroup()
|
||||
print(52)
|
||||
vm.isNewGroup = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension WeekTabView {
|
||||
func updateWeekScreenViewForNewGroup() {
|
||||
vm.updateSelectedDayIndex()
|
||||
if weekSlider.isEmpty {
|
||||
let currentWeek = Date().fetchWeek(vm.selectedDay)
|
||||
|
||||
if let firstDate = currentWeek.first?.date {
|
||||
weekSlider.append(firstDate.createPrevioustWeek())
|
||||
}
|
||||
|
||||
weekSlider.append(currentWeek)
|
||||
|
||||
if let lastDate = currentWeek.last?.date {
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ struct WeekViewForMonth: View {
|
||||
}
|
||||
print(difBetweenWeeks)
|
||||
vm.week += difBetweenWeeks
|
||||
vm.fetchWeekSchedule("")
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
vm.selectedDay = day.date
|
||||
vm.updateSelectedDayIndex()
|
||||
|
@ -79,7 +79,7 @@ struct WeekViewForWeek: View {
|
||||
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
||||
currentWeekIndex == 0 {
|
||||
vm.week -= 1
|
||||
vm.fetchWeekSchedule("")
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
||||
weekSlider.removeLast()
|
||||
currentWeekIndex = 1
|
||||
@ -90,7 +90,7 @@ struct WeekViewForWeek: View {
|
||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||
currentWeekIndex == (weekSlider.count - 1) {
|
||||
vm.week += 1
|
||||
vm.fetchWeekSchedule("")
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
weekSlider.removeFirst()
|
||||
currentWeekIndex = weekSlider.count - 2
|
||||
|
Reference in New Issue
Block a user