load message in page loading

This commit is contained in:
grimhilt 2023-05-08 01:10:13 +02:00
parent 53c79aebc4
commit 4ecd723cec
4 changed files with 29 additions and 57 deletions

View File

@ -1,28 +1,31 @@
# TRIFORM # TRIFORM
*WORK IN PROGRESS*
_WORK IN PROGRESS_
TRIFORM (Threaded Rooms Interface For Organised Relational Mails) is a mail client which sorts mails into conversations based on the members present in each mails. TRIFORM (Threaded Rooms Interface For Organised Relational Mails) is a mail client which sorts mails into conversations based on the members present in each mails.
## Features ## Features
- [x] Multi account - [x] Multi account (tested only with gmail)
- [x] Live syncing of mails - [x] Live syncing of mails
- [x] Live syncing of flags - [x] Live syncing of flags
- [x] Mark as read/unread - [x] Mark as read/unread
- [ ] Attachments - [x] Flag important
- [ ] Send new mails - [ ] Attachments
- [ ] Respond to mails - [ ] Send new mails
- [ ] Delete mails - [ ] Respond to mails
- [ ] Live sync with the ui - [x] Delete mails
- [ ] Delete rooms
- [ ] Live sync with the ui
## Installation ## Installation
## Definitions ## Definitions
- Room: General space where messages are grouped. - Room: General space where messages are grouped.
- Channel: Space use for newsletters or other conversations when there is a low need for reply. - Channel: Space use for newsletters or other conversations when there is a low need for reply.
- Group: Space contening several users that are part of the conversation. - Group: Space contening several users that are part of the conversation.
- DM: Space defining a conversation with only one other member. - DM: Space defining a conversation with only one other member.
- Thread: Sub-Space generally created when changing the number of member in a space. - Thread: Sub-Space generally created when changing the number of member in a space.
## Examples ## Examples

View File

@ -1,24 +0,0 @@
# mail
## Project setup
```
yarn install
```
### Compiles and hot-reloads for development
```
yarn serve
```
### Compiles and minifies for production
```
yarn build
```
### Lints and fixes files
```
yarn lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

View File

@ -77,8 +77,6 @@ function updateSeen(state: State, roomId: number, flag: string[], adding: boolea
} }
} }
} }
// define injection key todo
// export const key: InjectionKey<Store<State>> = Symbol()
const store = createStore<State>({ const store = createStore<State>({
state: { state: {
@ -96,9 +94,6 @@ const store = createStore<State>({
}, },
setActiveRoom(state, payload) { setActiveRoom(state, payload) {
state.activeRoom = payload; state.activeRoom = payload;
// todo load room on load page
const room = roomOnId(state, payload);
if (!room) return;
let roomMessage = msgOnRoomId(state, payload); let roomMessage = msgOnRoomId(state, payload);
if (!roomMessage) { if (!roomMessage) {
state.roomMessages.push({ messages: [], fetch: LoadingState.notLoaded, roomId: payload }); state.roomMessages.push({ messages: [], fetch: LoadingState.notLoaded, roomId: payload });
@ -115,7 +110,6 @@ const store = createStore<State>({
}); });
}, },
addRooms(state, payload) { addRooms(state, payload) {
// todo add if not exist
const buffer: RoomFromBack[] = []; const buffer: RoomFromBack[] = [];
payload.rooms.forEach((room: RoomFromBack) => { payload.rooms.forEach((room: RoomFromBack) => {
if (room.roomType == RoomType.THREAD) { if (room.roomType == RoomType.THREAD) {
@ -134,7 +128,6 @@ const store = createStore<State>({
}); });
}, },
removeRoom(state, payload) { removeRoom(state, payload) {
console.log(payload);
const roomMessageIndex = state.roomMessages.findIndex((roomM) => roomM.roomId === payload.roomId); const roomMessageIndex = state.roomMessages.findIndex((roomM) => roomM.roomId === payload.roomId);
state.roomMessages.splice(roomMessageIndex, 1); state.roomMessages.splice(roomMessageIndex, 1);
const roomIndex = state.rooms.findIndex((room) => room.id === payload.roomId); const roomIndex = state.rooms.findIndex((room) => room.id === payload.roomId);
@ -147,21 +140,18 @@ const store = createStore<State>({
parentRoom.threadIds = parentRoom?.threadIds.filter((id) => id !== roomToDelete.id); parentRoom.threadIds = parentRoom?.threadIds.filter((id) => id !== roomToDelete.id);
} }
} }
// todo fix to many at the same time bug
state.rooms.splice(roomIndex, 1); state.rooms.splice(roomIndex, 1);
// state.activeRoom = state.rooms[0].id; // state.activeRoom = state.rooms[0].id;
// router.push(`/${state.activeRoom}`); // router.push(`/${state.activeRoom}`);
}, },
addMessages(state, payload) { addMessages(state, payload) {
// todo add if not exist
const room = roomOnId(state, payload.roomId);
if (!room) return;
let roomMessage = msgOnRoomId(state, payload.roomId); let roomMessage = msgOnRoomId(state, payload.roomId);
if (!roomMessage) { if (!roomMessage) {
state.roomMessages.push({ roomId: payload.roomId, messages: [], fetch: LoadingState.notLoaded }); state.roomMessages.push({ roomId: payload.roomId, messages: [], fetch: LoadingState.notLoaded });
roomMessage = msgOnRoomId(state, payload.roomId); roomMessage = msgOnRoomId(state, payload.roomId);
} }
if (!roomMessage) return; if (!roomMessage) return;
payload.messages.forEach((message: any) => { payload.messages.forEach((message: any) => {
message.flags = message.flags?.split(",") ?? []; message.flags = message.flags?.split(",") ?? [];
roomMessage?.messages.push(message); roomMessage?.messages.push(message);
@ -225,9 +215,14 @@ const store = createStore<State>({
messages: messages:
(state) => (state) =>
(roomId: number): Message[] => { (roomId: number): Message[] => {
if (!roomId) return [];
const roomMessage = msgOnRoomId(state, roomId); const roomMessage = msgOnRoomId(state, roomId);
if (roomMessage) return roomMessage.messages; if (roomMessage && roomMessage.fetch === LoadingState.loaded) return roomMessage.messages;
state.roomMessages.push({ messages: [], roomId: roomId, fetch: LoadingState.notLoaded }); if (!roomMessage) {
state.roomMessages.push({ messages: [], roomId: roomId, fetch: LoadingState.notLoaded });
} else if (roomMessage.fetch === LoadingState.loaded) {
return roomMessage.messages;
}
store.dispatch("fetchMessages", { roomId: roomId, obj: msgOnRoomId(state, roomId) }); store.dispatch("fetchMessages", { roomId: roomId, obj: msgOnRoomId(state, roomId) });
return msgOnRoomId(state, roomId)?.messages ?? []; return msgOnRoomId(state, roomId)?.messages ?? [];
}, },

View File

@ -17,10 +17,10 @@ const id = ref(parseInt(route.params.id));
let room = ref(); let room = ref();
onBeforeMount(async () => { onBeforeMount(async () => {
console.log(id.value);
store.commit("setActiveRoom", id.value); store.commit("setActiveRoom", id.value);
room.value = store.getters.room(id.value); room.value = store.getters.room(id.value);
messages.value = store.getters.messages(room.value?.id); messages.value = store.getters.messages(id.value);
console.log(room.value);
}); });
onBeforeRouteUpdate(async (to, from) => { onBeforeRouteUpdate(async (to, from) => {
@ -28,9 +28,7 @@ onBeforeRouteUpdate(async (to, from) => {
id.value = parseInt(to.params.id); id.value = parseInt(to.params.id);
store.commit("setActiveRoom", id.value); store.commit("setActiveRoom", id.value);
room.value = await store.getters.room(id.value); room.value = await store.getters.room(id.value);
messages.value = store.getters.messages(room.value?.id); messages.value = store.getters.messages(id.value);
console.log(room.value);
} }
}); });