diff --git a/src/lib/Modal/CalendarModal.svelte b/src/lib/Modal/CalendarModal.svelte index b54ef792..85f7e86d 100644 --- a/src/lib/Modal/CalendarModal.svelte +++ b/src/lib/Modal/CalendarModal.svelte @@ -63,12 +63,19 @@ end: 'listDay,listWeek,listMonth,listYear, dayGridMonth' }, + // custom update button + customButtons: { + update: { + text: $lang('update'), + click: handleClick + } + }, + // locale locale: $selectedLanguage, noEventsContent: '', buttonText: { today: $lang('today'), - update: $lang('update'), listDay: $lang('day'), listWeek: $lang('week'), listMonth: $lang('month'), @@ -135,36 +142,34 @@ // custom update button async function handleClick(event: any) { + if (busy) return; + busy = true; + const target = event?.target; - if (target?.classList?.contains('ec-update')) { - event.stopPropagation(); - const setStyle = (data: boolean) => { - target.style.opacity = data ? '0.3' : 'unset'; - target.style.cursor = data ? 'default' : 'pointer'; - }; - - if (busy) return; - busy = true; - setStyle(true); - - try { - await $connection.sendMessagePromise({ - type: 'call_service', - domain: 'homeassistant', - service: 'update_entity', - target: { entity_id } - }); - } catch (err) { - console.error(err); - } finally { - ec?.refetchEvents(); - - timeout = setTimeout(() => { - setStyle(false); - busy = false; - }, 500); - } + const setStyle = (data: boolean) => { + target.style.opacity = data ? '0.3' : 'unset'; + target.style.cursor = data ? 'default' : 'pointer'; + }; + + setStyle(true); + + try { + await $connection.sendMessagePromise({ + type: 'call_service', + domain: 'homeassistant', + service: 'update_entity', + target: { entity_id } + }); + } catch (err) { + console.error(err); + } finally { + ec?.refetchEvents(); + + timeout = setTimeout(() => { + setStyle(false); + busy = false; + }, 500); } } @@ -175,8 +180,6 @@ }); - - {#if isOpen}

{getName(sel, entity)}