summaryrefslogtreecommitdiff
path: root/animism-align/frontend/views/align/align.actions.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-07-02 00:35:06 +0200
committerJules Laplace <julescarbon@gmail.com>2020-07-02 00:35:06 +0200
commit3e2c1d432d73823e66e19d0081b498ace467b231 (patch)
tree67a8b66eb8334b97e031f2c91da668591132ede3 /animism-align/frontend/views/align/align.actions.js
parent250527589e003420a84f36c4191d2e574f1ad28c (diff)
display the form
Diffstat (limited to 'animism-align/frontend/views/align/align.actions.js')
-rw-r--r--animism-align/frontend/views/align/align.actions.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/animism-align/frontend/views/align/align.actions.js b/animism-align/frontend/views/align/align.actions.js
index 2e1c795..82e4799 100644
--- a/animism-align/frontend/views/align/align.actions.js
+++ b/animism-align/frontend/views/align/align.actions.js
@@ -24,3 +24,39 @@ export const throttledSetZoom = throttle(zoom => dispatch => {
export const setCursor = cursor_ts => dispatch => (
dispatch({ type: types.align.set_display_setting, key: 'cursor_ts', value: cursor_ts })
)
+
+export const showNewTimestampForm = (start_ts, text) => dispatch => {
+ let croppedText;
+ if (store.getState().align.annotation.start_ts) {
+ croppedText = store.getState().align.annotation.text
+ } else {
+ croppedText = cutFirstSentence(text)
+ }
+ console.log(croppedText)
+ dispatch({
+ type: types.align.set_temporary_annotation,
+ data: {
+ id: 'new',
+ start_ts,
+ text: croppedText,
+ type: 'sentence',
+ }
+ })
+}
+
+const cutFirstSentence = text => {
+ const textToCrop = text.trim().replace("\n", " ").split("\n")[0]
+ let cropIndex = textToCrop.indexOf('. ') + 1
+ if (!cropIndex) cropIndex = textToCrop.length
+ const croppedText = textToCrop.substr(0, cropIndex).trim()
+ const updatedText = text.trim().replace(croppedText, '').trim()
+ actions.site.updateText(updatedText)
+ return croppedText
+}
+
+export const hideTimestampForm = () => dispatch => {
+ dispatch({
+ type: types.align.set_temporary_annotation,
+ data: {}
+ })
+}