notification stack added

This commit is contained in:
zurdi
2024-06-03 22:23:16 +02:00
parent 68f14e0f75
commit 99b49c80b8
6 changed files with 82 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
<script setup lang="ts">
import NotificationStack from "@/layouts/NotificationStack.vue";
import Notification from "@/components/Notification.vue";
import api from "@/services/api/index";
import platformApi from "@/services/api/platform";
@@ -16,9 +17,12 @@ import { normalizeString } from "@/utils";
import type { Emitter } from "mitt";
import { storeToRefs } from "pinia";
import { inject, onBeforeUnmount, onMounted } from "vue";
import storeNotifications from "@/stores/notifications";
// Props
const scanningStore = storeScanning();
const notificationStore = storeNotifications();
const { notifications } = storeToRefs(notificationStore);
const { scanningPlatforms } = storeToRefs(scanningStore);
const romsStore = storeRoms();
const galleryFilter = storeGalleryFilter();
@@ -126,12 +130,25 @@ onMounted(() => {
console.error(error);
});
});
</script>
<template>
<v-app>
<v-main>
<notification class="mt-6" />
<!-- <notification /> -->
<notification-stack />
<v-btn
@click="
emitter?.emit('snackbarShow', {
msg: 'test notification'+notifications.length,
icon: 'mdi-check-bold',
color: 'green',
})
"
>Add</v-btn
>
<router-view />
</v-main>
</v-app>

View File

@@ -1,29 +1,36 @@
<script setup lang="ts">
import type { Events, SnackbarStatus } from "@/types/emitter";
import type { Emitter } from "mitt";
import storeNotifications from "@/stores/notifications";
import { inject, ref } from "vue";
// Props
const show = ref(false);
const snackbarStatus = ref<SnackbarStatus>({ msg: "" });
const notificationStore = storeNotifications();
// Event listeners bus
const emitter = inject<Emitter<Events>>("emitter");
emitter?.on("snackbarShow", (snackbar: SnackbarStatus) => {
show.value = true;
snackbarStatus.value = snackbar;
snackbarStatus.value.id = notificationStore.notifications.length + 1;
// notificationStore.add(snackbarStatus.value);
});
function closeDialog() {
notificationStore.remove(snackbarStatus.value.id);
show.value = false;
}
</script>
<template>
<v-snackbar
transition="scroll-y-transition"
v-model="show"
:timeout="snackbarStatus.timeout ? snackbarStatus.timeout : 2000"
location="top"
:timeout="snackbarStatus.timeout ? snackbarStatus.timeout : 3000"
@timeout="closeDialog"
location="top right"
color="tooltip"
>
<v-icon

View File

@@ -9,7 +9,7 @@ import { useTheme } from "vuetify";
const theme = useTheme();
const storedTheme = parseInt(localStorage.getItem("settings.theme") ?? "");
const selectedTheme = ref(isNaN(storedTheme) ? autoThemeKey : storedTheme);
const options = computed(() => [
const themeOptions = computed(() => [
{
name: "dark",
icon: "mdi-moon-waning-crescent",
@@ -45,7 +45,13 @@ function toggleTheme() {
@update:model-value="toggleTheme"
>
<v-row no-gutters>
<v-col cols="4" sm="3" md="2" class="pa-1" v-for="theme in options">
<v-col
cols="4"
sm="3"
md="2"
class="pa-1"
v-for="theme in themeOptions"
>
<theme-option
:key="theme.name"
:text="theme.name"

View File

@@ -0,0 +1,23 @@
<script setup lang="ts">
import Notification from "@/components/Notification.vue";
import storeNotifications from "@/stores/notifications";
import type { SnackbarStatus } from "@/types/emitter";
import type { Emitter } from "mitt";
import { storeToRefs } from "pinia";
import type { Events } from "@/types/emitter";
import { inject } from "vue";
const notificationStore = storeNotifications();
const { notifications } = storeToRefs(notificationStore);
const emitter = inject<Emitter<Events>>("emitter");
emitter?.on("snackbarShow", (snackbar: SnackbarStatus) => {
snackbar.id = notificationStore.notifications.length + 1;
notificationStore.add(snackbar);
});
</script>
<template>
<notification
v-for="notification in notifications"
:style="{ 'margin-top': `${(notifications.indexOf(notification)+1) * 60}px` }"
/>
</template>
<style scoped></style>

View File

@@ -0,0 +1,22 @@
import type { SnackbarStatus } from "@/types/emitter";
import { defineStore } from "pinia";
export default defineStore("notifications", {
state: () => ({
notifications: [] as SnackbarStatus[],
}),
actions: {
add(notification: SnackbarStatus) {
this.notifications.push(notification);
},
remove(id: number | undefined) {
this.notifications = this.notifications.filter(
(notification) => notification.id !== id
);
},
clear() {
this.notifications = [] as SnackbarStatus[];
},
},
});

View File

@@ -2,6 +2,7 @@ import type { SaveSchema, SearchRomSchema, StateSchema } from "@/__generated__";
import type { Platform } from "@/stores/platforms";
import type { SimpleRom } from "@/stores/roms";
import type { User } from "@/stores/users";
import type internal from "stream";
export type UserItem = User & {
password: string;
@@ -9,6 +10,7 @@ export type UserItem = User & {
};
export type SnackbarStatus = {
id?: number;
msg: string;
timeout?: number;
icon?: string;