unknown 3 anni fa
parent
commit
adb5740dc0

File diff suppressed because it is too large
+ 1 - 1
.eslintcache


+ 1 - 1
src/api-data/index.ts

@@ -152,7 +152,7 @@ const getContacts = async <T>(): Promise<T | undefined> => {
 const getChatById = async <T>(id:string): Promise<T | undefined> => {
   try {
     const { data: { data } } = await axios.get(`/chats/${id}`);
-    return data
+    return data._doc
   } catch (e) {
     forbidden(e)
     return undefined

+ 3 - 3
src/components/HomePage/LeftBar/ChatsList/index.tsx

@@ -228,8 +228,8 @@ const ChatsList = () => {
   return total !== '0' ? (
     <List className={classes.list} component="nav"
           aria-label="main mailbox folders">
-      {chats.map(({ name, lastName, avatarUrl, updatedAt, color, companionId, mute, seen, total,
-        watched, typing, number, online, lastMessage }, i: number) =>
+      {chats.map(({ name, lastName, avatarUrl, color, companionId, mute, seen, total,
+        watched, typing, number, online, lastMessage,lastMessageCreatedAt,createdAt }, i: number) =>
           <ListItemButton
           key={number}
           selected={selectedIndex === i}
@@ -256,7 +256,7 @@ const ChatsList = () => {
                <div className={classes.listItem_iconTimeChecked}>
                  {watched&& <DoneAllIcon style={{ color: '#18bd03' }} fontSize='small' />}
               <Typography className={classes.listItem_icon_time} variant="h6" color="initial">
-                {timeStampEU(updatedAt)}
+                {timeStampEU(lastMessageCreatedAt?lastMessageCreatedAt:createdAt)}
               </Typography>
                </div>
             {lastMessage && total > seen ? <button onClick={(e) => handleNewMsgs(e, i,companionId)}

+ 5 - 2
src/components/HomePage/RightBar/ChatBar/index.tsx

@@ -61,7 +61,8 @@ const ChatBar = () => {
      top: divRef.current.scrollHeight,
      behavior: 'smooth'
      })
-   }
+  }
+
   const handleScroll = ({ target }: any) => {
     const different = target.scrollHeight - target.scrollTop
     if (different < 900) seenChat(companionId)
@@ -71,11 +72,13 @@ const ChatBar = () => {
 
   useEffect(() => {
     if (scroll) {
+      seenChat(companionId)
       dispatch(asyncGetMessagesById(companionId, handleScrollTo))
       dispatch(actionScroll(false))
     }
   }, [dispatch,scroll, companionId])  
-  
+  // () =>
+  //       divRef.current.scrollHeight < 900 && !watched&& seenChat(companionId))
   useEffect(() => {
     dispatch(asyncGetMessagesById(companionId, handleScrollTo))
     const handleReset = () => {

+ 8 - 8
src/redux/chat/reducer/index.ts

@@ -1,5 +1,6 @@
 import { createReducer } from '@reduxjs/toolkit';
-import { IChatPayload,IChatState } from '../../../typescript/redux/chat/interfaces';
+import { IChatPayload } from '../../../typescript/redux/chat/interfaces';
+import { TChat} from '../../../typescript/redux/chat/types';
 
 import {
   actionSelectChat,
@@ -7,14 +8,14 @@ import {
   actionRemoveChat
 } from '../action';
 
-const initialState: IChatState = {
-  chat: {
+const initialState: TChat = {
      name: '',
      lastName: '',
      avatarUrl:'',
      color: '',
      online: '',
      lastMessage: '',
+     lastMessageCreatedAt:'',
      mute: false,
      sort:false,
      seen: 0,
@@ -28,15 +29,14 @@ const initialState: IChatState = {
      createdAt: '',
      updatedAt: '',
     __v: 0,
-  },
 }
 
 const reducerChat = createReducer(initialState, {
-  [actionSelectChat.type]: (_,{ payload:chat }:IChatPayload) => {
-    return {chat}
+  [actionSelectChat.type]: (_,{ payload }:IChatPayload) => {
+    return payload
   },
-  [actionGetChatById.type]: (_,{ payload:chat }:IChatPayload) => {
-    return {chat}
+  [actionGetChatById.type]: (_,{ payload }:IChatPayload) => {
+    return payload
   },
   [actionRemoveChat.type]: (_state,_) => {
     return initialState

+ 2 - 2
src/redux/chat/selector/index.ts

@@ -1,8 +1,8 @@
 import { createSelector } from 'reselect';
 import { IState } from '../../../typescript/redux/interfaces'
 
-const getState = (state: IState) => state.chat;
-const getChat = (state: IState) => state.chat.chat;
+const getState = (state: IState) => state;
+const getChat = (state: IState) => state.chat;
 const getChatMemo = createSelector([getChat], chat => chat);
 
 export { getChat,getState,getChatMemo };

+ 0 - 4
src/typescript/redux/chat/interfaces.ts

@@ -1,9 +1,5 @@
 import { TChat } from './types'
 
-export interface IChatState  {
-  chat: TChat,
-}
-
 export interface IChatPayload {
   payload: TChat
 }

+ 1 - 0
src/typescript/redux/chat/types.ts

@@ -5,6 +5,7 @@ export type TChat = {
   color: string,
   online: string,
   lastMessage: string,
+  lastMessageCreatedAt:string,
   mute: boolean,
   sort:boolean,
   seen: number,

+ 1 - 0
src/typescript/redux/chats/types.ts

@@ -5,6 +5,7 @@ export type TChat = {
   color: string,
   online: string,
   lastMessage: string,
+  lastMessageCreatedAt:string,
   mute: boolean,
   sort:boolean,
   seen: number,

+ 2 - 2
src/typescript/redux/interfaces.ts

@@ -1,14 +1,14 @@
 import { IAuthorizationState } from './authorization/interfaces'
 import { IContactsState } from './contacts/interfaces'
 import { IChatsState } from './chats/interfaces'
-import { IChatState } from './chat/interfaces'
+import { TChat } from './chat/types'
 import { IMessagesState} from './messages/interfaces'
 import { IControlState } from './control/interfaces'
 
 export interface IState {
   messages: IMessagesState,
   contacts: IContactsState,
-  chat:IChatState,
+  chat:TChat,
   chats: IChatsState,
   control:IControlState,
   isLoading: boolean;