Add long press button for actions

This commit is contained in:
2024-12-20 16:36:29 +00:00
parent 215be2d5f0
commit 2b52a15f96
5 changed files with 88 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ declare module 'vue' {
DashboardItem: typeof import('./src/components/DashboardItem.vue')['default']
Indoor: typeof import('./src/components/Indoor.vue')['default']
IndoorSummary: typeof import('./src/components/IndoorSummary.vue')['default']
LongPressButton: typeof import('./src/components/LongPressButton.vue')['default']
NationalDays: typeof import('./src/components/NationalDays.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']

View File

@@ -4,5 +4,4 @@ sed -i -e "s~#API_PREFIX#~$API_PREFIX~g" /usr/share/nginx/html/assets/*
sed -i -e "s~#HOME_ASSISTANT_URL#~$HOME_ASSISTANT_URL~g" /usr/share/nginx/html/assets/*
sed -i -e "s~#HOME_ASSISTANT_TOKEN#~$HOME_ASSISTANT_TOKEN~g" /usr/share/nginx/html/assets/*
sed -i -e "s~#GARAGE_DEVICE#~$GARAGE_DEVICE~g" /usr/share/nginx/html/assets/*
sed -i -e "s~#ALARM_DEVICE#~$ALARM_DEVICE~g" /usr/share/nginx/html/assets/*
sed -i -e "s~#CALENDAR_EMBED_URL#~$CALENDAR_EMBED_URL~g" /usr/share/nginx/html/assets/*
sed -i -e "s~#ALARM_DEVICE#~$ALARM_DEVICE~g" /usr/share/nginx/html/assets/*

View File

@@ -0,0 +1,79 @@
<script lang="ts" setup>
import { ref } from 'vue';
const emit = defineEmits(['longPress']);
const props = defineProps(['duration', 'increment', 'progressSize']);
const current = ref(0 as number);
const loading = ref(false);
let interval: NodeJS.Timeout;
function mousedown() {
loading.value = true;
increment();
interval = setInterval(increment, props.increment);
}
function mouseup() {
reset();
}
function reset() {
clearInterval(interval);
loading.value = false;
current.value = 0;
}
function increment() {
current.value = current.value + props.increment;
if (current.value >= props.duration) {
emit('longPress');
reset();
}
}
function progress() {
if (current.value >= props.duration) {
return 100;
}
return (current.value / props.duration) * 100;
}
</script>
<template>
<button
:class="{ 'loading-button': loading }"
@mousedown="mousedown"
@mouseup="mouseup">
<span v-show="!loading">
<slot name="default"></slot>
</span>
<v-progress-circular
v-if="loading"
:size="props.progressSize"
:model-value="progress()"></v-progress-circular>
</button>
</template>
<style scoped>
.loading-button {
display: inline-flex;
flex-direction: column;
align-items: center;
}
</style>
<style>
.v-progress-circular__underlay {
stroke: #ebebeb !important;
z-index: 1;
}
</style>

View File

@@ -18,8 +18,4 @@ export default class Environment {
public static getAlarmDevice(): string {
return '#ALARM_DEVICE#';
}
public static getCalendarEmbedUrl(): string {
return '#CALENDAR_EMBED_URL#';
}
}

View File

@@ -5,6 +5,7 @@
import { usePowerStore } from '@/stores/powerStore';
import { useHomeAssistantStore } from '@/stores/homeAssistantStore';
import CalendarAgenda from '@/components/CalendarAgenda.vue';
import LongPressButton from '@/components/LongPressButton.vue';
const weatherStore = useWeatherStore();
weatherStore.start();
@@ -104,10 +105,13 @@
{{ laundryStore.current.dryer ? 'On' : 'Off' }}
</div>
</div>
<div
<LongPressButton
class="kiosk-garage-door text-center pt-4"
v-if="homeAssistantStore?.garageState"
v-on:click="homeAssistantStore.toggleGarage()"
:duration="2000"
:increment="100"
:progress-size="38"
v-on:longPress="homeAssistantStore.toggleGarage()"
:class="homeAssistantStore.garageState === 'closed' ? 'normal' : 'warning'">
<v-icon
class="kiosk-device-icon"
@@ -115,7 +119,7 @@
<div class="kiosk-device-text">
{{ capitalize(homeAssistantStore.garageState) }}
</div>
</div>
</LongPressButton>
<div
class="kiosk-house-alarm text-center pt-4"
v-if="homeAssistantStore?.houseAlarmState"