Random colors are now assigned to every member of a chat at startup

This commit is contained in:
joschuatonn
2024-06-20 07:29:00 +02:00
parent 0c9ca7c36a
commit 85b6da4387

View File

@@ -1,8 +1,9 @@
import { defineStore } from 'pinia';
import {chat, profilePicture, responseModel} from 'src/models';
import {chat, profilePicture, ptpUser, responseModel} from 'src/models';
import { api } from 'src/boot/axios';
import { useUserStore } from 'stores/user-store';
import { useQuasar } from 'quasar';
import { getRandomHexColor } from 'src/utils';
export const useChatStore = defineStore('chatStore',{
state:() => ({
@@ -21,6 +22,13 @@ export const useChatStore = defineStore('chatStore',{
},
async loadChatsByUser() : Promise<chat[]>{
this.chats = (await api.get("/users/chat/" + useUserStore().id)).data.response;
this.chats.forEach((c) => {
c.members.forEach((member) => {
member.nametagColor = getRandomHexColor();
})
})
this.chatsLoaded = true;
return this.chats;
},
@@ -44,6 +52,7 @@ export const useChatStore = defineStore('chatStore',{
console.log(members);
return (await api.post("/chats/create/" + chatName + "/" + keycloakID, members)).data;
},
async updateChat(chat : chat) {
const updatedChat : chat = {...chat};
@@ -54,7 +63,6 @@ export const useChatStore = defineStore('chatStore',{
}
});
return (await api.post("/chats/update", chat)).data;
},