-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added password change notification
- Loading branch information
Showing
5 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script lang="ts" setup> | ||
import { useNotificationEngine } from '@/stores/useNotificationEngine' | ||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' | ||
import { faCheckCircle, faX } from '@fortawesome/free-solid-svg-icons' | ||
const notificationEngine = useNotificationEngine() | ||
notificationEngine.$onAction(({ name, after }) => { | ||
if (name == 'add') { | ||
after((id) => { | ||
setTimeout(() => { | ||
notificationEngine.remove(id) | ||
}, 5000) | ||
}) | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-col items-end space-y-4 p-4"> | ||
<div v-for="[id, notification] in notificationEngine.notifications" :key="id"> | ||
<div class="flex items-start gap-x-4 rounded-lg bg-white p-4 shadow-lg dark:bg-gray-800"> | ||
<div | ||
class="h-10 w-10 shrink-0 rounded-full bg-green-100 py-2.5 text-green-700 dark:bg-green-800 dark:text-green-100" | ||
> | ||
<FontAwesomeIcon :icon="faCheckCircle" class="h-full w-full" /> | ||
</div> | ||
<div class="space-y-1"> | ||
<h3 class="text-sm">{{ $t(notification.title) }}</h3> | ||
<small class="text-gray-500 dark:text-gray-400">{{ $t(notification.description) }}</small> | ||
</div> | ||
<button class="h-3.5 w-3.5 shrink-0" @click="notificationEngine.remove(id)"> | ||
<FontAwesomeIcon :icon="faX" class="h-full w-full" /> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { defineStore } from 'pinia' | ||
import { ref } from 'vue' | ||
|
||
type NotificationType = 'success' | ||
|
||
interface Notification { | ||
type: NotificationType | ||
title: string | ||
description: string | ||
} | ||
|
||
export const useNotificationEngine = defineStore('notifications', () => { | ||
const notifications = ref(new Map<number, Notification>()) | ||
const id = ref(0) | ||
|
||
/** | ||
* Add a new notification, returns the id of the notification | ||
* @param type | ||
* @param title | ||
* @param description | ||
*/ | ||
function add(type: NotificationType, title: string, description: string): number { | ||
id.value++ | ||
notifications.value.set(id.value, { type, title, description }) | ||
return id.value | ||
} | ||
|
||
function remove(id: number) { | ||
notifications.value.delete(id) | ||
} | ||
|
||
return { notifications, add, remove } | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters