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: Shopping list UI overhaul - add wakelock #4236

Merged
merged 10 commits into from
Sep 28, 2024
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
47 changes: 47 additions & 0 deletions frontend/components/global/WakelockSwitch.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<div v-if="wakeIsSupported" class="d-print-none d-flex px-2"

Check warning on line 2 in frontend/components/global/WakelockSwitch.vue

View workflow job for this annotation

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

Expected a linebreak before this attribute
: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 } from "@nuxtjs/composition-api";

Check warning on line 9 in frontend/components/global/WakelockSwitch.vue

View workflow job for this annotation

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

'/home/runner/work/mealie/mealie/frontend/node_modules/@nuxtjs/composition-api/dist/runtime/index.mjs' imported multiple times
import { computed, onMounted, onUnmounted } from "@nuxtjs/composition-api";

Check warning on line 10 in frontend/components/global/WakelockSwitch.vue

View workflow job for this annotation

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

'/home/runner/work/mealie/mealie/frontend/node_modules/@nuxtjs/composition-api/dist/runtime/index.mjs' imported multiple times
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 @@ -282,6 +282,7 @@
/>
</div>
</v-lazy>
<WakelockSwitch/>
</v-container>
</template>

Expand Down
Loading