Outsourced notify funtionality into utils file

This commit is contained in:
joschuatonn
2024-05-30 09:17:40 +02:00
parent d12ca80375
commit d3b2eaa32a
2 changed files with 25 additions and 27 deletions

View File

@@ -67,7 +67,8 @@
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import ProfileCardComponent from './ProfileCardComponent.vue'; import ProfileCardComponent from './ProfileCardComponent.vue';
import { useUserStore } from 'src/stores/user-store'; import { useUserStore } from 'src/stores/user-store';
import type { ptpUser } from 'src/models'; import type { ptpUser, responseModel } from 'src/models';
import {sendNotification} from 'src/utils';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { useChatStore } from 'src/stores/chat-store'; import { useChatStore } from 'src/stores/chat-store';
@@ -79,8 +80,6 @@ import { useChatStore } from 'src/stores/chat-store';
const searchResults = ref([] as ptpUser[]); const searchResults = ref([] as ptpUser[]);
const $q = useQuasar();
const emit = defineEmits(['update:showDialog', 'showModal']); const emit = defineEmits(['update:showDialog', 'showModal']);
const props = defineProps({ const props = defineProps({
showDialog: Boolean, showDialog: Boolean,
@@ -117,36 +116,16 @@ import { useChatStore } from 'src/stores/chat-store';
let errorOccured = false; let errorOccured = false;
if(usersForChat.value.length == 0) { if(usersForChat.value.length == 0) {
$q.notify({ sendNotification("Du hast keine Mitglieder ausgewählt", false);
message: 'Du hast keine Mitglieder ausgewählt',
position: 'top',
timeout: 2000,
color: "red",
icon: 'warning'
});
errorOccured = true; errorOccured = true;
} }
if(chatName.value == "") { if(chatName.value == "") {
$q.notify({ sendNotification("Du hast keinen Namen festgelegt", false);
message: 'Du hast keinen Namen festgelegt',
position: 'top',
timeout: 2000,
color: "red",
icon: 'warning'
});
errorOccured = true; errorOccured = true;
} }
if(!errorOccured) { if(!errorOccured) {
$q.notify({
message: 'Der Chat "'+chatName.value+'" wurde erstellt',
position: 'top',
timeout: 2000,
color: "green",
type: "positive"
});
setupChat(chatName.value); setupChat(chatName.value);
closeDialog(); closeDialog();
chatName.value = ""; chatName.value = "";
@@ -157,8 +136,11 @@ import { useChatStore } from 'src/stores/chat-store';
const chatStore = useChatStore(); const chatStore = useChatStore();
const setupChat = async(chatName: string)=>{ const setupChat = async(chatName: string)=>{
await chatStore.createChat(chatName, usersForChat.value.map((user) => user.id)); chatStore.createChat(chatName, usersForChat.value.map((user) => user.id), userStore.user!.id).then((response : responseModel) => {
sendNotification(response.message, response.success);
reloadChats(); reloadChats();
});
} }
const reloadChats = async() => { const reloadChats = async() => {

16
src/utils.ts Normal file
View File

@@ -0,0 +1,16 @@
import { Notify } from "quasar";
import { responseModel } from "./models";
export const sendRestResponseAsNotification = (response : responseModel) => {
}
export const sendNotification = (message : string, successful : Boolean) => {
Notify.create({
message: message,
position: 'top',
timeout: 2000,
color: successful ? "green" : "red",
icon: successful ? "success" : "warning"
});
}