(updatedDays, day, modifier, props, state)
| 6 | import { VERTICAL_SCROLLABLE } from '../constants'; |
| 7 | |
| 8 | export function addModifier(updatedDays, day, modifier, props, state) { |
| 9 | const { numberOfMonths: numberOfVisibleMonths, enableOutsideDays, orientation } = props; |
| 10 | const { currentMonth: firstVisibleMonth, visibleDays } = state; |
| 11 | |
| 12 | let currentMonth = firstVisibleMonth; |
| 13 | let numberOfMonths = numberOfVisibleMonths; |
| 14 | if (orientation === VERTICAL_SCROLLABLE) { |
| 15 | numberOfMonths = Object.keys(visibleDays).length; |
| 16 | } else { |
| 17 | currentMonth = getPreviousMonthMemoLast(currentMonth); |
| 18 | numberOfMonths += 2; |
| 19 | } |
| 20 | if (!day || !isDayVisible(day, currentMonth, numberOfMonths, enableOutsideDays)) { |
| 21 | return updatedDays; |
| 22 | } |
| 23 | |
| 24 | const iso = toISODateString(day); |
| 25 | |
| 26 | let updatedDaysAfterAddition = { ...updatedDays }; |
| 27 | if (enableOutsideDays) { |
| 28 | const monthsToUpdate = Object.keys(visibleDays).filter((monthKey) => ( |
| 29 | Object.keys(visibleDays[monthKey]).indexOf(iso) > -1 |
| 30 | )); |
| 31 | |
| 32 | updatedDaysAfterAddition = monthsToUpdate.reduce((acc, monthIso) => { |
| 33 | const month = updatedDays[monthIso] || visibleDays[monthIso]; |
| 34 | |
| 35 | if (!month[iso] || !month[iso].has(modifier)) { |
| 36 | const modifiers = new Set(month[iso]); |
| 37 | modifiers.add(modifier); |
| 38 | acc[monthIso] = { |
| 39 | ...month, |
| 40 | [iso]: modifiers, |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | return acc; |
| 45 | }, updatedDaysAfterAddition); |
| 46 | } else { |
| 47 | const monthIso = toISOMonthString(day); |
| 48 | const month = updatedDays[monthIso] || visibleDays[monthIso] || {}; |
| 49 | |
| 50 | if (!month[iso] || !month[iso].has(modifier)) { |
| 51 | const modifiers = new Set(month[iso]); |
| 52 | modifiers.add(modifier); |
| 53 | updatedDaysAfterAddition[monthIso] = { |
| 54 | ...month, |
| 55 | [iso]: modifiers, |
| 56 | }; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return updatedDaysAfterAddition; |
| 61 | } |
| 62 | |
| 63 | export function deleteModifier(updatedDays, day, modifier, props, state) { |
| 64 | const { numberOfMonths: numberOfVisibleMonths, enableOutsideDays, orientation } = props; |
no test coverage detected
searching dependent graphs…