Skip to content

Commit

Permalink
Merge pull request #455 from matt8707/calendar
Browse files Browse the repository at this point in the history
Simplify calendar custom update button
  • Loading branch information
matt8707 authored May 11, 2024
2 parents a74a42f + 2eda4f1 commit 7931768
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions src/lib/Modal/CalendarModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -175,8 +180,6 @@
});
</script>

<svelte:document on:click|capture={handleClick} />

{#if isOpen}
<Modal size="large">
<h1 slot="title">{getName(sel, entity)}</h1>
Expand Down

0 comments on commit 7931768

Please sign in to comment.