publish: edit post content no longer tied to api

The component for editing a post was tied up in checking for API
instantiation -- we want the check for a blank body to be independent
of that.

Fixes #3040.
This commit is contained in:
Matilde Park 2020-06-22 22:36:39 -04:00
parent 4fded00005
commit ceff9626c5

View File

@ -25,17 +25,19 @@ export class EditPost extends Component {
componentDidUpdate(prevProps) {
const { props, state } = this;
const contents = props.notebooks[props.ship]?.[props.book]?.notes?.[props.note]?.file;
if (prevProps && prevProps.api !== props.api) {
if (!(props.notebooks[props.ship]?.[props.book]?.notes?.[props.note]?.file)) {
if (!contents) {
props.api?.fetchNote(props.ship, props.book, props.note);
} else if (state.body === '') {
const notebook = props.notebooks[props.ship][props.book];
const note = notebook.notes[props.note];
const file = note.file;
const body = file.slice(file.indexOf(';>') + 3);
this.setState({ body: body });
}
}
if (contents && state.body === '') {
const notebook = props.notebooks[props.ship][props.book];
const note = notebook.notes[props.note];
const file = note.file;
const body = file.slice(file.indexOf(';>') + 3);
this.setState({ body: body });
}
}
postSubmit() {
@ -95,7 +97,7 @@ export class EditPost extends Component {
};
return (
<div className="f9 h-100 relative">
<div className="f9 h-100 relative publish">
<div className="w-100 tl pv4 flex justify-center">
<SidebarSwitcher
sidebarShown={props.sidebarShown}