Commit
This commit is contained in:
@ -160,3 +160,137 @@ extension View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension WeekViewForWeek {
|
||||
func paginateWeek() {
|
||||
let calendar = Calendar.current
|
||||
if weekSlider.indices.contains(currentWeekIndex) {
|
||||
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
||||
currentWeekIndex == 0 {
|
||||
vm.week -= 1
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
||||
weekSlider.removeLast()
|
||||
currentWeekIndex = 1
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -1, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
}
|
||||
|
||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||
currentWeekIndex == (weekSlider.count - 1) {
|
||||
vm.week += 1
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
weekSlider.removeFirst()
|
||||
currentWeekIndex = weekSlider.count - 2
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 1, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension WeekViewForMonth {
|
||||
func getForegroundColor(day: Date.WeekDay) -> Color {
|
||||
if isDateInCurrentMonth(day.date) {
|
||||
return isSameDate(day.date, vm.selectedDay) ? .white : .black
|
||||
} else {
|
||||
return isSameDate(day.date, vm.selectedDay) ? .white : Color("greyForDaysInMonthTabView")
|
||||
}
|
||||
}
|
||||
|
||||
func getBackgroundColor(day: Date.WeekDay) -> Color {
|
||||
return isSameDate(day.date, vm.selectedDay) ? Color("blueColor") : Color("background")
|
||||
}
|
||||
|
||||
func overlay(day: Date.WeekDay) -> some View {
|
||||
Group {
|
||||
if day.date.isToday && !isSameDate(day.date, vm.selectedDay) {
|
||||
RoundedRectangle(cornerRadius: 100)
|
||||
.stroke(Color("blueColor"), lineWidth: 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleTap(day: Date.WeekDay) {
|
||||
if isSameWeek(day.date, vm.selectedDay) {
|
||||
print("На одной неделе")
|
||||
}
|
||||
else {
|
||||
var difBetweenWeeks = weeksBetween(startDate: vm.selectedDay, endDate: day.date)
|
||||
if day.date < vm.selectedDay {
|
||||
difBetweenWeeks = difBetweenWeeks * -1
|
||||
}
|
||||
print(difBetweenWeeks)
|
||||
vm.week += difBetweenWeeks
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
vm.selectedDay = day.date
|
||||
vm.updateSelectedDayIndex()
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func paginateMonth(_ indexOfWeek: Int = 0) {
|
||||
let calendar = Calendar.current
|
||||
if monthSlider.indices.contains(currentMonthIndex) {
|
||||
if let firstDate = monthSlider[currentMonthIndex].first?.week[0].date,
|
||||
currentMonthIndex == 0 {
|
||||
monthSlider.insert(firstDate.createPreviousMonth(), at: 0)
|
||||
monthSlider.removeLast()
|
||||
currentMonthIndex = 1
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
vm.week -= 5
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
|
||||
if let lastDate = monthSlider[currentMonthIndex].last?.week[6].date,
|
||||
currentMonthIndex == (monthSlider.count - 1) {
|
||||
monthSlider.append(lastDate.createNextMonth())
|
||||
monthSlider.removeFirst()
|
||||
currentMonthIndex = monthSlider.count - 2
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
vm.week += 5
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user