about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-07-02 00:36:16 +0200
committerThibaut Girka <thib@sitedethib.com>2019-07-04 16:24:48 +0200
commit894d82a3258c763adafad6640b71072d3071d411 (patch)
treed50d2b4ee7a1bddf0834515e9705c129a3d3f88d /app/javascript/flavours/glitch
parent6ab84c12a7ebc68fb8ce9a6b8228b28ec06a2c0f (diff)
[Glitch] When deleting & redrafting a poll, fill in closest expires_in
Port dc88d226e1fdb20499d6e81838b81894b2d0be2d to glitch-soc
Diffstat (limited to 'app/javascript/flavours/glitch')
-rw-r--r--app/javascript/flavours/glitch/reducers/compose.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/app/javascript/flavours/glitch/reducers/compose.js b/app/javascript/flavours/glitch/reducers/compose.js
index 36dfb8f15..a47b8b7bd 100644
--- a/app/javascript/flavours/glitch/reducers/compose.js
+++ b/app/javascript/flavours/glitch/reducers/compose.js
@@ -275,6 +275,12 @@ const expandMentions = status => {
   return fragment.innerHTML;
 };
 
+const expiresInFromExpiresAt = expires_at => {
+  if (!expires_at) return 24 * 3600;
+  const delta = (new Date(expires_at).getTime() - Date.now()) / 1000;
+  return [300, 1800, 3600, 21600, 86400, 259200, 604800].find(expires_in => expires_in >= delta) || 24 * 3600;
+};
+
 export default function compose(state = initialState, action) {
   switch(action.type) {
   case STORE_HYDRATE:
@@ -456,7 +462,7 @@ export default function compose(state = initialState, action) {
         map.set('poll', ImmutableMap({
           options: action.status.getIn(['poll', 'options']).map(x => x.get('title')),
           multiple: action.status.getIn(['poll', 'multiple']),
-          expires_in: 24 * 3600,
+          expires_in: expiresInFromExpiresAt(action.status.getIn(['poll', 'expires_at'])),
         }));
       }
     });