Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agenda - fix CalendarList props extraction #1994

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/agenda/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
NativeScrollEvent
} from 'react-native';

import {extractComponentProps} from '../componentUpdater';
import {extractCalendarListProps, extractReservationListProps} from '../componentUpdater';
import {xdateToData, toMarkingFormat} from '../interface';
import {sameDate, sameMonth} from '../dateutils';
// @ts-expect-error
Expand Down Expand Up @@ -328,7 +328,7 @@ export default class Agenda extends Component<AgendaProps, State> {
};

renderReservations() {
const reservationListProps = extractComponentProps(ReservationList, this.props);
const reservationListProps = extractReservationListProps(this.props);

return (
<ReservationList
Expand All @@ -344,7 +344,7 @@ export default class Agenda extends Component<AgendaProps, State> {
renderCalendarList() {
const {markedDates, items} = this.props;
const shouldHideExtraDays = this.state.calendarScrollable ? this.props.hideExtraDays : false;
const calendarListProps = extractComponentProps(CalendarList, this.props);
const calendarListProps = extractCalendarListProps(this.props);

return (
<CalendarList
Expand Down
11 changes: 3 additions & 8 deletions src/agenda/reservation-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import XDate from 'xdate';
import React, {Component} from 'react';
import {ActivityIndicator, View, FlatList, StyleProp, ViewStyle, TextStyle, NativeSyntheticEvent, NativeScrollEvent, LayoutChangeEvent} from 'react-native';

import {extractComponentProps} from '../../componentUpdater';
import {extractReservationProps} from '../../componentUpdater';
import {sameDate} from '../../dateutils';
import {toMarkingFormat} from '../../interface';
import styleConstructor from './style';
import Reservation, {ReservationProps} from './reservation';
import {AgendaEntry, AgendaSchedule} from '../../types';
import {AgendaEntry, AgendaSchedule, DayAgenda} from '../../types';


export type ReservationListProps = ReservationProps & {
Expand Down Expand Up @@ -48,11 +48,6 @@ export type ReservationListProps = ReservationProps & {
reservationsKeyExtractor?: (item: DayAgenda, index: number) => string;
};

interface DayAgenda {
reservation?: AgendaEntry;
date?: XDate;
}

interface State {
reservations: DayAgenda[];
}
Expand Down Expand Up @@ -252,7 +247,7 @@ class ReservationList extends Component<ReservationListProps, State> {
};

renderRow = ({item, index}: {item: DayAgenda; index: number}) => {
const reservationProps = extractComponentProps(Reservation, this.props);
const reservationProps = extractReservationProps(this.props);

return (
<View onLayout={this.onRowLayoutChange.bind(this, index)}>
Expand Down
125 changes: 124 additions & 1 deletion src/componentUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {CalendarListProps} from './calendar-list';
import {CalendarProps} from './calendar';
import {CalendarListProps} from './calendar-list';
import {AgendaProps} from './agenda';
import {ReservationListProps} from './agenda/reservation-list';

import {MarkingProps} from './calendar/day/marking';

const get = require('lodash/get');
Expand All @@ -18,6 +21,7 @@ export function shouldUpdate(props: any, newProps: any, paths: string[]) {
return false;
}

// TODO: remove
export function extractComponentProps(component: any, props: any, ignoreProps?: string[]) {
const componentPropTypes = component.propTypes;
if (componentPropTypes) {
Expand Down Expand Up @@ -161,3 +165,122 @@ export function extractCalendarProps(props: CalendarListProps) {

return others;
}

export function extractCalendarListProps(props: AgendaProps) {

const {
// Agenda props
loadItemsForMonth,
onCalendarToggled,
renderKnob,
selected,
hideKnob,
showClosingKnob,
// ReservationList props
items,
selectedDay,
topDay,
onDayChange,
showOnlySelectedDayItems,
renderEmptyData,
// onScroll,
// onScrollBeginDrag,
// onScrollEndDrag,
// onMomentumScrollBegin,
// onMomentumScrollEnd,
// refreshControl,
// refreshing,
// onRefresh,
reservationsKeyExtractor,
// Reservation props
date,
item,
rowHasChanged,
// renderDay,
renderItem,
renderEmptyDate,
...others
} = props;

return others;
}

export function extractReservationListProps(props: AgendaProps) {
const {
// ReservationList props
items,
selectedDay,
topDay,
onDayChange,
showOnlySelectedDayItems,
renderEmptyData,
onScroll,
onScrollBeginDrag,
onScrollEndDrag,
onMomentumScrollBegin,
onMomentumScrollEnd,
refreshControl,
refreshing,
onRefresh,
reservationsKeyExtractor,
// Reservation props
date,
item,
rowHasChanged,
renderDay,
renderItem,
renderEmptyDate,
} = props;

const ReservationListProps = {
// ReservationList props
items,
selectedDay,
topDay,
onDayChange,
showOnlySelectedDayItems,
renderEmptyData,
onScroll,
onScrollBeginDrag,
onScrollEndDrag,
onMomentumScrollBegin,
onMomentumScrollEnd,
refreshControl,
refreshing,
onRefresh,
reservationsKeyExtractor,
// Reservation props
date,
item,
rowHasChanged,
renderDay,
renderItem,
renderEmptyDate,
};

return ReservationListProps;
}

export function extractReservationProps(props: ReservationListProps) {
const {
date,
item,
theme,
rowHasChanged,
renderDay,
renderItem,
renderEmptyDate
} = props;

const reservationProps = {
date,
item,
theme,
rowHasChanged,
renderDay,
renderItem,
renderEmptyDate
};

return reservationProps;
}
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@ export type AgendaEntry = {
export type AgendaSchedule = {
[date: string]: AgendaEntry[];
}

export interface DayAgenda {
reservation?: AgendaEntry;
date?: XDate;
}