Add selectDefaultLanguage for publishes
This is useful when editing a publish, as it allows us to set the default language in the publish form to the language of the original claim
This commit is contained in:
parent
4698ee760a
commit
a4cdca9bbc
2 changed files with 28 additions and 2 deletions
|
@ -1,9 +1,22 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import { selectPublishFormValues, doUpdatePublishForm } from 'lbry-redux';
|
||||
import { selectIsStillEditing } from 'redux/selectors/publish';
|
||||
import PublishPage from './view';
|
||||
|
||||
const selectDefaultLanguage = createSelector(
|
||||
selectPublishFormValues,
|
||||
selectIsStillEditing,
|
||||
(publishState, isStillEditing) => {
|
||||
const { languages, language } = publishState;
|
||||
// returns the language of the original claim if editing
|
||||
return isStillEditing ? languages[0] : language;
|
||||
}
|
||||
);
|
||||
|
||||
const select = state => ({
|
||||
...selectPublishFormValues(state),
|
||||
defaultLanguage: selectDefaultLanguage(state),
|
||||
});
|
||||
|
||||
const perform = dispatch => ({
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// @flow
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import classnames from 'classnames';
|
||||
import usePersistedState from 'effects/use-persisted-state';
|
||||
import { FormField } from 'component/common/form';
|
||||
|
@ -9,6 +9,7 @@ import Card from 'component/common/card';
|
|||
|
||||
type Props = {
|
||||
language: ?string,
|
||||
defaultLanguage: ?string,
|
||||
name: ?string,
|
||||
licenseType: ?string,
|
||||
otherLicenseDescription: ?string,
|
||||
|
@ -18,9 +19,21 @@ type Props = {
|
|||
};
|
||||
|
||||
function PublishAdvanced(props: Props) {
|
||||
const { language, name, licenseType, otherLicenseDescription, licenseUrl, updatePublishForm } = props;
|
||||
const {
|
||||
language,
|
||||
defaultLanguage,
|
||||
name,
|
||||
licenseType,
|
||||
otherLicenseDescription,
|
||||
licenseUrl,
|
||||
updatePublishForm,
|
||||
} = props;
|
||||
const [hideSection, setHideSection] = usePersistedState('publish-advanced-options', true);
|
||||
|
||||
useEffect(() => {
|
||||
updatePublishForm({ language: defaultLanguage });
|
||||
}, []);
|
||||
|
||||
function toggleHideSection() {
|
||||
setHideSection(!hideSection);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue