'use strict'; import classNames from 'clsx'; import React from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { setSchedule, removeSchedule } from 'soapbox/actions/compose'; import IconButton from 'soapbox/components/icon-button'; import { HStack, Stack, Text } from 'soapbox/components/ui'; import BundleContainer from 'soapbox/features/ui/containers/bundle-container'; import { DatePicker } from 'soapbox/features/ui/util/async-components'; import { useAppDispatch, useCompose } from 'soapbox/hooks'; export const isCurrentOrFutureDate = (date: Date) => { return date && new Date().setHours(0, 0, 0, 0) <= new Date(date).setHours(0, 0, 0, 0); }; const isFiveMinutesFromNow = (time: Date) => { const fiveMinutesFromNow = new Date(new Date().getTime() + 300000); // now, plus five minutes (Pleroma won't schedule posts ) const selectedDate = new Date(time); return fiveMinutesFromNow.getTime() < selectedDate.getTime(); }; const messages = defineMessages({ schedule: { id: 'schedule.post_time', defaultMessage: 'Post Date/Time' }, remove: { id: 'schedule.remove', defaultMessage: 'Remove schedule' }, }); export interface IScheduleForm { composeId: string, } const ScheduleForm: React.FC = ({ composeId }) => { const dispatch = useAppDispatch(); const intl = useIntl(); const scheduledAt = useCompose(composeId).schedule; const active = !!scheduledAt; const onSchedule = (date: Date) => { dispatch(setSchedule(composeId, date)); }; const handleRemove = (e: React.MouseEvent) => { dispatch(removeSchedule(composeId)); e.preventDefault(); }; if (!active) { return null; } return ( {Component => ()} ); }; export default ScheduleForm;