diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js index 40ec1d4d9..c91649c22 100644 --- a/app/javascript/mastodon/actions/compose.js +++ b/app/javascript/mastodon/actions/compose.js @@ -12,7 +12,7 @@ import { showAlertForError } from './alerts'; import { showAlert } from './alerts'; import { openModal } from './modal'; import { defineMessages } from 'react-intl'; -import { addYears, addMonths, addDays, addHours, addMinutes, addSeconds, millisecondsToSeconds, set, parseISO, formatISO } from 'date-fns'; +import { addYears, addMonths, addDays, addHours, addMinutes, addSeconds, millisecondsToSeconds, set, parseISO, formatISO, format } from 'date-fns'; import { Set as ImmutableSet } from 'immutable'; import { postReferenceModal } from '../initial_state'; @@ -187,10 +187,10 @@ const parseSimpleDurationFormat = (value, origin = new Date()) => { return null; } - const [_, year = 0, month = 0, day = 0, hour = 0, minite = 0] = value.match(/^(?:(\d+)y)?(?:(\d+)m(?=[\do])o?)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?$/) ?? []; - const duration = millisecondsToSeconds(addMinutes(addHours(addDays(addMonths(addYears(origin, year), month), day), hour), minite) - origin); + const [, year = 0, month = 0, day = 0, hour = 0, minute = 0] = value.match(/^(?:(\d+)y)?(?:(\d+)m(?=[\do])o?)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?$/) ?? []; + const duration = millisecondsToSeconds(addMinutes(addHours(addDays(addMonths(addYears(origin, year), month), day), hour), minute) - origin); - return duration == 0 ? null : duration; + return duration === 0 ? null : duration; }; export const getDateTimeFromText = (value, origin = new Date()) => { @@ -843,16 +843,20 @@ export function removeDateTime() { }; export function changeScheduled(value) { + const date = value instanceof Date ? format(value, 'yyyy-MM-dd HH:mm') : value; + return { type: COMPOSE_SCHEDULED_CHANGE, - value: value, + value: date, }; }; export function changeExpires(value) { + const date = value instanceof Date ? format(value, 'yyyy-MM-dd HH:mm') : value; + return { type: COMPOSE_EXPIRES_CHANGE, - value: value, + value: date, }; }; diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js index e9d650712..d33ce6d0b 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.js +++ b/app/javascript/mastodon/features/compose/components/compose_form.js @@ -16,6 +16,7 @@ import PrivacyDropdownContainer from '../containers/privacy_dropdown_container'; import SearchabilityDropdownContainer from '../containers/searchability_dropdown_container'; import CircleDropdownContainer from '../containers/circle_dropdown_container'; import DateTimeFormContainer from '../containers/datetime_form_container'; +import ExpiresIndicatorContainer from '../containers/expires_indicator_container'; import EmojiPickerDropdown from '../containers/emoji_picker_dropdown_container'; import PollFormContainer from '../containers/poll_form_container'; import UploadFormContainer from '../containers/upload_form_container'; @@ -261,6 +262,7 @@ class ComposeForm extends ImmutablePureComponent { + diff --git a/app/javascript/mastodon/features/compose/components/datetime_dropdown.js b/app/javascript/mastodon/features/compose/components/datetime_dropdown.js index 54d1757ff..bf64c1871 100644 --- a/app/javascript/mastodon/features/compose/components/datetime_dropdown.js +++ b/app/javascript/mastodon/features/compose/components/datetime_dropdown.js @@ -8,10 +8,10 @@ import { getDateTimeFromText } from 'mastodon/actions/compose'; import { layoutFromWindow } from 'mastodon/is_mobile'; import { openModal } from '../../../actions/modal'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; -import classNames from 'classnames' -import { format, minTime, maxTime, max } from 'date-fns' -import DatePicker from "react-datepicker"; -import "react-datepicker/dist/react-datepicker.css"; +import classNames from 'classnames'; +import { format, minTime, maxTime, max } from 'date-fns'; +import DatePicker from 'react-datepicker'; +import 'react-datepicker/dist/react-datepicker.css'; const messages = defineMessages({ datetime_open_calendar: { id: 'datetime.open_calendar', defaultMessage: 'Open calendar' }, @@ -50,7 +50,6 @@ class DateTimeDropdown extends React.PureComponent { }; static propTypes = { - presets: ImmutablePropTypes.list, value: PropTypes.oneOfType([ PropTypes.string, PropTypes.instanceOf(Date), @@ -67,7 +66,9 @@ class DateTimeDropdown extends React.PureComponent { id: PropTypes.string, valueKey: PropTypes.arrayOf(PropTypes.string).isRequired, onChange: PropTypes.func.isRequired, + datetimePresets: ImmutablePropTypes.list, intl: PropTypes.object.isRequired, + dispatch: PropTypes.func.isRequired, }; static defaultProps = { @@ -85,7 +86,7 @@ class DateTimeDropdown extends React.PureComponent { getDateTimePresets = () => { const { datetimePresets, intl } = this.props; - + if (!datetimePresets) { return ImmutableList([ ImmutableMap({ id: '5m', title: intl.formatMessage(messages.minutes, { number: 5 }) }), @@ -101,12 +102,12 @@ class DateTimeDropdown extends React.PureComponent { ImmutableMap({ id: '1y1mo', title: intl.formatMessage(messages.years_months, { year: 1, month: 1 }) }), ]); } - + return datetimePresets.toList(); }; onOpenCalendar = () => { - const { valueKey, onChange, minDate, maxDate, openToDate, dispatch } = this.props + const { valueKey, onChange, minDate, maxDate, openToDate, dispatch } = this.props; dispatch(openModal('CALENDAR', { valueKey: valueKey, @@ -121,15 +122,13 @@ class DateTimeDropdown extends React.PureComponent { const { dateValue, stringValue, invalid, minDate, maxDate, openToDate, placeholder, id, className, onChange, intl } = this.props; const layout = layoutFromWindow(); - const CalendarIconButton = forwardRef(({ value, onClick }, ref) => ( - + const CalendarIconButton = forwardRef((props, ref) => ( + )); return (
- {layout === 'mobile' ? - - : + {layout === 'mobile' ? : ( - } + )}