-
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
Conversation
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.
I tested this out and it works great, thx a ton. So nice to get rid of that finished map, and all those lifecycle events.
I'm not sure why the non-relative import doesn't throw an error, because I've almost always seen that. I'd change it to relative just in case tho.
Lets let @SleeplessOne1917 take a look, then we can merge.
import { CommentNodeI } from "../../interfaces"; | ||
import { I18NextService, UserService } from "../../services"; | ||
import { Icon } from "../common/icon"; | ||
import { MarkdownTextArea } from "../common/markdown-textarea"; | ||
import { RequestState } from "shared/services/HttpService"; |
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.
These need to be relative imports, or it'll fail.
@@ -87,7 +86,6 @@ interface CommentNodeProps { | |||
allLanguages: Language[]; | |||
siteLanguages: number[]; | |||
hideImages?: boolean; | |||
finished: Map<CommentId, boolean | undefined>; |
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.
@@ -973,13 +968,19 @@ export class Home extends Component<HomeRouteProps, HomeState> { | |||
const createCommentRes = await HttpService.client.createComment(form); | |||
this.createAndUpdateComments(createCommentRes); | |||
|
|||
if (createCommentRes.state === "failed") { |
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.
Thx, these are going to be handy.
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.
Thanks a lot for helping with this. Most of my efforts on making a nice looking UI have been focused on the UI rewrite, so I really appreciate you improving the UX on the current UI while the new one is under development.
import { CommentNodeI } from "../../interfaces"; | ||
import { I18NextService, UserService } from "../../services"; | ||
import { Icon } from "../common/icon"; | ||
import { MarkdownTextArea } from "../common/markdown-textarea"; | ||
import { RequestState } from "shared/services/HttpService"; |
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.
Use a relative import for this. For some reason, VS Code auto-imports from shared/*
sometimes, but doing so causes the build to fail.
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.
The Dockerfile
builds and runs fine with absolute import. I added a linter rule to catch these in the future.
handleCommentSubmit(content: string, language_id?: number) { | ||
async handleCommentSubmit( | ||
content: string, | ||
language_id?: number, | ||
): Promise<boolean> { | ||
const { node, onUpsertComment, edit } = this.props; | ||
if (typeof node === "number") { | ||
const post_id = node; | ||
onUpsertComment({ | ||
return onUpsertComment({ | ||
content, | ||
post_id, | ||
language_id, | ||
}); | ||
}).then(r => r.state !== "failed"); | ||
} else { | ||
if (edit) { | ||
const comment_id = node.comment_view.comment.id; | ||
onUpsertComment({ | ||
return onUpsertComment({ | ||
content, | ||
comment_id, | ||
language_id, | ||
}); | ||
}).then(r => r.state !== "failed"); | ||
} else { | ||
const post_id = node.comment_view.post.id; | ||
const parent_id = node.comment_view.comment.id; | ||
this.props.onUpsertComment({ | ||
return onUpsertComment({ | ||
content, | ||
parent_id, | ||
post_id, | ||
language_id, | ||
}); | ||
}).then(r => r.state !== "failed"); | ||
} | ||
} |
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.
I think this would be cleaner as
async handleCommentSubmit(
content: string,
language_id?: number,
): Promise<boolean> {
const { node, onUpsertComment, edit } = this.props;
let response: RequestState<CommentResponse>;
if (typeof node === "number") {
const post_id = node;
response = await onUpsertComment({
content,
post_id,
language_id,
});
} else if (edit) {
const comment_id = node.comment_view.comment.id;
response = await onUpsertComment({
content,
comment_id,
language_id,
});
} else {
const post_id = node.comment_view.post.id;
const parent_id = node.comment_view.comment.id;
response = await onUpsertComment({
content,
parent_id,
post_id,
language_id,
});
}
return response.state !== "failed";
}
Also, if you do use this code, make sure to run prettier on it since Github makes it hard to format code.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't onSubmit
always return a boolean, making the coalesce for success
unnecessary?
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.
onSubmit
is optional, which makes success
of type boolean | undefined
.
I used this snippet for testing, which selectively replaces the form with an empty object. It also adds a one second delay before the request is made. (Comment and post examples: submit_buttons.webm)
Comment and post examples with the above snippet: submit_buttons.webm