Skip to content

Commit

Permalink
feat: add ability to run 'actions' from alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
JSKitty committed Nov 19, 2024
1 parent 0497b07 commit 1ae3f39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/alerts/Alert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const icon = computed(() => {
</button>
<button v-if="actionName"
class="btn btn-notification-action notifyButtonSecond"
@click="$emit('hideAlert')"
@click="$emit('runAction')"
>
{{ actionName }}
</button>
Expand Down
12 changes: 12 additions & 0 deletions scripts/alerts/Alerts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ watch(alerts, () => {
show,
count,
actionName: previousAlert.actionName,
actionFunc: previousAlert.actionFunc,
// Store original message so we can use it as key.
// This skips the animation in case of multiple errors
original: previousAlert.message,
Expand All @@ -46,6 +47,16 @@ watch(alerts, () => {
pushAlert();
foldedAlerts.value = res;
});
/**
* Run an 'action' connected to an alert
* @param {import('./alert.js').Alert} cAlert - The caller alert which is running an action
*/
function runAction(cAlert) {
cAlert.actionFunc();
cAlert.show = false;
}
</script>
<template>
Expand All @@ -60,6 +71,7 @@ watch(alerts, () => {
:notificationCount="alert.value.count"
:actionName="alert.value.actionName"
@hideAlert="alert.value.show = false"
@runAction="runAction(alert.value)"
/>
</div>
</transition-group>
Expand Down

0 comments on commit 1ae3f39

Please sign in to comment.