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

#68 Added wakelock to recipe detail page #93

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
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
97 changes: 96 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@fortawesome/free-solid-svg-icons": "^6.4.0",
"@fortawesome/vue-fontawesome": "^3.0.3",
"@inertiajs/vue3": "^1.0.0",
"@vueuse/core": "^10.11.0",
"dayjs": "^1.11.9",
"vue-advanced-cropper": "^2.8.8"
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Components/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const props = defineProps({
'bg-blue-600 hover:bg-blue-500 active:bg-blue-700': buttonStyle === 'info',
'bg-white hover:bg-blue-500 active:bg-blue-700': buttonStyle === 'info',
'text-white hover:text-white': buttonStyle !== 'ghost',
'bg-white text-gray-500 hover:bg-gray-100 hover:text-gray-700': buttonStyle === 'ghost',
'bg-transparent text-gray-500 hover:bg-gray-100 hover:text-gray-700': buttonStyle === 'ghost',
}"
>
<slot />
Expand Down
105 changes: 77 additions & 28 deletions resources/js/Pages/Recipes/Show.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script setup>
import { faEllipsisV } from "@fortawesome/free-solid-svg-icons";
import { faEllipsisV, faMoon, faSun } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { Head, router } from "@inertiajs/vue3";
import { computed } from "vue";
import { useWakeLock } from "@vueuse/core";
import { computed, reactive } from "vue";
import Button from "@/Components/Button.vue";
import Dropdown from "@/Components/Dropdown.vue";
import DropdownLink from "@/Components/DropdownLink.vue";
Expand Down Expand Up @@ -42,6 +43,25 @@ function confirmDeletion() {
});
}
}

const wakeLock = reactive(useWakeLock());
const wakeLockButtonIcon = computed(() => (wakeLock.isActive ? faMoon : faSun));
const wakeLockButtonTitle = computed(() =>
wakeLock.isActive ? "Scherm automatisch dimmer volgens systeem instellingen" : "Scherm niet automatisch dimmen"
);

function toggleWakeLock() {
return wakeLock.isActive ? wakeLock.release() : wakeLock.request("screen");
}

const strikedIngredients = reactive(new Set());
const toggleStrike = (ingredient) => {
if (strikedIngredients.has(ingredient)) {
strikedIngredients.delete(ingredient);
} else {
strikedIngredients.add(ingredient);
}
};
</script>

<template>
Expand All @@ -52,18 +72,30 @@ function confirmDeletion() {
<div class="overflow-hidden bg-white sm:rounded-lg sm:shadow-lg">
<div class="m-6 space-y-6 md:space-y-10 lg:m-10">
<div>
<Dropdown v-if="$page.props.auth.user" align="right" width="48" class="float-right">
<template #trigger>
<Button button-style="ghost" aria-label="Uitklapmenu voor acties op recept" class="w-10 !p-2.5">
<FontAwesomeIcon :icon="faEllipsisV" class="mx-auto" />
</Button>
</template>

<template #content>
<DropdownLink :href="route('recipes.edit', recipe.id)">Recept bewerken</DropdownLink>
<DropdownLink href="#" @click="confirmDeletion">Verwijder</DropdownLink>
</template>
</Dropdown>
<div class="float-right flex gap-2">
<Button
v-if="wakeLock.isSupported"
button-style="ghost"
aria-label="Uitklapmenu voor acties op recept"
class="w-10 !p-2.5"
:title="wakeLockButtonTitle"
@click="toggleWakeLock"
>
<FontAwesomeIcon :icon="wakeLockButtonIcon" class="mx-auto" />
</Button>
<Dropdown v-if="$page.props.auth.user" align="right" width="48">
<template #trigger>
<Button button-style="ghost" aria-label="Uitklapmenu voor acties op recept" class="w-10 !p-2.5">
<FontAwesomeIcon :icon="faEllipsisV" class="mx-auto" />
</Button>
</template>

<template #content>
<DropdownLink :href="route('recipes.edit', recipe.id)">Recept bewerken</DropdownLink>
<DropdownLink href="#" @click="confirmDeletion">Verwijder</DropdownLink>
</template>
</Dropdown>
</div>

<h1 class="mb-4 text-2xl font-bold md:text-3xl">{{ recipe.title }}</h1>

Expand Down Expand Up @@ -191,23 +223,40 @@ function confirmDeletion() {

<div class="space-y-6">
<div v-for="list in recipe.ingredients">
<button
v-if="strikedIngredients.size > 0"
class="float-right text-sm"
@click="() => strikedIngredients.clear()"
>
reset
</button>
<h3 v-if="list.title" class="mb-2 mt-8 text-lg font-bold">{{ list.title }}</h3>

<ul class="m-0 space-y-1">
<li v-for="ingredient in list.ingredients" class="flex flex-auto">
<template v-if="ingredient.amount">
<!-- The span is a trick to prevent extra whitspace between the amount and the following text. -->
<!-- Multiplying and deviding the amount is a trick to round to 2 decimal places. -->
<span>{{ Math.round(ingredient.amount * 100) / 100 }}&nbsp;</span>
</template>
<template v-if="ingredient.unit">{{ ingredient.unit }}&nbsp;</template>
<template v-if="ingredient.name_plural && ingredient.amount > 1">
{{ ingredient.name_plural }}
</template>
<template v-else>
{{ ingredient.name }}
</template>
<template v-if="ingredient.info">{{ ingredient.info }}</template>
<li
v-for="(ingredient, id) in list.ingredients"
:key="`${ingredient.name}-${id}`"
class="flex flex-auto"
>
<span
class="cursor-pointer"
:class="{ 'text-gray-600 line-through': strikedIngredients.has(ingredient) }"
@click="toggleStrike(ingredient)"
>
<template v-if="ingredient.amount">
<!-- The span is a trick to prevent extra whitspace between the amount and the following text. -->
<!-- Multiplying and deviding the amount is a trick to round to 2 decimal places. -->
<span>{{ Math.round(ingredient.amount * 100) / 100 }}&nbsp;</span>
</template>
<template v-if="ingredient.unit">{{ ingredient.unit }}&nbsp;</template>
<template v-if="ingredient.name_plural && ingredient.amount > 1">
{{ ingredient.name_plural }}
</template>
<template v-else>
{{ ingredient.name }}
</template>
<template v-if="ingredient.info">{{ ingredient.info }}</template>
</span>
</li>
</ul>
</div>
Expand Down