Add an isScheduled state to publish form + use it to set the initial state of the date/time controls
This commit is contained in:
parent
cb562ef27d
commit
a021475128
3 changed files with 9 additions and 4 deletions
|
@ -1,9 +1,10 @@
|
|||
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 PublishStreamReleaseDate from './view';
|
||||
|
||||
const select = (state) => ({
|
||||
isScheduled: selectIsScheduled(state),
|
||||
releaseTime: makeSelectPublishFormValue('releaseTime')(state),
|
||||
});
|
||||
|
||||
|
|
|
@ -13,14 +13,15 @@ function dateToLinuxTimestamp(date: Date) {
|
|||
}
|
||||
|
||||
type Props = {
|
||||
isScheduled: boolean,
|
||||
releaseTime: ?number,
|
||||
updatePublishForm: ({}) => void,
|
||||
};
|
||||
const PublishStreamReleaseDate = (props: Props) => {
|
||||
const { releaseTime, updatePublishForm } = props;
|
||||
const { isScheduled, releaseTime, updatePublishForm } = props;
|
||||
|
||||
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 shouldPublishLater = !publishLater;
|
||||
|
@ -41,7 +42,7 @@ const PublishStreamReleaseDate = (props: Props) => {
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!releaseTime) updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true });
|
||||
if (!isScheduled) updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: true });
|
||||
return () => updatePublishForm({ releaseTimeEdited: undefined, releaseAnytime: false });
|
||||
}, []);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
selectResolvingUris,
|
||||
selectClaimsByUri,
|
||||
} from 'redux/selectors/claims';
|
||||
import { SCHEDULED_LIVESTREAM_TAG } from 'constants/tags';
|
||||
|
||||
const selectState = (state) => state.publish || {};
|
||||
|
||||
|
@ -126,3 +127,5 @@ export const selectUploadCount = createSelector(
|
|||
selectCurrentUploads,
|
||||
(currentUploads) => currentUploads && Object.keys(currentUploads).length
|
||||
);
|
||||
|
||||
export const selectIsScheduled = (state) => selectState(state).tags.some((t) => t.name === SCHEDULED_LIVESTREAM_TAG);
|
||||
|
|
Loading…
Reference in a new issue