From 8f4d2dd417e7fd7a77a1d403101f1b47c13affdf Mon Sep 17 00:00:00 2001 From: Artyom Date: Sun, 19 Jun 2016 19:20:28 +0300 Subject: [PATCH] Merging for item notes --- src/JS.hs | 52 ++++++++++++++++++++++++++++++++++++++------------ src/Main.hs | 19 +++++++++++++----- src/View.hs | 6 ++++-- static/css.css | 2 ++ 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/JS.hs b/src/JS.hs index 9caba07..4bcd483 100644 --- a/src/JS.hs +++ b/src/JS.hs @@ -405,12 +405,28 @@ makeTraitEditor = $(sectionNode).append(area, br, cancelBtn, markdown); |] --- | Dynamically creates a 'View.markdownEdito' (but specifically for item +{- Note [blurb diffing] +~~~~~~~~~~~~~~~~~~~~~~~ + +A note on why we need 'empty' in 'makeItemNotesEditor'. + +Assume that the notes are empty. The text in the area, therefore, will be some default blurb (“# Links, #Imports, #Usage”, etc). Suppose the user edits it. What will be sent to the server? + + * original: blurb + * our version: modified blurb + +What will happen next? The server will compare it to the value currently at the server (i.e. an empty string), and think that the blurb *was* on the server but got deleted while the client was doing editing. This is wrong, and will result in a diff popup comparing an edited blurb to an empty string. To prevent this, we pass 'empty' to 'makeItemNotesEditor' – if we're using a blurb, we'll pass an empty string as the original. + +-} + +-- | Dynamically creates a 'View.markdownEditor' (but specifically for item -- notes). See Note [dynamic interface]. makeItemNotesEditor :: JSFunction a => a makeItemNotesEditor = + -- See Note [blurb diffing] makeJSFunction "makeItemNotesEditor" - ["notesNode", "sectionNode", "textareaUid", "content", "itemId"] + ["notesNode", "sectionNode", "textareaUid", + "empty", "content", "itemId"] [text| $(sectionNode).html(""); area = $("