Add an isScheduled state to publish form + use it to set the initial state of the date/time controls

This commit is contained in:
Dan Peterson 2022-01-05 08:59:26 -06:00 committed by Thomas Zarebczan
parent cb562ef27d
commit a021475128
3 changed files with 9 additions and 4 deletions

View file

@ -1,9 +1,10 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectPublishFormValue } from 'redux/selectors/publish'; import { makeSelectPublishFormValue, selectIsScheduled } from 'redux/selectors/publish';
import { doUpdatePublishForm } from 'redux/actions/publish'; import { doUpdatePublishForm } from 'redux/actions/publish';
import PublishStreamReleaseDate from './view'; import PublishStreamReleaseDate from './view';
const select = (state) => ({ const select = (state) => ({
isScheduled: selectIsScheduled(state),
releaseTime: makeSelectPublishFormValue('releaseTime')(state), releaseTime: makeSelectPublishFormValue('releaseTime')(state),
}); });

View file

@ -13,14 +13,15 @@ function dateToLinuxTimestamp(date: Date) {
} }
type Props = { type Props = {
isScheduled: boolean,
releaseTime: ?number, releaseTime: ?number,
updatePublishForm: ({}) => void, updatePublishForm: ({}) => void,
}; };
const PublishStreamReleaseDate = (props: Props) => { const PublishStreamReleaseDate = (props: Props) => {
const { releaseTime, updatePublishForm } = props; const { isScheduled, releaseTime, updatePublishForm } = props;
const [date, setDate] = React.useState(releaseTime ? linuxTimestampToDate(releaseTime) : 'DEFAULT'); const [date, setDate] = React.useState(releaseTime ? linuxTimestampToDate(releaseTime) : 'DEFAULT');
const [publishLater, setPublishLater] = React.useState(Boolean(releaseTime)); const [publishLater, setPublishLater] = React.useState(isScheduled);
const handleToggle = () => { const handleToggle = () => {
const shouldPublishLater = !publishLater; const shouldPublishLater = !publishLater;
@ -41,7 +42,7 @@ const PublishStreamReleaseDate = (props: Props) => {
}; };
useEffect(() => { useEffect(() => {
if (!releaseTime) updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true }); if (!isScheduled) updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true });
return () => updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: false }); return () => updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: false });
}, []); }, []);

View file

@ -6,6 +6,7 @@ import {
selectResolvingUris, selectResolvingUris,
selectClaimsByUri, selectClaimsByUri,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { SCHEDULED_LIVESTREAM_TAG } from 'constants/tags';
const selectState = (state) => state.publish || {}; const selectState = (state) => state.publish || {};
@ -126,3 +127,5 @@ export const selectUploadCount = createSelector(
selectCurrentUploads, selectCurrentUploads,
(currentUploads) => currentUploads && Object.keys(currentUploads).length (currentUploads) => currentUploads && Object.keys(currentUploads).length
); );
export const selectIsScheduled = (state) => selectState(state).tags.some((t) => t.name === SCHEDULED_LIVESTREAM_TAG);