diff --git a/front/src/style.css b/front/src/style.css index e0eaae40575493d59809380c5ab97a136e5a585b..29ef3ccc37d2d7821f18938dd90d8e761e5bc17c 100644 --- a/front/src/style.css +++ b/front/src/style.css @@ -55,10 +55,8 @@ justify-content: space-between; } -.image-text-bloc > .text-section > .text-element:first-child { - flex-grow: 1; -} - .image-text-bloc > .text-section > .text-element:last-child { white-space: nowrap; + flex-grow: 1; + text-align: right; } diff --git a/server/index.js b/server/index.js index a9a740d2bb915c42911b6e26bbf0ccc144bb43cf..7efe6a45dcd3ce7cd31425cddd23f4946614f49e 100644 --- a/server/index.js +++ b/server/index.js @@ -41,6 +41,6 @@ io.of('/').on('connection', (socket) => { }); socket.on('disconnect', () => { - chrono.clear(); + chrono.stop(); }); }); diff --git a/server/utils.js b/server/utils.js index 0716563e9fb2361df198888890de647cfe70f282..ebc10574df921d9bdaa3a993e0311fcf4a32c9be 100644 --- a/server/utils.js +++ b/server/utils.js @@ -2,14 +2,6 @@ const jwt = require('jsonwebtoken'); const { cert } = require('./config'); -const initialOutput = { id: null, clear: () => undefined, trigger: () => undefined }; - -const replace = (toReplace, replacer) => { - Object.keys(replacer).forEach((x) => { - toReplace[x] = replacer[x]; - }); -}; - function Timeout(fn, interval) { this.id = setTimeout(fn, interval); this.cleared = false; @@ -19,7 +11,7 @@ function Timeout(fn, interval) { }; } -const interval = (fn, initialTTL, output = initialOutput) => { +const interval = (fn, initialTTL, output = {}) => { const getTimeout = ttl => new Timeout(async () => { let TTL; @@ -41,18 +33,48 @@ const interval = (fn, initialTTL, output = initialOutput) => { const nextTTL = parseInt(TTL, 10) || initialTTL; interval(fn, nextTTL, output); }, ttl); - const getOutput = timeout => ({ - id: timeout.id, - clear: () => timeout.clear(), - trigger: () => { - timeout.clear(); - const newTimeout = getTimeout(0); - replace(output, getOutput(newTimeout)); - }, - }); - const timeout = getTimeout(initialTTL); - replace(output, getOutput(timeout)); + const getOutput = (timeout) => { + const stop = () => { + if (timeout) { + timeout.clear(); + } + }; + return { + start: (ttl) => { + if (timeout && !timeout.cleared) { + throw new Error('Interval is already started'); + } + const newOutput = getOutput(getTimeout(ttl || initialTTL)); + Object.assign(output, getOutput(newOutput)); + return output; + }, + startNow: () => { + if (timeout && !timeout.cleared) { + throw new Error('Interval is already started'); + } + Object.assign(output, getOutput(getTimeout(0))); + return output; + }, + restart: (ttl) => { + stop(); + Object.assign(output, getOutput(getTimeout(ttl || initialTTL))); + return output; + }, + stop, + restartNow: () => { + stop(); + Object.assign(output, getOutput(getTimeout(0))); + return output; + }, + }; + }; + + if (Object.keys(output).length === 0) { + Object.assign(output, getOutput(null)); + } else { + Object.assign(output, getOutput(getTimeout(initialTTL))); + } return output; };