-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some submit button issues #2487
Changes from all commits
59b08d9
b920e2b
e6aede3
676bc8b
b77468c
4fbbd9b
befc445
02515b7
c1f6c35
824d7bf
2ba74ca
48cb1f3
cb36e26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { numToSI, randomStr } from "@utils/helpers"; | |
import autosize from "autosize"; | ||
import classNames from "classnames"; | ||
import { NoOptionI18nKeys } from "i18next"; | ||
import { Component, InfernoNode, linkEvent } from "inferno"; | ||
import { Component, linkEvent } from "inferno"; | ||
import { Prompt } from "inferno-router"; | ||
import { Language } from "lemmy-js-client"; | ||
import { | ||
|
@@ -41,15 +41,14 @@ interface MarkdownTextAreaProps { | |
replyType?: boolean; | ||
focus?: boolean; | ||
disabled?: boolean; | ||
finished?: boolean; | ||
/** | ||
* Whether to show the language selector | ||
*/ | ||
showLanguage?: boolean; | ||
hideNavigationWarnings?: boolean; | ||
onContentChange?(val: string): void; | ||
onReplyCancel?(): void; | ||
onSubmit?(content: string, languageId?: number): void; | ||
onSubmit?(content: string, languageId?: number): Promise<boolean>; | ||
allLanguages: Language[]; // TODO should probably be nullable | ||
siteLanguages: number[]; // TODO same | ||
} | ||
|
@@ -115,27 +114,6 @@ export class MarkdownTextArea extends Component< | |
} | ||
} | ||
|
||
componentWillReceiveProps( | ||
nextProps: MarkdownTextAreaProps & { children?: InfernoNode }, | ||
) { | ||
if (nextProps.finished) { | ||
this.setState({ | ||
previewMode: false, | ||
imageUploadStatus: undefined, | ||
loading: false, | ||
content: undefined, | ||
}); | ||
if (this.props.replyType) { | ||
this.props.onReplyCancel?.(); | ||
} | ||
|
||
const textarea: any = document.getElementById(this.id); | ||
const form: any = document.getElementById(this.formId); | ||
form.reset(); | ||
setTimeout(() => autosize.update(textarea), 10); | ||
} | ||
} | ||
|
||
render() { | ||
const languageId = this.state.languageId; | ||
|
||
|
@@ -149,8 +127,8 @@ export class MarkdownTextArea extends Component< | |
message={I18NextService.i18n.t("block_leaving")} | ||
when={ | ||
!this.props.hideNavigationWarnings && | ||
!!this.state.content && | ||
!this.state.submitted | ||
((!!this.state.content && !this.state.submitted) || | ||
this.state.loading) | ||
} | ||
/> | ||
<div className="mb-3 row"> | ||
|
@@ -575,11 +553,15 @@ export class MarkdownTextArea extends Component< | |
this.setState({ languageId: val[0] }); | ||
} | ||
|
||
handleSubmit(i: MarkdownTextArea, event: any) { | ||
async handleSubmit(i: MarkdownTextArea, event: any) { | ||
event.preventDefault(); | ||
if (i.state.content) { | ||
i.setState({ loading: true, submitted: true }); | ||
i.props.onSubmit?.(i.state.content, i.state.languageId); | ||
const success = await i.props.onSubmit?.( | ||
i.state.content, | ||
i.state.languageId, | ||
); | ||
i.setState({ loading: false, submitted: success ?? true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, its nice to get rid of these.