Skip to content

Commit

Permalink
feat: Shopping list UI overhaul - add wakelock (#4236)
Browse files Browse the repository at this point in the history
Co-authored-by: Kuchenpirat <[email protected]>
  • Loading branch information
Wetzel402 and Kuchenpirat authored Sep 28, 2024
1 parent 8fe1b0c commit 28b0190
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 47 deletions.
49 changes: 2 additions & 47 deletions frontend/components/Domain/Recipe/RecipePage/RecipePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@
<RecipePageFooter :recipe="recipe" />
</v-card-text>
</v-card>

<div
v-if="recipe && wakeIsSupported"
class="d-print-none d-flex px-2"
:class="$vuetify.breakpoint.smAndDown ? 'justify-center' : 'justify-end'"
>
<v-switch v-model="wakeLock" small :label="$t('recipe.screen-awake')" />
</div>

<WakelockSwitch/>
<RecipePageComments
v-if="!recipe.settings.disableComments && !isEditForm && !isCookMode"
:recipe="recipe"
Expand All @@ -91,7 +83,7 @@ import {
onUnmounted,
useRoute,
} from "@nuxtjs/composition-api";
import { invoke, until, useWakeLock } from "@vueuse/core";
import { invoke, until } from "@vueuse/core";
import RecipePageEditorToolbar from "./RecipePageParts/RecipePageEditorToolbar.vue";
import RecipePageFooter from "./RecipePageParts/RecipePageFooter.vue";
import RecipePageHeader from "./RecipePageParts/RecipePageHeader.vue";
Expand Down Expand Up @@ -194,40 +186,6 @@ export default defineComponent({
}
});
/** =============================================================
* Wake Lock
*/
const { isSupported: wakeIsSupported, isActive, request, release } = useWakeLock();
const wakeLock = computed({
get: () => isActive,
set: () => {
if (isActive.value) {
unlockScreen();
} else {
lockScreen();
}
},
});
async function lockScreen() {
if (wakeIsSupported) {
console.log("Wake Lock Requested");
await request("screen");
}
}
async function unlockScreen() {
if (wakeIsSupported || isActive) {
console.log("Wake Lock Released");
await release();
}
}
onMounted(() => lockScreen());
onUnmounted(() => unlockScreen());
/** =============================================================
* Recipe Save Delete
*/
Expand Down Expand Up @@ -308,9 +266,6 @@ export default defineComponent({
isEditJSON,
isCookMode,
toggleCookMode,
wakeLock,
wakeIsSupported,
saveRecipe,
deleteRecipe,
addStep,
Expand Down
49 changes: 49 additions & 0 deletions frontend/components/global/WakelockSwitch.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div
v-if="wakeIsSupported"
class="d-print-none d-flex px-2"
:class="$vuetify.breakpoint.smAndDown ? 'justify-center' : 'justify-end'"
>
<v-switch v-model="wakeLock" small :label="$t('recipe.screen-awake')" />
</div>
</template>

<script lang="ts">
import { defineComponent, computed, onMounted, onUnmounted } from "@nuxtjs/composition-api";
import { useWakeLock } from "@vueuse/core";
export default defineComponent({
setup() {
const { isSupported: wakeIsSupported, isActive, request, release } = useWakeLock();
const wakeLock = computed({
get: () => isActive,
set: () => {
if (isActive.value) {
unlockScreen();
} else {
lockScreen();
}
},
});
async function lockScreen() {
if (wakeIsSupported) {
console.log("Wake Lock Requested");
await request("screen");
}
}
async function unlockScreen() {
if (wakeIsSupported || isActive) {
console.log("Wake Lock Released");
await release();
}
}
onMounted(() => lockScreen());
onUnmounted(() => unlockScreen());
return {
wakeLock,
wakeIsSupported,
};
},
});
</script>
1 change: 1 addition & 0 deletions frontend/pages/shopping-lists/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
/>
</div>
</v-lazy>
<WakelockSwitch/>
</v-container>
</template>

Expand Down

0 comments on commit 28b0190

Please sign in to comment.