From 6ea0d4e02eba6fe5a8a9c82b667c0a982ddeafbd Mon Sep 17 00:00:00 2001 From: grimhilt Date: Sun, 2 Apr 2023 16:52:19 +0200 Subject: [PATCH] use strict front --- front/src/services/imapAPI.ts | 8 ++++---- front/src/store/models/model.ts | 6 +++++- front/src/store/store.ts | 32 ++++++++++++++++++++++++-------- front/src/utils/string.ts | 4 ++-- front/tsconfig.json | 2 +- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/front/src/services/imapAPI.ts b/front/src/services/imapAPI.ts index 85379d5..949b046 100644 --- a/front/src/services/imapAPI.ts +++ b/front/src/services/imapAPI.ts @@ -1,19 +1,19 @@ import API from "./API"; export default { - registerAccount(data) { + registerAccount(data: object) { return API().post("/mail/account", data); }, getAccounts() { return API().get("/mail/accounts"); }, - getRooms(mailboxId) { + getRooms(mailboxId: number) { return API().get(`/mail/${mailboxId}/rooms`); }, - getMessages(roomId) { + getMessages(roomId: number) { return API().get(`/mail/${roomId}/messages`); }, - getMembers(roomId) { + getMembers(roomId: number) { return API().get(`/mail/${roomId}/members`); }, }; diff --git a/front/src/store/models/model.ts b/front/src/store/models/model.ts index 0c0f79a..ff3aa84 100644 --- a/front/src/store/models/model.ts +++ b/front/src/store/models/model.ts @@ -7,6 +7,10 @@ export enum RoomType { THREAD = 4, }; +export interface Message { + +} + export interface Room { id: number; roomName: string; @@ -15,7 +19,7 @@ export interface Room { user: string; userId: number; unseen: number; - messages: object[]; + messages: Message[]; messagesFetched: boolean; threads: object[]; } diff --git a/front/src/store/store.ts b/front/src/store/store.ts index d10d0a6..e5e2e12 100644 --- a/front/src/store/store.ts +++ b/front/src/store/store.ts @@ -1,8 +1,24 @@ import API from "@/services/imapAPI"; import { createStore, Store } from "vuex"; -import { Room, Account, Address } from "./models/model"; +import { Room, Account, Address, RoomType, Message } from "./models/model"; -function createRoom(options): Room { +interface RoomFromBack { + id: number; + roomName: string; + roomType: RoomType; + mailboxId: number; + user: string; + userId: number; + // unseen: number; + // todo thread +} + +interface AccountFromBack { + id: number; + email: string; +} + +function createRoom(options: RoomFromBack): Room { return { id: options.id, roomName: options.roomName, @@ -10,7 +26,7 @@ function createRoom(options): Room { mailboxId: options.mailboxId, userId: options.userId, user: options.user, - unseen: options.unseen, + unseen: 0, messages: [], messagesFetched: false, threads: [], @@ -48,13 +64,13 @@ const store = createStore({ store.dispatch("fetchMessages", { roomId: payload, room: room }); }, addAccounts(state, payload) { - payload.forEach((account) => { + payload.forEach((account: AccountFromBack) => { state.accounts.push({ id: account.id, email: account.email, fetched: false }); }); }, addRooms(state, payload) { // todo add if not exist - payload.rooms.forEach((room) => { + payload.rooms.forEach((room: RoomFromBack) => { state.rooms.push(createRoom(room)); }); }, @@ -62,14 +78,14 @@ const store = createStore({ // todo add if not exist const room = state.rooms.find((room) => room.id == payload.roomId); if (!room) return; - payload.messages.forEach((message) => { + payload.messages.forEach((message: Message) => { room.messages.push(message); }); room.messagesFetched = true; }, addAddress(state, payload) { // todo add if not exist - payload.addresses.forEach((address) => { + payload.addresses.forEach((address: Address) => { state.addresses.push(address); }); }, @@ -79,7 +95,7 @@ const store = createStore({ if (state.activeAccount === 0) return state.rooms; return state.rooms.filter((room) => room.mailboxId == state.activeAccount); }, - messages: (state) => (roomId) => { + messages: (state) => (roomId: number) => { const room = state.rooms.find((room) => room.id == roomId); if (!room) return []; if (!room.messagesFetched) { diff --git a/front/src/utils/string.ts b/front/src/utils/string.ts index 13a11de..ae78b00 100644 --- a/front/src/utils/string.ts +++ b/front/src/utils/string.ts @@ -1,6 +1,6 @@ -export function decodeEmojis(text) { +export function decodeEmojis(text: string): string { if (!text) return text; const regex = /\\u{([^}]+)}/g; - const decodedText = text.replace(regex, (_, hex) => String.fromCodePoint(parseInt(hex, 16))); + const decodedText = text.replace(regex, (_: string, hex: string) => String.fromCodePoint(parseInt(hex, 16))); return decodedText; } diff --git a/front/tsconfig.json b/front/tsconfig.json index cd0ce03..06bddb3 100644 --- a/front/tsconfig.json +++ b/front/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "es5", "module": "esnext", - // "strict": true, + "strict": true, "jsx": "preserve", "importHelpers": true, "moduleResolution": "node",