Skip to content

Commit

Permalink
make timer keep remaining time as goal after log time, and add initia…
Browse files Browse the repository at this point in the history
…l goal in timer modal
  • Loading branch information
wang9hu committed Oct 26, 2023
1 parent 467cbb8 commit 29e9bb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/models/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const timerSchema = new Schema({
startAt: { type: Date, default: Date.now },
time: { type: Number, default: 900000 },
goal: { type: Number, default: 900000 },
initialGoal: { type: Number, default: 900000 },
paused: { type: Boolean, default: false },
forcedPause: { type: Boolean, default: false },
started: { type: Boolean, default: false },
Expand Down
24 changes: 11 additions & 13 deletions src/websockets/TimerService/clientsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,30 @@ const ackForcedPause = (client) => {
};

const stopTimer = (client) => {
if (client.started) pauseTimer(client);
client.startAt = moment.invalid();
client.started = false;
client.pause = false;
client.forcedPause = false;
if (client.time === 0) {
client.goal = client.initialGoal;
client.time = client.goal;
} else {
client.goal = client.time;
}
};

const clearTimer = (client) => {
stopTimer(client);
client.goal = client.initialGoal;
client.time = client.goal;
};

const setGoal = (client, msg) => {
const newGoal = parseInt(msg.split('=')[1]);
if (!client.started) {
client.goal = newGoal;
client.time = newGoal;
} else {
const passedTime = client.goal - client.time;
if (passedTime >= newGoal) {
client.time = 0;
client.goal = passedTime;
} else {
client.time = newGoal - passedTime;
client.goal = newGoal;
}
}
client.goal = newGoal;
client.time = newGoal;
client.initialGoal = newGoal;
};

const addGoal = (client, msg) => {
Expand Down

0 comments on commit 29e9bb2

Please sign in to comment.