remove duplicate loading
This commit is contained in:
parent
16d0fafb1a
commit
41aabb868f
@ -53,7 +53,6 @@ import {
|
|||||||
getThreadInfoOnId,
|
getThreadInfoOnId,
|
||||||
incrementNotSeenRoom,
|
incrementNotSeenRoom,
|
||||||
} from "../../db/saveMessage-db";
|
} from "../../db/saveMessage-db";
|
||||||
import { AttrsWithEnvelope } from "../../interfaces/mail/attrs.interface";
|
|
||||||
import { AttrsWithEnvelopeTest, createReplyWithSameMembers } from "../test-utils/test-messageUtils";
|
import { AttrsWithEnvelopeTest, createReplyWithSameMembers } from "../test-utils/test-messageUtils";
|
||||||
// todo esbuild
|
// todo esbuild
|
||||||
// new message from us
|
// new message from us
|
||||||
|
@ -10,6 +10,12 @@ export interface Message {
|
|||||||
todo: true;
|
todo: true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum LoadingState {
|
||||||
|
notLoaded = 0,
|
||||||
|
loading = 1,
|
||||||
|
loaded = 2,
|
||||||
|
}
|
||||||
|
|
||||||
export interface Room {
|
export interface Room {
|
||||||
id: number;
|
id: number;
|
||||||
roomName: string;
|
roomName: string;
|
||||||
@ -19,7 +25,7 @@ export interface Room {
|
|||||||
userId: number;
|
userId: number;
|
||||||
unseen: number;
|
unseen: number;
|
||||||
messages: Message[];
|
messages: Message[];
|
||||||
messagesFetched: boolean;
|
messageLoading: LoadingState;
|
||||||
threads: object[];
|
threads: object[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import API from "@/services/imapAPI";
|
|||||||
import { decodeEmojis } from "@/utils/string";
|
import { decodeEmojis } from "@/utils/string";
|
||||||
import { AxiosError, AxiosResponse } from "axios";
|
import { AxiosError, AxiosResponse } from "axios";
|
||||||
import { createStore, Store } from "vuex";
|
import { createStore, Store } from "vuex";
|
||||||
import { Room, Account, Address, RoomType, Message } from "./models/model";
|
import { Room, Account, Address, RoomType, Message, LoadingState } from "./models/model";
|
||||||
|
|
||||||
interface RoomFromBack {
|
interface RoomFromBack {
|
||||||
id: number;
|
id: number;
|
||||||
@ -31,7 +31,7 @@ function createRoom(options: RoomFromBack): Room {
|
|||||||
user: options.user,
|
user: options.user,
|
||||||
unseen: 0,
|
unseen: 0,
|
||||||
messages: [],
|
messages: [],
|
||||||
messagesFetched: false,
|
messageLoading: LoadingState.notLoaded,
|
||||||
threads: [],
|
threads: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -63,8 +63,19 @@ const store = createStore<State>({
|
|||||||
},
|
},
|
||||||
setActiveRoom(state, payload) {
|
setActiveRoom(state, payload) {
|
||||||
state.activeRoom = payload;
|
state.activeRoom = payload;
|
||||||
const room = state.rooms.find((room) => room.id == payload);
|
// todo load room on load page
|
||||||
store.dispatch("fetchMessages", { roomId: payload, room: room });
|
// let room;
|
||||||
|
// // const room = state.rooms.find((room) => room.id == payload);
|
||||||
|
// console.log(state.rooms.length);
|
||||||
|
// for (let i = 0; i < state.rooms.length; i++) {
|
||||||
|
// console.log(state.rooms[i].id, payload.value);
|
||||||
|
// if (state.rooms[i].id == payload.value) {
|
||||||
|
// room = state.rooms[i];
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// console.log(room);
|
||||||
|
// store.dispatch("fetchMessages", { roomId: payload, room: room });
|
||||||
},
|
},
|
||||||
addAccounts(state, payload) {
|
addAccounts(state, payload) {
|
||||||
payload.forEach((account: AccountFromBack) => {
|
payload.forEach((account: AccountFromBack) => {
|
||||||
@ -84,7 +95,6 @@ const store = createStore<State>({
|
|||||||
payload.messages.forEach((message: Message) => {
|
payload.messages.forEach((message: Message) => {
|
||||||
room.messages.push(message);
|
room.messages.push(message);
|
||||||
});
|
});
|
||||||
room.messagesFetched = true;
|
|
||||||
},
|
},
|
||||||
addAddress(state, payload) {
|
addAddress(state, payload) {
|
||||||
// todo add if not exist
|
// todo add if not exist
|
||||||
@ -115,8 +125,8 @@ const store = createStore<State>({
|
|||||||
(roomId: number): Message[] => {
|
(roomId: number): Message[] => {
|
||||||
const room = state.rooms.find((room) => room.id == roomId);
|
const room = state.rooms.find((room) => room.id == roomId);
|
||||||
if (!room) return [];
|
if (!room) return [];
|
||||||
if (!room.messagesFetched) {
|
if (room.messageLoading === LoadingState.notLoaded) {
|
||||||
store.dispatch("fetchMessages", { roomId: room.id });
|
store.dispatch("fetchMessages", { roomId: room.id, room: room });
|
||||||
}
|
}
|
||||||
return room.messages;
|
return room.messages;
|
||||||
},
|
},
|
||||||
@ -144,13 +154,16 @@ const store = createStore<State>({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fetchMessages: async (context, data) => {
|
fetchMessages: async (context, data) => {
|
||||||
if (!data.room || data.room?.fetched == false) {
|
if (!data.room || data.room.messageLoading === LoadingState.notLoaded) {
|
||||||
|
data.room.messageLoading = LoadingState.loading;
|
||||||
store.dispatch("fetchRoomMembers", { roomId: data.roomId });
|
store.dispatch("fetchRoomMembers", { roomId: data.roomId });
|
||||||
API.getMessages(data.roomId)
|
API.getMessages(data.roomId)
|
||||||
.then((res: AxiosResponse) => {
|
.then((res: AxiosResponse) => {
|
||||||
|
data.room.messageLoading = LoadingState.loaded;
|
||||||
context.commit("addMessages", { messages: res.data, roomId: data.roomId });
|
context.commit("addMessages", { messages: res.data, roomId: data.roomId });
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
|
data.room.messageLoading = LoadingState.notLoaded;
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,19 @@ import { useRoute, onBeforeRouteUpdate } from "vue-router";
|
|||||||
import { onBeforeMount, ref } from "vue";
|
import { onBeforeMount, ref } from "vue";
|
||||||
import Header from "./Header.vue";
|
import Header from "./Header.vue";
|
||||||
import Message from "./Message.vue";
|
import Message from "./Message.vue";
|
||||||
|
import { RoomType } from "@/store/models/model";
|
||||||
|
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const id = ref(parseInt(route.params?.id));
|
const id = ref(parseInt(route.params?.id));
|
||||||
|
// let room;
|
||||||
onBeforeMount(async () => {
|
onBeforeMount(async () => {
|
||||||
console.log(id);
|
|
||||||
// get data
|
// get data
|
||||||
let room = store.getters.room(id);
|
// room = store.getters.room(id);
|
||||||
if (!room || room?.fetched === false) {
|
// if (!room || room?.fetched === false) {
|
||||||
// todo
|
// // todo
|
||||||
// await store.dispatch("fetchMessages", );
|
// // await store.dispatch("fetchMessages", );
|
||||||
}
|
// }
|
||||||
store.commit("setActiveRoom", id);
|
store.commit("setActiveRoom", id);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -23,9 +24,18 @@ onBeforeRouteUpdate(async (to, from) => {
|
|||||||
if (to.params.id !== from.params.id) {
|
if (to.params.id !== from.params.id) {
|
||||||
id.value = parseInt(to.params.id);
|
id.value = parseInt(to.params.id);
|
||||||
console.log(id);
|
console.log(id);
|
||||||
|
// room = store.getters.room(id);
|
||||||
|
// console.log(room);
|
||||||
store.commit("setActiveRoom", id);
|
store.commit("setActiveRoom", id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const shouldDisplayComposer = () => {
|
||||||
|
if (!id.value) return false;
|
||||||
|
const room = store.getters.room(id);
|
||||||
|
if (!room) return false;
|
||||||
|
return room.roomType === RoomType.THREAD || room.roomType === RoomType.GROUP;
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -35,7 +45,8 @@ onBeforeRouteUpdate(async (to, from) => {
|
|||||||
<div class="content">
|
<div class="content">
|
||||||
<Message v-for="(message, index) in store.getters.messages(id)" :key="index" :data="message" />
|
<Message v-for="(message, index) in store.getters.messages(id)" :key="index" :data="message" />
|
||||||
</div>
|
</div>
|
||||||
<div id="composer">COMPOSER</div>
|
{{ room?.roomType }}
|
||||||
|
<div id="composer" v-if="shouldDisplayComposer()">COMPOSER</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -67,6 +78,6 @@ onBeforeRouteUpdate(async (to, from) => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column-reverse;
|
flex-direction: column-reverse;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
margin-bottom: 100px;
|
margin-bottom: 60px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user