Calendar: Jump by year while holding Shift (#6828)
This commit is contained in:
parent
319c0396a4
commit
2bf27f3f44
@ -1,5 +1,3 @@
|
|||||||
import type { FC } from '../../lib/teact/teact';
|
|
||||||
import type React from '../../lib/teact/teact';
|
|
||||||
import {
|
import {
|
||||||
memo, useCallback, useEffect, useMemo, useRef, useState,
|
memo, useCallback, useEffect, useMemo, useRef, useState,
|
||||||
} from '../../lib/teact/teact';
|
} from '../../lib/teact/teact';
|
||||||
@ -65,7 +63,7 @@ const WEEKDAY_LETTERS = [
|
|||||||
'lng_weekday7',
|
'lng_weekday7',
|
||||||
];
|
];
|
||||||
|
|
||||||
const CalendarModal: FC<OwnProps & StateProps> = ({
|
const CalendarModal = ({
|
||||||
selectedAt,
|
selectedAt,
|
||||||
minAt,
|
minAt,
|
||||||
maxAt,
|
maxAt,
|
||||||
@ -84,7 +82,7 @@ const CalendarModal: FC<OwnProps & StateProps> = ({
|
|||||||
onSubmit,
|
onSubmit,
|
||||||
onDateChange,
|
onDateChange,
|
||||||
onSecondButtonClick,
|
onSecondButtonClick,
|
||||||
}) => {
|
}: OwnProps & StateProps) => {
|
||||||
const { showNotification } = getActions();
|
const { showNotification } = getActions();
|
||||||
|
|
||||||
const menuRef = useRef<HTMLDivElement>();
|
const menuRef = useRef<HTMLDivElement>();
|
||||||
@ -214,20 +212,32 @@ const CalendarModal: FC<OwnProps & StateProps> = ({
|
|||||||
handleContextMenu(e);
|
handleContextMenu(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
function handlePrevMonth() {
|
function handlePrevMonth(e: React.MouseEvent) {
|
||||||
setCurrentMonthAndYear((d) => {
|
setCurrentMonthAndYear((d) => {
|
||||||
const dateCopy = new Date(d);
|
const dateCopy = new Date(d);
|
||||||
dateCopy.setMonth(dateCopy.getMonth() - 1);
|
if (e.shiftKey) {
|
||||||
|
dateCopy.setFullYear(dateCopy.getFullYear() - 1);
|
||||||
|
if (dateCopy < minDate) {
|
||||||
|
return new Date(minDate.getFullYear(), minDate.getMonth(), 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dateCopy.setMonth(dateCopy.getMonth() - 1);
|
||||||
|
}
|
||||||
return dateCopy;
|
return dateCopy;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleNextMonth() {
|
function handleNextMonth(e: React.MouseEvent) {
|
||||||
setCurrentMonthAndYear((d) => {
|
setCurrentMonthAndYear((d) => {
|
||||||
const dateCopy = new Date(d);
|
const dateCopy = new Date(d);
|
||||||
dateCopy.setMonth(dateCopy.getMonth() + 1);
|
if (e.shiftKey) {
|
||||||
|
dateCopy.setFullYear(dateCopy.getFullYear() + 1);
|
||||||
|
if (dateCopy > maxDate) {
|
||||||
|
return new Date(maxDate.getFullYear(), maxDate.getMonth(), 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dateCopy.setMonth(dateCopy.getMonth() + 1);
|
||||||
|
}
|
||||||
return dateCopy;
|
return dateCopy;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -388,7 +398,7 @@ const CalendarModal: FC<OwnProps & StateProps> = ({
|
|||||||
color="translucent"
|
color="translucent"
|
||||||
iconName="previous"
|
iconName="previous"
|
||||||
disabled={shouldDisablePrevMonth}
|
disabled={shouldDisablePrevMonth}
|
||||||
onClick={!shouldDisablePrevMonth ? handlePrevMonth : undefined}
|
onClick={shouldDisablePrevMonth ? undefined : handlePrevMonth}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@ -397,7 +407,7 @@ const CalendarModal: FC<OwnProps & StateProps> = ({
|
|||||||
color="translucent"
|
color="translucent"
|
||||||
iconName="next"
|
iconName="next"
|
||||||
disabled={shouldDisableNextMonth}
|
disabled={shouldDisableNextMonth}
|
||||||
onClick={!shouldDisableNextMonth ? handleNextMonth : undefined}
|
onClick={shouldDisableNextMonth ? undefined : handleNextMonth}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user