Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for breaks when updating tray status #71

Merged
merged 5 commits into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions resources/scripts/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,37 +107,20 @@ function formatTime([minutes, seconds]: TimeRemaining) {

async function prepareForNextMember() {
const activeMember = getActiveMember(team);
const nextMember = whosNext(team);
startButtonText.value = `Start session for ${activeMember.name}`;
await updateTray(
activeMember.name,
nextMember.name,
formatTime(timeRemaining.value)
);
await updateTrayStatus();
}

async function onTick(timeLeft: TimeRemaining) {
updateTimeDisplay(timeLeft);
const { name } = getActiveMember(team);
const nextMember = whosNext(team);
await updateTray(name, nextMember.name, formatTime(timeLeft));
}

async function onBreakTick(timeLeft: TimeRemaining) {
updateTimeDisplay(timeLeft);
const nextMember = whosNext(team);
await updateTray("Break", nextMember.name, formatTime(timeLeft));
await updateTrayStatus();
}

async function onEnd() {
if (
takeBreaks.value &&
getLast(team).index == getActiveMember(team).index &&
!onBreak.value
) {
if (isBreakNext()) {
onBreak.value = true;
resetTimeDisplay();
timer.value = startTimer(intervalLength.value, onBreakTick, onEnd);
timer.value = startTimer(intervalLength.value, onTick, onEnd);

await showWindow();
} else {
Expand All @@ -147,6 +130,14 @@ async function onEnd() {
}
}

function isBreakNext() {
return (
takeBreaks.value &&
getLast(team).index == getActiveMember(team).index &&
!onBreak.value
);
}

function endBreak() {
onBreak.value = false;

Expand Down Expand Up @@ -227,8 +218,9 @@ function toggleMemberHere(selectedMemberIndex: number, isHere: boolean) {
}
}

function toggleBreaks(value: boolean) {
async function toggleBreaks(value: boolean) {
takeBreaks.value = value;
await updateTrayStatus();
}

async function updateTeamSize(newSize: number) {
Expand All @@ -240,6 +232,12 @@ async function randomizeTeamOrder() {
shuffleTeam(team);
await saveTeam(team.map(m => m.name));
}

async function updateTrayStatus() {
const now = onBreak.value ? "Break" : getActiveMember(team).name;
const next = isBreakNext() ? "Break" : whosNext(team).name;
await updateTray(now, next, formatTime(timeRemaining.value));
}
</script>

<style scoped>
Expand Down
Loading