mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-22 07:29:08 +00:00
feat: increment running timer
This commit is contained in:
@@ -3,6 +3,7 @@ import Countdown from '../../common/components/countdown/Countdown';
|
|||||||
import { stringFromMillis } from '../../common/dateConfig';
|
import { stringFromMillis } from '../../common/dateConfig';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useSocket } from '../../app/context/socketContext';
|
import { useSocket } from '../../app/context/socketContext';
|
||||||
|
import { Button } from '@chakra-ui/button';
|
||||||
import StartIconBtn from '../../common/components/buttons/StartIconBtn';
|
import StartIconBtn from '../../common/components/buttons/StartIconBtn';
|
||||||
import PauseIconBtn from '../../common/components/buttons/PauseIconBtn';
|
import PauseIconBtn from '../../common/components/buttons/PauseIconBtn';
|
||||||
import PrevIconBtn from '../../common/components/buttons/PrevIconBtn';
|
import PrevIconBtn from '../../common/components/buttons/PrevIconBtn';
|
||||||
@@ -96,6 +97,14 @@ export default function PlaybackControl() {
|
|||||||
const started = stringFromMillis(timer.startedAt, true);
|
const started = stringFromMillis(timer.startedAt, true);
|
||||||
const finish = stringFromMillis(timer.expectedFinish, true);
|
const finish = stringFromMillis(timer.expectedFinish, true);
|
||||||
|
|
||||||
|
const incrementProps = {
|
||||||
|
size: 'sm',
|
||||||
|
width: '2.9em',
|
||||||
|
colorScheme: 'whiteAlpha',
|
||||||
|
variant: 'outline',
|
||||||
|
_focus: { boxShadow: 'none' },
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.mainContainer}>
|
<div className={style.mainContainer}>
|
||||||
<div className={style.timeContainer}>
|
<div className={style.timeContainer}>
|
||||||
@@ -110,6 +119,32 @@ export default function PlaybackControl() {
|
|||||||
<span className={style.tag}>Finish at </span>
|
<span className={style.tag}>Finish at </span>
|
||||||
<span className={style.time}>{finish}</span>
|
<span className={style.time}>{finish}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div className={style.btn}>
|
||||||
|
<Button
|
||||||
|
{...incrementProps}
|
||||||
|
onClick={() => socket.emit('increment-timer', 1)}
|
||||||
|
>
|
||||||
|
+1
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
{...incrementProps}
|
||||||
|
onClick={() => socket.emit('increment-timer', 5)}
|
||||||
|
>
|
||||||
|
+5
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
{...incrementProps}
|
||||||
|
onClick={() => socket.emit('increment-timer', -1)}
|
||||||
|
>
|
||||||
|
-1
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
{...incrementProps}
|
||||||
|
onClick={() => socket.emit('increment-timer', -5)}
|
||||||
|
>
|
||||||
|
-5
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={style.playbackContainer}>
|
<div className={style.playbackContainer}>
|
||||||
|
|||||||
@@ -17,10 +17,10 @@
|
|||||||
.timeContainer {
|
.timeContainer {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-areas:
|
grid-template-areas:
|
||||||
'clk clk ...'
|
'clk clk btn'
|
||||||
'sta fin ...';
|
'sta fin btn';
|
||||||
grid-template-rows: 1fr auto;
|
grid-template-rows: 1fr auto;
|
||||||
grid-template-columns: 1fr 1fr 80px;
|
grid-template-columns: 2fr 2fr 22%;
|
||||||
gap: 5px;
|
gap: 5px;
|
||||||
justify-items: start;
|
justify-items: start;
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,22 @@
|
|||||||
grid-area: clk;
|
grid-area: clk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
grid-area: btn;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.minus {
|
||||||
|
grid-area: min;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
.start {
|
.start {
|
||||||
grid-area: sta;
|
grid-area: sta;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,6 +239,12 @@ class EventTimer extends Timer {
|
|||||||
socket.emit('timer', this.getObject());
|
socket.emit('timer', this.getObject());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('increment-timer', (data) => {
|
||||||
|
if (isNaN(parseInt(data))) return;
|
||||||
|
if (data < -5 || data > 5) return;
|
||||||
|
this.increment(data * 1000 * 60);
|
||||||
|
});
|
||||||
|
|
||||||
/*******************************************/
|
/*******************************************/
|
||||||
// playstate
|
// playstate
|
||||||
socket.on('set-playstate', (data) => {
|
socket.on('set-playstate', (data) => {
|
||||||
@@ -624,6 +630,14 @@ class EventTimer extends Timer {
|
|||||||
this.broadcastState();
|
this.broadcastState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
increment(amount) {
|
||||||
|
// call super
|
||||||
|
super.increment(amount);
|
||||||
|
|
||||||
|
// broadcast current state
|
||||||
|
this.broadcastState();
|
||||||
|
}
|
||||||
|
|
||||||
goto(eventIndex) {
|
goto(eventIndex) {
|
||||||
// load event
|
// load event
|
||||||
this.loadEvent(eventIndex);
|
this.loadEvent(eventIndex);
|
||||||
|
|||||||
+18
-2
@@ -58,6 +58,7 @@ class Timer {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'pause':
|
case 'pause':
|
||||||
|
if (this.current <= 0) return;
|
||||||
// update paused time
|
// update paused time
|
||||||
this._pausedInterval = now - this._pausedAt;
|
this._pausedInterval = now - this._pausedAt;
|
||||||
break;
|
break;
|
||||||
@@ -129,8 +130,8 @@ class Timer {
|
|||||||
start() {
|
start() {
|
||||||
// do we need to change
|
// do we need to change
|
||||||
if (this.state === 'start') return;
|
if (this.state === 'start') return;
|
||||||
else if (this.duration === 0) return;
|
else if (this.duration <= 0) return;
|
||||||
else if (this.startedAt == null) {
|
else if (this._startedAt == null) {
|
||||||
this._resetTimers();
|
this._resetTimers();
|
||||||
const now = this._getCurrentTime();
|
const now = this._getCurrentTime();
|
||||||
this._startedAt = now;
|
this._startedAt = now;
|
||||||
@@ -165,6 +166,21 @@ class Timer {
|
|||||||
this._resetTimers();
|
this._resetTimers();
|
||||||
this.state = 'stop';
|
this.state = 'stop';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
increment(amount) {
|
||||||
|
|
||||||
|
if (amount < 0) {
|
||||||
|
if (Math.abs(amount) > this.current) {
|
||||||
|
console.log('ot os');
|
||||||
|
|
||||||
|
this.current = 0;
|
||||||
|
this._finishAt = this._getCurrentTime();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.current += amount;
|
||||||
|
this._finishAt += amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Timer;
|
module.exports = Timer;
|
||||||
|
|||||||
Reference in New Issue
Block a user