diff --git a/src/agenda/index.tsx b/src/agenda/index.tsx index 4e19d9f9d8..04cc6c3afd 100644 --- a/src/agenda/index.tsx +++ b/src/agenda/index.tsx @@ -4,22 +4,28 @@ import XDate from 'xdate'; import memoize from 'memoize-one'; import React, {Component} from 'react'; -import {Text, View, Dimensions, Animated, ViewStyle, LayoutChangeEvent, NativeSyntheticEvent, NativeScrollEvent} from 'react-native'; +import { + Text, + View, + Dimensions, + Animated, + ViewStyle, + LayoutChangeEvent, + NativeSyntheticEvent, + NativeScrollEvent +} from 'react-native'; // @ts-expect-error import {extractComponentProps} from '../component-updater.js'; // @ts-expect-error import {parseDate, xdateToData, toMarkingFormat} from '../interface'; -// @ts-expect-error -import dateutils from '../dateutils'; -// @ts-expect-error +import {weekDayNames, sameDate, sameMonth} from '../dateutils'; import {AGENDA_CALENDAR_KNOB} from '../testIDs'; // @ts-expect-error import {VelocityTracker} from '../input'; import CalendarList, {CalendarListProps} from '../calendar-list'; import styleConstructor from './style'; -import ReservationList, {ReservationListProps} from './reservation-list'; - +import ReservationList, {ReservationListProps} from './reservation-list'; const HEADER_HEIGHT = 104; const KNOB_HEIGHT = 24; @@ -28,36 +34,37 @@ export type ReservationItemType = { name: string; height: number; day: XDate; -} +}; export type ReservationsType = { - [date: string]: ReservationItemType[] -} + [date: string]: ReservationItemType[]; +}; -export type AgendaProps = CalendarListProps & ReservationListProps & { - /** agenda container style */ - style?: ViewStyle; - /** the list of items that have to be displayed in agenda. If you want to render item as empty date +export type AgendaProps = CalendarListProps & + ReservationListProps & { + /** agenda container style */ + style?: ViewStyle; + /** the list of items that have to be displayed in agenda. If you want to render item as empty date the value of date key has to be an empty array []. If there exists no value for date key it is considered that the date in question is not yet loaded */ - items: ReservationsType; - /** callback that gets called when items for a certain month should be loaded (month became visible) */ - loadItemsForMonth?: (data: any) => void; - /** callback that fires when the calendar is opened or closed */ - onCalendarToggled?: (enabled: boolean) => void; - /** callback that gets called on day press */ - onDayPress?: (data: any) => void; - /** callback that gets called when day changes while scrolling agenda list */ - onDaychange?: (data: any) => void; //TODO: Should be renamed 'onDayChange' - /** specify how agenda knob should look like */ - renderKnob?: () => JSX.Element; - /** initially selected day */ - selected: boolean, //TODO: Should be renamed 'selectedDay' - /** Hide knob button. Default = false */ - hideKnob: boolean, - /** When `true` and `hideKnob` prop is `false`, the knob will always be visible and the user will be able to drag the knob up and close the calendar. Default = false */ - showClosingKnob: boolean -} + items: ReservationsType; + /** callback that gets called when items for a certain month should be loaded (month became visible) */ + loadItemsForMonth?: (data: any) => void; + /** callback that fires when the calendar is opened or closed */ + onCalendarToggled?: (enabled: boolean) => void; + /** callback that gets called on day press */ + onDayPress?: (data: any) => void; + /** callback that gets called when day changes while scrolling agenda list */ + onDaychange?: (data: any) => void; //TODO: Should be renamed 'onDayChange' + /** specify how agenda knob should look like */ + renderKnob?: () => JSX.Element; + /** initially selected day */ + selected: boolean; //TODO: Should be renamed 'selectedDay' + /** Hide knob button. Default = false */ + hideKnob: boolean; + /** When `true` and `hideKnob` prop is `false`, the knob will always be visible and the user will be able to drag the knob up and close the calendar. Default = false */ + showClosingKnob: boolean; + }; type AgendaState = { scrollY: Animated.Value; @@ -66,7 +73,7 @@ type AgendaState = { firstReservationLoad: boolean; selectedDay: XDate; topDay: XDate; -} +}; /** * @description: Agenda component @@ -103,7 +110,7 @@ export default class Agenda extends Component { hideKnob: PropTypes.bool, /** When `true` and `hideKnob` prop is `false`, the knob will always be visible and the user will be able to drag the knob up and close the calendar. Default = false */ showClosingKnob: PropTypes.bool - } + }; private style: {[key: string]: ViewStyle}; private viewHeight: number; @@ -156,7 +163,7 @@ export default class Agenda extends Component { } componentDidUpdate(prevProps: AgendaProps) { - if (this.props.selected && !dateutils.sameDate(parseDate(this.props.selected), parseDate(prevProps.selected))) { + if (this.props.selected && !sameDate(parseDate(this.props.selected), parseDate(prevProps.selected))) { this.setState({selectedDay: parseDate(this.props.selected)}); } else if (!prevProps.items) { this.loadReservations(this.props); @@ -339,7 +346,7 @@ export default class Agenda extends Component { onDayChange = (day: any) => { const newDate = parseDate(day); - const withAnimation = dateutils.sameMonth(newDate, this.state.selectedDay); + const withAnimation = sameMonth(newDate, this.state.selectedDay); this.calendar.scrollToDay(day, this.calendarOffset(), withAnimation); this.setState({ @@ -388,15 +395,16 @@ export default class Agenda extends Component { renderKnob() { const {showClosingKnob, hideKnob, renderKnob} = this.props; - let knob: JSX.Element | null = ; + let knob: JSX.Element | null = ; if (!hideKnob) { - const knobView = renderKnob ? renderKnob() : ; - knob = !this.state.calendarScrollable || showClosingKnob ? ( - - (this.knob = c)}>{knobView} - - ) : null; + const knobView = renderKnob ? renderKnob() : ; + knob = + !this.state.calendarScrollable || showClosingKnob ? ( + + (this.knob = c)}>{knobView} + + ) : null; } return knob; } @@ -410,12 +418,12 @@ export default class Agenda extends Component { }); renderWeekNumbersSpace = () => { - return this.props.showWeekNumbers && ; + return this.props.showWeekNumbers && ; }; render() { const {firstDay, hideKnob, style, testID} = this.props; - const weekDaysNames = dateutils.weekDayNames(firstDay); + const weekDaysNames = weekDayNames(firstDay); const agendaHeight = this.initialScrollPadPosition(); const weekdaysStyle = [ this.style.weekdays, @@ -461,13 +469,14 @@ export default class Agenda extends Component { weekdaysStyle.push({height: HEADER_HEIGHT}); } - const openCalendarScrollPadPosition = !hideKnob && this.state.calendarScrollable && this.props.showClosingKnob ? agendaHeight + HEADER_HEIGHT : 0; + const openCalendarScrollPadPosition = + !hideKnob && this.state.calendarScrollable && this.props.showClosingKnob ? agendaHeight + HEADER_HEIGHT : 0; const shouldAllowDragging = !hideKnob && !this.state.calendarScrollable; const scrollPadPosition = (shouldAllowDragging ? HEADER_HEIGHT : openCalendarScrollPadPosition) - KNOB_HEIGHT; const scrollPadStyle = { height: KNOB_HEIGHT, top: scrollPadPosition, - left: (this.viewWidth - 80) / 2, + left: (this.viewWidth - 80) / 2 }; return ( diff --git a/src/agenda/reservation-list/index.tsx b/src/agenda/reservation-list/index.tsx index af58b5d237..e88fd85c8c 100644 --- a/src/agenda/reservation-list/index.tsx +++ b/src/agenda/reservation-list/index.tsx @@ -3,19 +3,25 @@ import PropTypes from 'prop-types'; import XDate from 'xdate'; import React, {Component} from 'react'; -import {ActivityIndicator, View, FlatList, ViewStyle, TextStyle, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent} from 'react-native'; +import { + ActivityIndicator, + View, + FlatList, + ViewStyle, + TextStyle, + NativeSyntheticEvent, + NativeScrollEvent, + LayoutChangeEvent +} from 'react-native'; // @ts-expect-error import {extractComponentProps} from '../../component-updater'; -// @ts-expect-error -import dateutils from '../../dateutils'; -// @ts-expect-error +import {sameDate} from '../../dateutils'; import {toMarkingFormat} from '../../interface'; import styleConstructor from './style'; import Reservation, {ReservationProps} from './reservation'; import {ReservationItemType, ReservationsType} from 'agenda'; - export interface DayReservations { reservation?: ReservationItemType; date?: XDate; @@ -50,10 +56,10 @@ export type ReservationListProps = ReservationProps & { /** A RefreshControl component, used to provide pull-to-refresh functionality for the ScrollView */ refreshControl?: JSX.Element; /** Set this true while waiting for new data from a refresh */ - refreshing?: boolean, + refreshing?: boolean; /** If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make sure to also set the refreshing prop correctly */ onRefresh?: () => void; -} +}; interface ReservationsListState { reservations: DayReservations[]; @@ -93,11 +99,11 @@ class ReservationList extends Component { + renderRow = ({item, index}: {item: DayReservations; index: number}) => { const reservationProps = extractComponentProps(Reservation, this.props); return ( - + ); }; @@ -283,7 +289,7 @@ class ReservationList extends Component; + return ; } return ( diff --git a/src/agenda/reservation-list/reservation.tsx b/src/agenda/reservation-list/reservation.tsx index 07d6ac6e35..9991e2dc7e 100644 --- a/src/agenda/reservation-list/reservation.tsx +++ b/src/agenda/reservation-list/reservation.tsx @@ -7,15 +7,12 @@ import {View, Text} from 'react-native'; // @ts-expect-error import {xdateToData} from '../../interface'; -// @ts-expect-error -import dateutils from '../../dateutils'; -// @ts-expect-error +import {isToday} from '../../dateutils'; import {RESERVATION_DATE} from '../../testIDs'; import styleConstructor from './style'; import {Theme} from '../../commons/types'; import {DayReservations} from './index'; - export interface ReservationProps { item: DayReservations; /** Specify theme properties to override specific styles for reservation parts. Default = {} */ @@ -27,7 +24,7 @@ export interface ReservationProps { /** specify how each item should be rendered in agenda */ renderItem?: (reservation: any, isFirst: boolean) => React.Component; /** specify how empty date content with no items should be rendered */ - renderEmptyDate?: (date?: XDate) => React.Component + renderEmptyDate?: (date?: XDate) => React.Component; } class Reservation extends Component { @@ -45,7 +42,7 @@ class Reservation extends Component { renderItem: PropTypes.func, /** specify how empty date content with no items should be rendered */ renderEmptyDate: PropTypes.func - } + }; style; @@ -82,7 +79,7 @@ class Reservation extends Component { return this.props.renderDay(date ? xdateToData(date) : undefined, item); } - const today = dateutils.isToday(date) ? this.style.today : undefined; + const today = isToday(date) ? this.style.today : undefined; const dayNames = XDate.locales[XDate.defaultLocale].dayNamesShort; if (date) { @@ -97,11 +94,10 @@ class Reservation extends Component { ); } else { - return ; + return ; } } - render() { const {reservation, date} = this.props.item; let content; diff --git a/src/calendar-list/index.tsx b/src/calendar-list/index.tsx index 9ef19e0331..4b7da533f7 100644 --- a/src/calendar-list/index.tsx +++ b/src/calendar-list/index.tsx @@ -9,9 +9,7 @@ import {FlatList, Platform, Dimensions, View, ViewStyle, LayoutChangeEvent} from import {extractComponentProps} from '../component-updater'; // @ts-expect-error import {xdateToData, parseDate} from '../interface'; -// @ts-expect-error -import dateutils from '../dateutils'; -// @ts-expect-error +import {page, sameDate} from '../dateutils'; import {STATIC_HEADER} from '../testIDs'; import styleConstructor from './style'; import Calendar, {CalendarProps} from '../calendar'; @@ -62,14 +60,14 @@ export type CalendarListProps = CalendarProps & { removeClippedSubviews: boolean; }; -type XDateAndBump = XDate & {propBump?: number} ; +type XDateAndBump = XDate & {propBump?: number}; type CalendarListState = { rows: Array; texts: Array; openDate: XDate; currentMonth: XDate; -} +}; /** * @description: Calendar List component for both vertical and horizontal calendars @@ -187,7 +185,7 @@ class CalendarList extends Component { for (let i = 0; i < rowClone.length; i++) { let val: XDate | string = prevState.texts[i]; - // @ts-ignore + // @ts-ignore if (rowClone[i].getTime) { val = rowClone[i].clone(); // @ts-ignore @@ -207,10 +205,10 @@ class CalendarList extends Component { if (!horizontal) { let week = 0; - const days = dateutils.page(day, firstDay); + const days = page(day, firstDay); for (let i = 0; i < days.length; i++) { week = Math.floor(i / 7); - if (dateutils.sameDate(days[i], day)) { + if (sameDate(days[i], day)) { scrollAmount += 46 * week; break; } diff --git a/src/calendar/day/index.tsx b/src/calendar/day/index.tsx index e5c418ce5f..6c475e7ebb 100644 --- a/src/calendar/day/index.tsx +++ b/src/calendar/day/index.tsx @@ -6,9 +6,7 @@ import memoize from 'memoize-one'; import React, {Component} from 'react'; // @ts-expect-error import {shouldUpdate} from '../../component-updater'; -// @ts-expect-error -import dateutils from '../../dateutils'; -// @ts-expect-error +import {isToday as dateutils_isToday} from '../../dateutils'; import {xdateToData} from '../../interface'; // @ts-expect-error import {SELECT_DATE_SLOT} from '../../testIDs'; @@ -102,7 +100,7 @@ export default class Day extends Component { render() { const {day, marking} = this.props; const date = xdateToData(day); - const isToday = dateutils.isToday(day); + const isToday = dateutils_isToday(day); const Component = this.getDayComponent(); const dayProps = _.omit(this.props, 'day'); const accessibilityLabel = this.getAccessibilityLabel(day, marking, isToday); diff --git a/src/calendar/index.tsx b/src/calendar/index.tsx index cae10b7287..12b61490f2 100644 --- a/src/calendar/index.tsx +++ b/src/calendar/index.tsx @@ -8,9 +8,7 @@ import {View, ViewStyle} from 'react-native'; // @ts-expect-error import GestureRecognizer, {swipeDirections} from 'react-native-swipe-gestures'; -// @ts-expect-error -import dateutils from '../dateutils'; -// @ts-expect-error +import {page, isGTE, isLTE, sameMonth} from '../dateutils'; import {xdateToData, parseDate, toMarkingFormat} from '../interface'; // @ts-expect-error import {getState} from '../day-state-manager'; @@ -26,10 +24,9 @@ import BasicDay from './day/basic'; import {MarkingProps} from './day/marking'; import {Theme} from '../commons/types'; - type MarkedDatesType = { - [key: string]: MarkingProps -} + [key: string]: MarkingProps; +}; export interface CalendarProps extends CalendarHeaderProps, DayProps { /** Specify theme properties to override specific styles for calendar parts */ @@ -75,7 +72,7 @@ export interface CalendarProps extends CalendarHeaderProps, DayProps { } interface CalendarState { - currentMonth: any + currentMonth: any; } /** * @description: Calendar component @@ -163,7 +160,7 @@ class Calendar extends Component { const minDate = parseDate(this.props.minDate); const maxDate = parseDate(this.props.maxDate); - if (!(minDate && !dateutils.isGTE(day, minDate)) && !(maxDate && !dateutils.isLTE(day, maxDate))) { + if (!(minDate && !isGTE(day, minDate)) && !(maxDate && !isLTE(day, maxDate))) { const shouldUpdateMonth = disableMonthChange === undefined || !disableMonthChange; if (shouldUpdateMonth) { @@ -229,7 +226,7 @@ class Calendar extends Component { const {hideExtraDays, markedDates} = this.props; const dayProps = extractComponentProps(Day, this.props); - if (!dateutils.sameMonth(day, this.state.currentMonth) && hideExtraDays) { + if (!sameMonth(day, this.state.currentMonth) && hideExtraDays) { return ; } @@ -269,7 +266,7 @@ class Calendar extends Component { const {currentMonth} = this.state; const {firstDay, showSixWeeks, hideExtraDays} = this.props; const shouldShowSixWeeks = showSixWeeks && !hideExtraDays; - const days = dateutils.page(currentMonth, firstDay, shouldShowSixWeeks); + const days = page(currentMonth, firstDay, shouldShowSixWeeks); const weeks = []; while (days.length) { @@ -286,7 +283,7 @@ class Calendar extends Component { if (current) { const lastMonthOfDay = toMarkingFormat(current.clone().addMonths(1, true).setDate(1).addDays(-1)); - if (displayLoadingIndicator && !(markedDates?.[lastMonthOfDay])) { + if (displayLoadingIndicator && !markedDates?.[lastMonthOfDay]) { indicator = true; } } diff --git a/src/dateutils.js b/src/dateutils.js index edc1fb1d14..8cf847a352 100644 --- a/src/dateutils.js +++ b/src/dateutils.js @@ -142,7 +142,7 @@ function getWeekDates(date, firstDay, format) { } } -module.exports = { +export { weekDayNames, sameMonth, sameWeek, diff --git a/src/day-state-manager.js b/src/day-state-manager.js index 86676692cb..8994d976df 100644 --- a/src/day-state-manager.js +++ b/src/day-state-manager.js @@ -23,6 +23,4 @@ function getState(day, current, props) { return state; } -module.exports = { - getState -}; +export {getState}; diff --git a/src/expandableCalendar/Context/Presenter.js b/src/expandableCalendar/Context/Presenter.js index e293e8a488..2a09f0977b 100644 --- a/src/expandableCalendar/Context/Presenter.js +++ b/src/expandableCalendar/Context/Presenter.js @@ -1,6 +1,6 @@ import _ from 'lodash'; import XDate from 'xdate'; -import dateutils from '../../dateutils'; +import {sameMonth as dateutils_sameMonth} from '../../dateutils'; import {xdateToData, toMarkingFormat} from '../../interface'; const commons = require('../commons'); @@ -44,7 +44,7 @@ class Presenter { }; setDate = (props, date, newDate, updateState, updateSource) => { - const sameMonth = dateutils.sameMonth(XDate(date), XDate(newDate)); + const sameMonth = dateutils_sameMonth(XDate(date), XDate(newDate)); const buttonIcon = this.getButtonIcon(date, props.showTodayButton); updateState(buttonIcon); diff --git a/src/expandableCalendar/agendaList.js b/src/expandableCalendar/agendaList.js index e80de7698a..e554e8d68d 100644 --- a/src/expandableCalendar/agendaList.js +++ b/src/expandableCalendar/agendaList.js @@ -3,7 +3,7 @@ import React, {Component} from 'react'; import {SectionList, Text} from 'react-native'; import PropTypes from 'prop-types'; import XDate from 'xdate'; -import dateutils from '../dateutils'; +import {isToday as dateutils_isToday} from '../dateutils'; import styleConstructor from './style'; import asCalendarConsumer from './asCalendarConsumer'; import {getMoment} from '../momentResolver'; @@ -109,7 +109,7 @@ class AgendaList extends Component { if (markToday) { const todayString = XDate.locales[XDate.defaultLocale].today || commons.todayString; - const isToday = dateutils.isToday(XDate(title)); + const isToday = dateutils_isToday(XDate(title)); sectionTitle = isToday ? `${todayString}, ${sectionTitle}` : sectionTitle; } diff --git a/src/expandableCalendar/index.js b/src/expandableCalendar/index.js index 9c7afe57c2..7f9eaf23d1 100644 --- a/src/expandableCalendar/index.js +++ b/src/expandableCalendar/index.js @@ -7,7 +7,7 @@ import React, {Component} from 'react'; import {AccessibilityInfo, PanResponder, Animated, View, Text, Image} from 'react-native'; import {CALENDAR_KNOB} from '../testIDs'; -import dateutils from '../dateutils'; +import {page, weekDayNames} from '../dateutils'; import {parseDate, toMarkingFormat} from '../interface'; import styleConstructor, {HEADER_HEIGHT} from './style'; import CalendarList from '../calendar-list'; @@ -207,7 +207,7 @@ class ExpandableCalendar extends Component { } getNumberOfWeeksInMonth(month) { - const days = dateutils.page(month, this.props.firstDay); + const days = page(month, this.props.firstDay); return days.length / 7; } @@ -411,7 +411,7 @@ class ExpandableCalendar extends Component { renderHeader() { const monthYear = XDate(this.props.context.date).toString('MMMM yyyy'); - const weekDaysNames = dateutils.weekDayNames(this.props.firstDay); + const weekDaysNames = weekDayNames(this.props.firstDay); return ( ; } }