Commit 9c6467e267ec5e13ac657da60215077fc7b42510
Fix cancel edit + selecting emoji
Anders Rune Jensen committed on 11/6/2017, 11:29:59 PMParent: 363c1fceec796d28922e74365e68a01c75b5e076
Files changed
book/html/layout/detail.js | changed |
book/html/layout/detail.js | ||
---|---|---|
@@ -65,8 +65,12 @@ | ||
65 | 65 … | cb(null, getEmojiSuggestions(inputText.slice(1))) |
66 | 66 … | } |
67 | 67 … | }, {cls: 'PatchSuggest'}) |
68 | 68 … | |
69 … | + ratingTypeInput.addEventListener('suggestselect', ev => { | |
70 … | + value.set(ev.detail.value) | |
71 … | + }) | |
72 … | + | |
69 | 73 … | return when(isEditing, suggestWrapper, |
70 | 74 … | h('span.text', { innerHTML: computed(value, simpleMarkdown) })) |
71 | 75 … | } |
72 | 76 … | |
@@ -97,8 +101,10 @@ | ||
97 | 101 … | |
98 | 102 … | const { title, authors, description, images } = api.book.html |
99 | 103 … | |
100 | 104 … | let isEditingSubjective = Value(false) |
105 … | + let originalSubjective = {} | |
106 … | + let originalBook = {} | |
101 | 107 … | let reviews = [] |
102 | 108 … | |
103 | 109 … | return [h('Message -book-detail', [ |
104 | 110 … | title({ title: obs.title, msg, isEditing, onUpdate: obs.title.set }), |
@@ -108,9 +114,18 @@ | ||
108 | 114 … | h('section.description', |
109 | 115 … | description({description: obs.description, isEditing, onUpdate: obs.description.set})), |
110 | 116 … | ]), |
111 | 117 … | h('section.actions', [ |
112 | - h('button.edit', { 'ev-click': () => isEditing.set(!isEditing()) }, | |
118 … | + h('button.edit', { 'ev-click': () => { | |
119 … | + if (isEditing()) { // cancel | |
120 … | + Object.keys(originalBook).forEach((v) => { | |
121 … | + obs[v].set(originalBook[v]) | |
122 … | + }) | |
123 … | + } else | |
124 … | + originalBook = JSON.parse(JSON.stringify(obs())) | |
125 … | + | |
126 … | + isEditing.set(!isEditing()) | |
127 … | + } }, | |
113 | 128 … | when(isEditing, 'Cancel', 'Edit book')), |
114 | 129 … | when(isEditing, h('button', {'ev-click': () => saveBook(obs)}, 'Update book')) |
115 | 130 … | ]), |
116 | 131 … | h('section.subjective', [ |
@@ -138,9 +153,21 @@ | ||
138 | 153 … | return reviews |
139 | 154 … | }) |
140 | 155 … | ]), |
141 | 156 … | h('section.actions', [ |
142 | - h('button.subjective', { 'ev-click': () => isEditingSubjective.set(!isEditingSubjective()) }, | |
157 … | + h('button.subjective', { | |
158 … | + 'ev-click': () => { | |
159 … | + if (isEditingSubjective()) { // cancel | |
160 … | + let subj = obs.subjective.get(api.keys.sync.id()) | |
161 … | + Object.keys(originalSubjective).forEach((v) => { | |
162 … | + subj[v].set(originalSubjective[v]) | |
163 … | + }) | |
164 … | + } else | |
165 … | + originalSubjective = JSON.parse(JSON.stringify(obs.subjective.get(api.keys.sync.id())())) | |
166 … | + | |
167 … | + isEditingSubjective.set(!isEditingSubjective()) | |
168 … | + } | |
169 … | + }, | |
143 | 170 … | when(isEditingSubjective, 'Cancel', 'Edit rating')), |
144 | 171 … | when(isEditingSubjective, h('button', { 'ev-click': () => saveSubjective(obs) }, 'Update rating')) |
145 | 172 … | ]), |
146 | 173 … | ])] |
Built with git-ssb-web