fix publishForm flow errors

This commit is contained in:
btzr-io 2020-08-10 20:26:44 -05:00 committed by Sean Yesmunt
parent b49df1fc0a
commit 334f582a4d

View file

@ -37,9 +37,9 @@ const MODES = Object.values(PUBLISH_MODES);
type Props = { type Props = {
disabled: boolean, disabled: boolean,
tags: Array<Tag>, tags: Array<Tag>,
publish: (?string) => void, publish: (source?: string | File) => void,
filePath: ?string, filePath: string | File,
fileText: ?string, fileText: string,
bid: ?number, bid: ?number,
bidError: ?string, bidError: ?string,
editingURI: ?string, editingURI: ?string,
@ -217,21 +217,26 @@ function PublishForm(props: Props) {
function createWebFile() { function createWebFile() {
if (fileText) { if (fileText) {
const fileName = name || title; const fileName = name || title;
if (fileName) {
return new File([fileText], `${fileName}.md`, { type: 'text/markdown' }); return new File([fileText], `${fileName}.md`, { type: 'text/markdown' });
} }
} }
}
// @endif // @endif
// @if TARGET='app' // @if TARGET='app'
// Save file changes locally ( desktop ) // Save file changes locally ( desktop )
function saveFileChanges() { function saveFileChanges() {
let output = filePath; let output;
if (!output || output === '') { if (!output || output === '') {
// Generate a temporary file: // Generate a temporary file:
output = tempy.file({ name: 'post.md' }); output = tempy.file({ name: 'post.md' });
} else if (typeof filePath === 'string') {
// Use current file
output = filePath;
} }
// Create a temporary file and save file changes // Create a temporary file and save file changes
if (typeof output === 'string') { if (output && output !== '') {
// Save file changes // Save file changes
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fs.writeFile(output, fileText, (error, data) => { fs.writeFile(output, fileText, (error, data) => {