mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
notification stack added
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
23
frontend/src/layouts/NotificationStack.vue
Normal file
23
frontend/src/layouts/NotificationStack.vue
Normal 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>
|
||||
22
frontend/src/stores/notifications.ts
Normal file
22
frontend/src/stores/notifications.ts
Normal 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[];
|
||||
},
|
||||
},
|
||||
});
|
||||
2
frontend/src/types/emitter.d.ts
vendored
2
frontend/src/types/emitter.d.ts
vendored
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user