Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Fixes comment/edit bug when no changes occur (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone authored Apr 21, 2020
1 parent 9b29f41 commit 54b0735
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions client/scripts/views/pages/view_proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ interface IProposalBodyAttrs {
interface IProposalBodyState {
editing: boolean;
quillEditorState: any;
currentText: any;
}

const ProposalHeader: m.Component<IProposalHeaderAttrs> = {
Expand Down Expand Up @@ -321,6 +322,7 @@ export const ProposalBody: m.Component<IProposalBodyAttrs, IProposalBodyState> =
href: '#',
onclick: async (e) => {
e.preventDefault();
vnode.state.currentText = proposal['body'] || proposal['description'];
if (getSetGlobalReplyStatus(GlobalStatus.Get)) {
if (activeQuillEditorHasText()) {
const confirmed = await confirmationModalWithText('Unsubmitted replies will be lost. Continue?')();
Expand Down Expand Up @@ -353,8 +355,13 @@ export const ProposalBody: m.Component<IProposalBodyAttrs, IProposalBodyState> =
href: '#',
onclick: async (e) => {
e.preventDefault();
// TODO: Only show confirmation modal if edits have been made
const confirmed = await confirmationModalWithText('Cancel editing? Changes will not be saved.')();
let confirmed = true;
const threadText = vnode.state.quillEditorState.markdownMode
? vnode.state.quillEditorState.editor.getText()
: JSON.stringify(vnode.state.quillEditorState.editor.getContents());
if (threadText !== vnode.state.currentText) {
confirmed = await confirmationModalWithText('Cancel editing? Changes will not be saved.')();
}
if (!confirmed) return;
vnode.state.editing = false;
getSetGlobalEditingStatus(GlobalStatus.Set, false);
Expand Down Expand Up @@ -444,6 +451,7 @@ interface IProposalCommentState {
editing: boolean;
replying: boolean;
quillEditorState: any;
currentText: any;
}

interface IProposalCommentAttrs {
Expand Down Expand Up @@ -528,6 +536,7 @@ const ProposalComment: m.Component<IProposalCommentAttrs, IProposalCommentState>
onclick: async (e) => {
e.preventDefault();
vnode.state.editing = true;
vnode.state.currentText = comment.text;
if (getSetGlobalReplyStatus(GlobalStatus.Get)) {
if (activeQuillEditorHasText()) {
const confirmed = await confirmationModalWithText('Unsubmitted replies will be lost. Continue?')();
Expand Down Expand Up @@ -559,8 +568,13 @@ const ProposalComment: m.Component<IProposalCommentAttrs, IProposalCommentState>
href: '#',
onclick: async (e) => {
e.preventDefault();
// TODO: Only show confirmation modal if edits have been made
const confirmed = await confirmationModalWithText('Cancel editing? Changes will not be saved.')();
let confirmed = true;
const commentText = vnode.state.quillEditorState.markdownMode
? vnode.state.quillEditorState.editor.getText()
: JSON.stringify(vnode.state.quillEditorState.editor.getContents());
if (commentText !== vnode.state.currentText) {
confirmed = await confirmationModalWithText('Cancel editing? Changes will not be saved.')();
}
if (!confirmed) return;
vnode.state.editing = false;
getSetGlobalEditingStatus(GlobalStatus.Set, false);
Expand Down

0 comments on commit 54b0735

Please sign in to comment.