2022-01-27 16:32:12 -06:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-01-27 16:32:12 -06:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2024-09-09 14:57:16 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-01-27 16:32:12 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React, { useState, FormEvent } from "react";
|
|
|
|
|
|
|
|
|
|
import { _t } from "../../../languageHandler";
|
|
|
|
|
import Field from "../elements/Field";
|
|
|
|
|
import { RovingAccessibleButton, useRovingTabIndex } from "../../../accessibility/RovingTabIndex";
|
2023-03-22 11:45:44 -05:00
|
|
|
import { formatDateForInput } from "../../../DateUtils";
|
2022-01-27 16:32:12 -06:00
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
|
ts: number;
|
2023-03-13 15:07:20 +00:00
|
|
|
onDatePicked: (dateString: string) => void;
|
2022-01-27 16:32:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const JumpToDatePicker: React.FC<IProps> = ({ ts, onDatePicked }: IProps) => {
|
|
|
|
|
const date = new Date(ts);
|
2023-03-22 11:45:44 -05:00
|
|
|
const dateInputDefaultValue = formatDateForInput(date);
|
2022-01-27 16:32:12 -06:00
|
|
|
|
2023-03-22 11:45:44 -05:00
|
|
|
const [dateValue, setDateValue] = useState(dateInputDefaultValue);
|
2022-01-27 16:32:12 -06:00
|
|
|
const [onFocus, isActive, ref] = useRovingTabIndex<HTMLInputElement>();
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const onDateValueInput = (ev: React.ChangeEvent<HTMLInputElement>): void => setDateValue(ev.target.value);
|
2022-01-27 16:32:12 -06:00
|
|
|
const onJumpToDateSubmit = (ev: FormEvent): void => {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
onDatePicked(dateValue);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<form className="mx_JumpToDatePicker_form" onSubmit={onJumpToDateSubmit}>
|
2023-10-02 13:52:27 +01:00
|
|
|
<span className="mx_JumpToDatePicker_label">{_t("room|jump_to_date")}</span>
|
2022-01-27 16:32:12 -06:00
|
|
|
<Field
|
2022-05-10 12:49:05 -04:00
|
|
|
element="input"
|
2022-01-27 16:32:12 -06:00
|
|
|
type="date"
|
|
|
|
|
onInput={onDateValueInput}
|
|
|
|
|
value={dateValue}
|
2023-03-22 11:45:44 -05:00
|
|
|
// Prevent people from selecting a day in the future (there won't be any
|
|
|
|
|
// events there anyway).
|
|
|
|
|
max={formatDateForInput(new Date())}
|
2022-01-27 16:32:12 -06:00
|
|
|
className="mx_JumpToDatePicker_datePicker"
|
2023-10-02 13:52:27 +01:00
|
|
|
label={_t("room|jump_to_date_prompt")}
|
2022-01-27 16:32:12 -06:00
|
|
|
onFocus={onFocus}
|
|
|
|
|
inputRef={ref}
|
|
|
|
|
tabIndex={isActive ? 0 : -1}
|
|
|
|
|
/>
|
|
|
|
|
<RovingAccessibleButton
|
|
|
|
|
element="button"
|
|
|
|
|
type="submit"
|
|
|
|
|
kind="primary"
|
|
|
|
|
className="mx_JumpToDatePicker_submitButton"
|
|
|
|
|
onClick={onJumpToDateSubmit}
|
|
|
|
|
>
|
2023-09-01 08:26:48 +01:00
|
|
|
{_t("action|go")}
|
2022-01-27 16:32:12 -06:00
|
|
|
</RovingAccessibleButton>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default JumpToDatePicker;
|