Publish: Make 'Channel' setting persistent.

Per discussion with Tom.
This commit is contained in:
infiinte-persistence 2020-06-16 11:58:25 +02:00 committed by Sean Yesmunt
parent 9d6af38a21
commit ff7b4092c9
2 changed files with 21 additions and 2 deletions
ui
component/publishForm
page/publish

View file

@ -66,6 +66,7 @@ type Props = {
// Add back type // Add back type
updatePublishForm: any => void, updatePublishForm: any => void,
checkAvailability: string => void, checkAvailability: string => void,
onChannelChange: string => void,
}; };
function PublishForm(props: Props) { function PublishForm(props: Props) {
@ -89,6 +90,7 @@ function PublishForm(props: Props) {
publish, publish,
disabled = false, disabled = false,
checkAvailability, checkAvailability,
onChannelChange,
} = props; } = props;
const TAGS_LIMIT = 5; const TAGS_LIMIT = 5;
const formDisabled = (!filePath && !editingURI) || publishing; const formDisabled = (!filePath && !editingURI) || publishing;
@ -144,6 +146,11 @@ function PublishForm(props: Props) {
} }
}, [name, channel, resolveUri, updatePublishForm, checkAvailability]); }, [name, channel, resolveUri, updatePublishForm, checkAvailability]);
function handleChannelNameChange(channel) {
onChannelChange(channel);
updatePublishForm({ channel });
}
return ( return (
<div className="card-stack"> <div className="card-stack">
<PublishFile disabled={disabled || publishing} inProgress={isInProgress} /> <PublishFile disabled={disabled || publishing} inProgress={isInProgress} />
@ -182,7 +189,7 @@ function PublishForm(props: Props) {
<Card <Card
actions={ actions={
<React.Fragment> <React.Fragment>
<SelectChannel channel={channel} onChannelChange={channel => updatePublishForm({ channel })} /> <SelectChannel channel={channel} onChannelChange={handleChannelNameChange} />
<p className="help"> <p className="help">
{__('This is a username or handle that your content can be found under.')}{' '} {__('This is a username or handle that your content can be found under.')}{' '}
{__('Ex. @Marvel, @TheBeatles, @BooksByJoe')} {__('Ex. @Marvel, @TheBeatles, @BooksByJoe')}

View file

@ -5,6 +5,7 @@ import Page from 'component/page';
import Yrbl from 'component/yrbl'; import Yrbl from 'component/yrbl';
import LbcSymbol from 'component/common/lbc-symbol'; import LbcSymbol from 'component/common/lbc-symbol';
import RewardAuthIntro from 'component/rewardAuthIntro'; import RewardAuthIntro from 'component/rewardAuthIntro';
import usePersistedState from 'effects/use-persisted-state';
type Props = { type Props = {
balance: number, balance: number,
@ -14,6 +15,8 @@ type Props = {
function PublishPage(props: Props) { function PublishPage(props: Props) {
const { balance } = props; const { balance } = props;
const [channel, setChannel] = usePersistedState('publish-channel', '');
function scrollToTop() { function scrollToTop() {
const mainContent = document.querySelector('main'); const mainContent = document.querySelector('main');
if (mainContent) { if (mainContent) {
@ -21,6 +24,10 @@ function PublishPage(props: Props) {
} }
} }
function handleChannelChange(channel) {
setChannel(channel);
}
return ( return (
<Page> <Page>
{balance === 0 ? ( {balance === 0 ? (
@ -55,7 +62,12 @@ function PublishPage(props: Props) {
</div> </div>
</Fragment> </Fragment>
) : ( ) : (
<PublishForm scrollToTop={scrollToTop} disabled={balance === 0} /> <PublishForm
scrollToTop={scrollToTop}
disabled={balance === 0}
channel={channel}
onChannelChange={handleChannelChange}
/>
)} )}
</Page> </Page>
); );