New: Calendar month view will scroll to today on load and press

Closes #5574
This commit is contained in:
Mark McDowall 2023-05-11 20:58:12 -07:00
parent c7d39579b4
commit 7c0d344437
5 changed files with 113 additions and 89 deletions

View File

@ -1,74 +0,0 @@
import classNames from 'classnames';
import moment from 'moment';
import PropTypes from 'prop-types';
import React from 'react';
import * as calendarViews from 'Calendar/calendarViews';
import CalendarEventConnector from 'Calendar/Events/CalendarEventConnector';
import CalendarEventGroupConnector from 'Calendar/Events/CalendarEventGroupConnector';
import styles from './CalendarDay.css';
function CalendarDay(props) {
const {
date,
time,
isTodaysDate,
events,
view,
onEventModalOpenToggle
} = props;
return (
<div className={classNames(
styles.day,
view === calendarViews.DAY && styles.isSingleDay
)}
>
{
view === calendarViews.MONTH &&
<div className={classNames(
styles.dayOfMonth,
isTodaysDate && styles.isToday,
!moment(date).isSame(moment(time), 'month') && styles.isDifferentMonth
)}
>
{moment(date).date()}
</div>
}
<div>
{
events.map((event) => {
if (event.isGroup) {
return (
<CalendarEventGroupConnector
key={event.seriesId}
{...event}
onEventModalOpenToggle={onEventModalOpenToggle}
/>
);
}
return (
<CalendarEventConnector
key={event.id}
episodeId={event.id}
{...event}
onEventModalOpenToggle={onEventModalOpenToggle}
/>
);
})
}
</div>
</div>
);
}
CalendarDay.propTypes = {
date: PropTypes.string.isRequired,
time: PropTypes.string.isRequired,
isTodaysDate: PropTypes.bool.isRequired,
events: PropTypes.arrayOf(PropTypes.object).isRequired,
view: PropTypes.string.isRequired,
onEventModalOpenToggle: PropTypes.func.isRequired
};
export default CalendarDay;

View File

@ -0,0 +1,80 @@
import classNames from 'classnames';
import moment from 'moment';
import React from 'react';
import * as calendarViews from 'Calendar/calendarViews';
import CalendarEventConnector from 'Calendar/Events/CalendarEventConnector';
import CalendarEventGroupConnector from 'Calendar/Events/CalendarEventGroupConnector';
import Series from 'Series/Series';
import CalendarEventGroup, { CalendarEvent } from 'typings/CalendarEventGroup';
import styles from './CalendarDay.css';
interface CalendarDayProps {
date: string;
time: string;
isTodaysDate: boolean;
events: (CalendarEvent | CalendarEventGroup)[];
view: string;
onEventModalOpenToggle(...args: unknown[]): unknown;
}
function CalendarDay(props: CalendarDayProps) {
const { date, time, isTodaysDate, events, view, onEventModalOpenToggle } =
props;
const ref = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
if (isTodaysDate && view === calendarViews.MONTH && ref.current) {
ref.current.scrollIntoView();
}
}, [time, isTodaysDate, view]);
return (
<div
ref={ref}
className={classNames(
styles.day,
view === calendarViews.DAY && styles.isSingleDay
)}
>
{view === calendarViews.MONTH && (
<div
className={classNames(
styles.dayOfMonth,
isTodaysDate && styles.isToday,
!moment(date).isSame(moment(time), 'month') &&
styles.isDifferentMonth
)}
>
{moment(date).date()}
</div>
)}
<div>
{events.map((event) => {
if (event.isGroup) {
return (
<CalendarEventGroupConnector
key={event.seriesId}
{...event}
onEventModalOpenToggle={onEventModalOpenToggle}
/>
);
}
return (
<CalendarEventConnector
key={event.id}
{...event}
episodeId={event.id}
series={event.series as Series}
airDateUtc={event.airDateUtc as string}
onEventModalOpenToggle={onEventModalOpenToggle}
/>
);
})}
</div>
</div>
);
}
export default CalendarDay;

View File

@ -236,6 +236,7 @@ class CalendarEvent extends Component {
CalendarEvent.propTypes = { CalendarEvent.propTypes = {
id: PropTypes.number.isRequired, id: PropTypes.number.isRequired,
episodeId: PropTypes.number.isRequired,
series: PropTypes.object.isRequired, series: PropTypes.object.isRequired,
episodeFile: PropTypes.object, episodeFile: PropTypes.object,
title: PropTypes.string.isRequired, title: PropTypes.string.isRequired,
@ -248,14 +249,15 @@ CalendarEvent.propTypes = {
hasFile: PropTypes.bool.isRequired, hasFile: PropTypes.bool.isRequired,
grabbed: PropTypes.bool, grabbed: PropTypes.bool,
queueItem: PropTypes.object, queueItem: PropTypes.object,
showEpisodeInformation: PropTypes.bool.isRequired, // These props come from the connector, not marked as required to apease TS for now.
showFinaleIcon: PropTypes.bool.isRequired, showEpisodeInformation: PropTypes.bool,
showSpecialIcon: PropTypes.bool.isRequired, showFinaleIcon: PropTypes.bool,
showCutoffUnmetIcon: PropTypes.bool.isRequired, showSpecialIcon: PropTypes.bool,
fullColorEvents: PropTypes.bool.isRequired, showCutoffUnmetIcon: PropTypes.bool,
timeFormat: PropTypes.string.isRequired, fullColorEvents: PropTypes.bool,
colorImpairedMode: PropTypes.bool.isRequired, timeFormat: PropTypes.string,
onEventModalOpenToggle: PropTypes.func.isRequired colorImpairedMode: PropTypes.bool,
onEventModalOpenToggle: PropTypes.func
}; };
export default CalendarEvent; export default CalendarEvent;

View File

@ -235,14 +235,15 @@ class CalendarEventGroup extends Component {
} }
CalendarEventGroup.propTypes = { CalendarEventGroup.propTypes = {
series: PropTypes.object.isRequired, // Most of these props come from the connector and are required, but TS is confused.
series: PropTypes.object,
events: PropTypes.arrayOf(PropTypes.object).isRequired, events: PropTypes.arrayOf(PropTypes.object).isRequired,
isDownloading: PropTypes.bool.isRequired, isDownloading: PropTypes.bool,
showEpisodeInformation: PropTypes.bool.isRequired, showEpisodeInformation: PropTypes.bool,
showFinaleIcon: PropTypes.bool.isRequired, showFinaleIcon: PropTypes.bool,
fullColorEvents: PropTypes.bool.isRequired, fullColorEvents: PropTypes.bool,
timeFormat: PropTypes.string.isRequired, timeFormat: PropTypes.string,
colorImpairedMode: PropTypes.bool.isRequired, colorImpairedMode: PropTypes.bool,
onEventModalOpenToggle: PropTypes.func.isRequired onEventModalOpenToggle: PropTypes.func.isRequired
}; };

View File

@ -0,0 +1,15 @@
import Episode from 'Episode/Episode';
export interface CalendarEvent extends Episode {
isGroup: false;
}
interface CalendarEventGroup {
isGroup: true;
seriesId: number;
seasonNumber: number;
episodeIds: number[];
events: Episode[];
}
export default CalendarEventGroup;