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

feat: Automatic instruction timers #4467

Open
wants to merge 34 commits into
base: mealie-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f1bcf9c
Added inital commit for instructions timer
codetakki Oct 29, 2024
fa8765d
Added some better styling
codetakki Oct 29, 2024
066a4e4
Minutes being used as sec
codetakki Oct 29, 2024
0190664
Merge branch 'mealie-next' into feature-step-linked-timers
codetakki Oct 29, 2024
e4a0790
Regex for parsing string now includes locale strings, supporting mult…
codetakki Oct 29, 2024
169849d
Merge branch 'feature-step-linked-timers' of https://github.com/codet…
codetakki Oct 29, 2024
1fc82fb
Fixed some typing issues
codetakki Oct 30, 2024
8f3e357
Removed locals for all byt en-us
codetakki Oct 30, 2024
9005067
Moved code related to clock timer to composable
codetakki Nov 1, 2024
6a33194
instructions timer not uses use-timer composable
codetakki Nov 1, 2024
f5f19f2
Reset timer on unmount
codetakki Nov 1, 2024
9bd4e27
Removed unused import
codetakki Nov 1, 2024
757e72d
made timer icon more reactive to changes
codetakki Nov 1, 2024
ea8b311
Merge branch 'mealie-next' into feature-step-linked-timers
codetakki Nov 1, 2024
20ee5b2
Merge branch 'mealie-next' into feature-step-linked-timers
codetakki Nov 5, 2024
97e0c4e
added timers to recipe step
michael-genson Nov 5, 2024
4dfa6ab
added to schema
michael-genson Nov 5, 2024
6573114
move parser utils
michael-genson Nov 5, 2024
a61ffcc
add duration parser
michael-genson Nov 5, 2024
20c3752
added frontend schema defs
michael-genson Nov 5, 2024
65d3206
fix setter/init
michael-genson Nov 5, 2024
526430d
add parser to cleaner/scraper
michael-genson Nov 5, 2024
6edb885
added tests
michael-genson Nov 5, 2024
e90e623
lol
michael-genson Nov 5, 2024
e0584bd
lol
michael-genson Nov 5, 2024
dd6a6e8
Merge branch 'feature-step-linked-timers' of https://github.com/codet…
michael-genson Nov 5, 2024
24de141
Added edit for timers
codetakki Nov 8, 2024
216cd45
Changed some margins
codetakki Nov 8, 2024
aa74bdf
added timer parsing to migration using best-guess language
michael-genson Nov 10, 2024
8e463f1
Merge branch 'mealie-next' into feature-step-linked-timers
codetakki Nov 12, 2024
1fbf1e3
small margin adjustment
codetakki Nov 12, 2024
db88b71
FIxed merging error
codetakki Nov 12, 2024
b613bf4
Localized timer edit component
codetakki Nov 12, 2024
3169c9c
Merge branch 'mealie-next' into feature-step-linked-timers
codetakki Nov 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@
:markup="getIngredientByRefId(ing.referenceId)"
/>
</div>
<div>
<RecipePageInstructionsTimer :text="step.text"></RecipePageInstructionsTimer>
</div>
</v-card-text>
</div>
</v-expand-transition>
Expand All @@ -279,6 +282,7 @@ import {
nextTick,
} from "@nuxtjs/composition-api";
import RecipeIngredientHtml from "../../RecipeIngredientHtml.vue";
import RecipePageInstructionsTimer from "./RecipePageInstructionsTimer.vue";
import { RecipeStep, IngredientReferences, RecipeIngredient, RecipeAsset, Recipe } from "~/lib/api/types/recipe";
import { parseIngredientText } from "~/composables/recipes";
import { uuid4, detectServerBaseUrl } from "~/composables/use-utils";
Expand All @@ -300,6 +304,7 @@ export default defineComponent({
draggable,
RecipeIngredientHtml,
DropZone,
RecipePageInstructionsTimer,
},
props: {
value: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<template v-if="timers && timers.length">
<div @click.stop>

<v-divider class="mb-2"></v-divider>
<div
v-for="(timer, i) in timers"
:key="i"
class="d-flex align-center my-2 justify-center">
<v-icon :color="timer.done.value ? 'success' : ''" :class="timer.done.value ? 'shake' : ''">mdi-timer</v-icon>
<v-btn
icon
:disabled="timer.remainingTime.value <= 30"
depressed
@click="timer.remainingTime.value -= 30"><v-icon>mdi-minus</v-icon></v-btn>
{{ timer.hours.value ? timer.hours.value + "h" : "" }} {{ timer.minutes.value ? timer.minutes.value + "m" : "" }}
{{ (timer.seconds.value || !timer.minutes.value) ? timer.seconds.value + "s" : "" }}
<v-btn
icon
depressed
@click="timer.remainingTime.value += 30"><v-icon>mdi-plus</v-icon></v-btn>
<v-btn
v-if="!timer.isCounting.value && !timer.hasStarted.value"
rounded
depressed
@click="timer.startAlarm"> {{$t("recipe.timer.start")}} </v-btn>
<v-btn
v-else-if="(timer.hasStarted.value && timer.isCounting.value)"
rounded
depressed
@click="timer.pauseTimer"> {{$t("recipe.timer.pause")}} </v-btn>
</v-btn>
<span v-else-if="!timer.done.value">
<v-btn
rounded
depressed
@click="timer.startAlarm">
{{$t("recipe.timer.continue")}}
</v-btn>
<v-btn
icon
@click="timer.resetTimer"><v-icon>mdi-restore</v-icon></v-btn>
</span>
<span v-else>
<v-btn
icon
@click="timer.resetTimer"><v-icon>mdi-restore</v-icon></v-btn>
</span>
</div>
</div>
</template>
<script lang="ts">
import { computed, ref, onBeforeUnmount } from "vue";
import { useContext } from "@nuxtjs/composition-api";

import { TranslateResult } from "vue-i18n"
// @ts-ignore typescript can't find our audio file, but it's there!
import timerAlarmAudio from "~/assets/audio/kitchen_alarm.mp3";
export default {
props: {
text: {
type: String,
default: "",
},
},
setup(props) {
const { i18n } = useContext();
// Makes regex work with multiple languages via locales
const minuetStrings = computed<string[]>(() => {
console.log(i18n.availableLocales);
const result: TranslateResult[] = [];
i18n.availableLocales.forEach((locale) => {
result.push(i18n.t("recipe.timer.minute", locale ))
result.push(i18n.t("recipe.timer.minutes", locale ))
})
return result
})
michael-genson marked this conversation as resolved.
Show resolved Hide resolved

const extractMinutes = (text: string) => {
const regexMins = new RegExp(`\\b(\\d+)\\s*(${minuetStrings.value.join("|")})\\b`, "gi");
const matchesMin = text.matchAll(regexMins);
const timers = [];
for (const match of matchesMin) {
timers.push(createTimer(Number(match[1]) * 60));
}
return timers;
};
const timers = computed(() => {
return extractMinutes(props.text as string);
});

const createTimer = (totalSeconds: number) => {
codetakki marked this conversation as resolved.
Show resolved Hide resolved
const remainingTime = ref(totalSeconds);
const hours = computed(() => Math.floor(remainingTime.value / 3600));
const minutes = computed(() => Math.floor((remainingTime.value % 3600) / 60));
const seconds = computed(() => remainingTime.value % 60);
const isCounting = ref(false);
const hasStarted = ref(false)
const done = ref(false)

let timer = null;

const formattedTime = computed(() => {
const hrs = Math.floor(remainingTime.value / 3600);
const mins = Math.floor((remainingTime.value % 3600) / 60);
const secs = remainingTime.value % 60;
return `${hrs.toString().padStart(2, "0")}:${mins.toString().padStart(2, "0")}:${secs
.toString()
.padStart(2, "0")}`;
});

const startAlarm = () => {
if (remainingTime.value > 0) {
isCounting.value = true;
timer = setInterval(updateTimer, 1000);
hasStarted.value = true
}
};

// ts doesn't recognize timerAlarmAudio because it's a weird import
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const alarmSound = new Audio(timerAlarmAudio);
alarmSound.loop = true;
const updateTimer = () => {
if (remainingTime.value >= 1) {
remainingTime.value--;
} else {
pauseTimer();
alarmSound.play();
done.value = true;
}
};

const pauseTimer = () => {
isCounting.value = false;
clearInterval(timer);

Check failure on line 135 in frontend/components/Domain/Recipe/RecipePage/RecipePageParts/RecipePageInstructionsTimer.vue

View workflow job for this annotation

GitHub Actions / Frontend and End-to-End Tests / lint

Unsafe argument of type `any` assigned to a parameter of type `string | number | Timeout | undefined`
alarmSound.pause();
};

const resetTimer = () => {
clearInterval(timer);

Check failure on line 140 in frontend/components/Domain/Recipe/RecipePage/RecipePageParts/RecipePageInstructionsTimer.vue

View workflow job for this annotation

GitHub Actions / Frontend and End-to-End Tests / lint

Unsafe argument of type `any` assigned to a parameter of type `string | number | Timeout | undefined`
remainingTime.value = totalSeconds;
isCounting.value = false;
hasStarted.value = false;
done.value = false;
alarmSound.pause();
};

onBeforeUnmount(() => {
resetTimer();
});
return {
hours,
minutes,
seconds,
remainingTime,
isCounting,
formattedTime,
startAlarm,
resetTimer,
pauseTimer,
originalTimer: totalSeconds,
hasStarted,
done
};
};

return {
timers,
};
},
};
</script>
<style scoped>
.shake {
animation: shake 0.82s cubic-bezier(0.36, 0.07, 0.19, 0.97) infinite;
}
@keyframes shake {
10%, 90% {
transform: translate3d(-1px, 0, 0);
}
20%, 80% {
transform: translate3d(2px, 0, 0);
}
30%, 50%, 70% {
transform: translate3d(-4px, 0, 0);
}
40%, 60% {
transform: translate3d(4px, 0, 0);
}
}
</style>
7 changes: 6 additions & 1 deletion frontend/lang/messages/af-ZA.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Begin die kombuis timer",
"pause-timer": "Onderbreek die kombuis timer",
"resume-timer": "Hervat kombuis timer",
"stop-timer": "Stop die kombuis timer"
"stop-timer": "Stop die kombuis timer",
"continue": "Gaan voort",
"pause": "Pouse",
"start": "Begin timer",
"minutes": "minute",
"minute": "minuut"
},
"edit-timeline-event": "Wysig tydlyn gebeurtenis",
"timeline": "Tydlyn",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/ar-SA.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Start Timer",
"pause-timer": "Pause Timer",
"resume-timer": "Resume Timer",
"stop-timer": "Stop Timer"
"stop-timer": "Stop Timer",
"continue": "يكمل",
"pause": "يوقف",
"start": "بدء الموقت",
"minutes": "دقائق",
"minute": "دقيقة"
},
"edit-timeline-event": "Edit Timeline Event",
"timeline": "Timeline",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/bg-BG.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Стартирай таймера",
"pause-timer": "Поставяне таймера на пауза",
"resume-timer": "Възобновяване на таймера",
"stop-timer": "Спри таймера"
"stop-timer": "Спри таймера",
"continue": "Продължи",
"pause": "Пауза",
"start": "Стартирайте таймера",
"minutes": "минути",
"minute": "минута"
},
"edit-timeline-event": "Редактирай събитие",
"timeline": "Хронология на събитията",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/ca-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Iniciar temporitzador",
"pause-timer": "Pausa el temporitzador",
"resume-timer": "Reprèn el temporitzador",
"stop-timer": "Atura el temporitzador"
"stop-timer": "Atura el temporitzador",
"continue": "Continua",
"pause": "Pausa",
"start": "Inicieu el temporitzador",
"minutes": "minuts",
"minute": "minut"
},
"edit-timeline-event": "Edita l'esdeveniment de la cronologia",
"timeline": "Cronologia",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/cs-CZ.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Spustit časovač",
"pause-timer": "Pozastavit časovač",
"resume-timer": "Resume Timer",
"stop-timer": "Stop Timer"
"stop-timer": "Stop Timer",
"continue": "Pokračovat",
"pause": "Pauza",
"start": "Spustit časovač",
"minutes": "zápis",
"minute": "minuta"
},
"edit-timeline-event": "Upravit událost časové osy",
"timeline": "Časová osa",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/da-DK.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Start timer",
"pause-timer": "Sæt timer på pause",
"resume-timer": "Genoptag Timer",
"stop-timer": "Stop timer"
"stop-timer": "Stop timer",
"continue": "Fortsætte",
"pause": "Pause",
"start": "Start timer",
"minutes": "minutter",
"minute": "minut"
},
"edit-timeline-event": "Rediger tidslinjebegivenhed",
"timeline": "Tidslinje",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Wecker starten",
"pause-timer": "Wecker pausieren",
"resume-timer": "Wecker fortsetzen",
"stop-timer": "Wecker stoppen"
"stop-timer": "Wecker stoppen",
"continue": "Weitermachen",
"pause": "Pause",
"start": "Timer starten",
"minutes": "Minuten",
"minute": "Minute"
},
"edit-timeline-event": "Zeitstrahl-Ereignis bearbeiten",
"timeline": "Zeitstrahl",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/el-GR.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Εναρξη χρονομέτρου",
"pause-timer": "Παύση χρονόμετρου",
"resume-timer": "Συνέχιση χρονομέτρου",
"stop-timer": "Διακοπή χρονόμετρου"
"stop-timer": "Διακοπή χρονόμετρου",
"continue": "Συνεχίζω",
"pause": "Παύση",
"start": "Έναρξη χρονοδιακόπτη",
"minutes": "πρακτικά",
"minute": "λεπτό"
},
"edit-timeline-event": "Επεξεργασία συμβάντος χρονοδιαγράμματος",
"timeline": "Χρονοδιάγραμμα",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Start Timer",
"pause-timer": "Pause Timer",
"resume-timer": "Resume Timer",
"stop-timer": "Stop Timer"
"stop-timer": "Stop Timer",
"continue": "Continue",
"pause": "Pause",
"start": "Start timer",
"minutes": "minutes",
"minute": "minute"
},
"edit-timeline-event": "Edit Timeline Event",
"timeline": "Timeline",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Start Timer",
"pause-timer": "Pause Timer",
"resume-timer": "Resume Timer",
"stop-timer": "Stop Timer"
"stop-timer": "Stop Timer",
"pause": "Pause",
"start": "Start timer",
"continue": "Continue",
"minute": "minute",
"minutes": "minutes"
},
"edit-timeline-event": "Edit Timeline Event",
"timeline": "Timeline",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Iniciar Temporizador",
"pause-timer": "Pausar Temporizador",
"resume-timer": "Reanudar Temporizador",
"stop-timer": "Detener temporizador"
"stop-timer": "Detener temporizador",
"continue": "Continuar",
"pause": "Pausa",
"start": "Iniciar temporizador",
"minutes": "minutos",
"minute": "minuto"
},
"edit-timeline-event": "Editar evento en la cronología",
"timeline": "Cronología",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/fi-FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Käynnistä ajastin",
"pause-timer": "Keskeytä ajastin",
"resume-timer": "Jatka ajastusta",
"stop-timer": "Pysäytä ajastin"
"stop-timer": "Pysäytä ajastin",
"continue": "Jatkaa",
"pause": "Tauko",
"start": "Käynnistä ajastin",
"minutes": "minuuttia",
"minute": "minuutti"
},
"edit-timeline-event": "Muokkaa Aikajanan Tapahtumaa",
"timeline": "Aikajana",
Expand Down
7 changes: 6 additions & 1 deletion frontend/lang/messages/fr-BE.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,12 @@
"start-timer": "Démarrer le minuteur",
"pause-timer": "Mettre en pause le minuteur",
"resume-timer": "Reprendre le minuteur",
"stop-timer": "Arrêter le minuteur"
"stop-timer": "Arrêter le minuteur",
"continue": "Continuer",
"pause": "Pause",
"start": "Démarrer la minuterie",
"minutes": "minutes",
"minute": "minute"
},
"edit-timeline-event": "Modifier l’événement dans l’historique",
"timeline": "Historique",
Expand Down
Loading
Loading