Przeglądaj źródła

done litle bit left bar

unknown 3 lat temu
rodzic
commit
e00e1883fd

Plik diff jest za duży
+ 1 - 1
.eslintcache


+ 1 - 1
src/App.tsx

@@ -38,7 +38,7 @@ function App() {
 
   useEffect(() => {
     if (!localStorage.isChecked) localStorage.isChecked = 'true'
-    if (localStorage.isNew) localStorage.removeItem('isNew')
+    localStorage.removeItem('isNew')
   }, [])
 
    useEffect(() => {

+ 0 - 13
src/api-data/index.ts

@@ -162,7 +162,6 @@ const getChatById = async <T>(id:string): Promise<T | undefined> => {
 const startChat = async <T>(id:string): Promise<T | undefined> => {
   try {
     const { data: { data } } = await axios.post('/chats', { id });
-    console.log(data)
     return data
   } catch (e) {
     forbidden(e)
@@ -180,16 +179,6 @@ const removeChatForBoth = async <T>(id:string): Promise<T | undefined> => {
   }
 };
 
-const removeChatForMe = async <T>(id:string): Promise<T | undefined> => {
-  try {
-    const { data: { data } } = await axios.delete(`/chats/me/${id}`);
-    return data
-  } catch (e) {
-    forbidden(e)
-    return undefined
-  }
-};
-
 const muteChat = async <T>(id:string): Promise<T | undefined> => {
   try {
     const { data: { data } } = await axios.patch('/chats/mute', {id});
@@ -233,7 +222,6 @@ const typingChat = async <T>(id:string,typing:boolean): Promise<T | undefined> =
 const getChats = async <T>(): Promise<T | undefined> => {
   try {
     const { data: { data } } = await axios.get('/chats');
-    console.log(data)
     return data
   } catch (e) {
     forbidden(e)
@@ -318,7 +306,6 @@ export {
   getContacts,
   startChat,
   removeChatForBoth,
-  removeChatForMe,
   getChatById,
   muteChat,
   sortChat,

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

@@ -180,7 +180,7 @@ const ChatsList = () => {
   const dispatch = useDispatch()
   const ref = useRef<any>(null)
   const [selectedIndex, setSelectedIndex] = useState<number>(1);
-  const { total, chats, lastMessages, lastOnline } = useSelector(getState)
+  const { total, chats } = useSelector(getState)
   const chat = useSelector(getChatMemo)
 
   const handleListItemClick = (i: number, companionId: string) => {
@@ -193,7 +193,6 @@ const ChatsList = () => {
     e.stopPropagation()
     dispatch(asyncStartChatById(companionId))
     dispatch(actionScroll(true))
-    console.log(i,'index','clicked read new messages')
   }
 
   useEffect(() => {
@@ -208,7 +207,7 @@ const ChatsList = () => {
       dispatch(asyncStartChatById(companionId))
       dispatch(actionScroll(true))
     }
-    if (!chats.find((el) => el.companionId === chat.companionId)) {
+    if (chat.companionId&&!chats.find((el) => el.companionId === chat.companionId)) {
       dispatch(actionRemoveChat())
     }
     if (ref.current) {
@@ -229,14 +228,15 @@ 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 }, i: number) => 
+      {chats.map(({ name, lastName, avatarUrl, updatedAt, color, companionId, mute, seen, total,
+        watched, typing, number, online, lastMessage }, i: number) =>
           <ListItemButton
           key={number}
           selected={selectedIndex === i}
           onClick={() => handleListItemClick(i,companionId)}
           >
           <ListItemIcon className={classes.listItem_iconAvatar}>
-            <StyledBadge overlap="circular"  variant={lastOnline[i].online === 'true'?'dot':'standard'}
+            <StyledBadge overlap="circular"  variant={online === 'true'?'dot':'standard'}
                   anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}>
                  <Avatar alt={name} src={avatarUrl?`http://localhost:3000/${avatarUrl}`:undefined}
                      sx={{ background: color, width: 54, height: 54 }}>
@@ -250,16 +250,16 @@ const ChatsList = () => {
             {mute&&<VolumeOffIcon className={classes.listItemInnerText__icon} fontSize='small' />}</div>}
             secondary={typing ? <span className={classes.listItem_typing}>
               typing<span className={classes.listItem_dots}>...</span></span> :
-              lastMessages[i] ? slicedWord(lastMessages[i].message, 35) :
+              lastMessage ? slicedWord(lastMessage, 35) :
               `${firstLetter(name)}${slicedWord(name, 8, 1)} joined Telegram`}/>
           <ListItemIcon className={classes.listItem_iconRight}>
                <div className={classes.listItem_iconTimeChecked}>
                  {watched&& <DoneAllIcon style={{ color: '#18bd03' }} fontSize='small' />}
               <Typography className={classes.listItem_icon_time} variant="h6" color="initial">
-                {lastMessages[i] ? timeStampEU(lastMessages[i].updatedAt) :
-                timeStampEU(updatedAt)}</Typography>
+                {timeStampEU(updatedAt)}
+              </Typography>
                </div>
-            {lastMessages[i] && total > seen ? <button onClick={(e) => handleNewMsgs(e, i,companionId)}
+            {lastMessage && total > seen ? <button onClick={(e) => handleNewMsgs(e, i,companionId)}
               className={mute?classes.listItem_iconRightBtnMute:classes.listItem_iconRightBtn}>{total-seen}</button> :
               <button  className={classes.listItem_iconRightBtnHidden}/>}
           </ListItemIcon>            

+ 4 - 9
src/components/HomePage/RightBar/HeaderBar/Buttons/DeleteModal/index.tsx

@@ -4,7 +4,7 @@ import { makeStyles } from '@material-ui/core'
 import { useSelector } from 'react-redux';
 
 import { getChat } from '../../../../../../redux/chat/selector';
-import { removeChatForBoth,removeChatForMe } from '../../../../../../api-data';
+import { removeChatForBoth } from '../../../../../../api-data';
 import { firstLetter,slicedWord } from '../../../../../../helpers';
 
 const useStyles = makeStyles({
@@ -46,8 +46,7 @@ const DeleteModal = ({setModal}:{setModal:any}) => {
   const handleDeleteModal = (e: any) => {
     const id = e.target.id
     if (id === 'overlay' || id === 'cancel')  return setModal(false)
-    if (id === 'deleteForBoth') removeChatForBoth(companionId)
-    if (id === 'deleteForMe') removeChatForMe(companionId)
+    removeChatForBoth(companionId)
   }  
   return (
     <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
@@ -62,12 +61,8 @@ const DeleteModal = ({setModal}:{setModal:any}) => {
          <p style={{color: '#050505'}}>{`Are you sure you want to delete the
           chat with ${`${firstLetter(name)}${slicedWord(name, 15, 1)} 
             ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}?`}</p>
-          <Button id='deleteForBoth' variant="text" color="error" style={{fontWeight:500,fontSize:18}}>
-            {`DELETE FOR ME AND ${`${firstLetter(name)}${slicedWord(name, 15, 1)} 
-            ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}`}
-          </Button>
-          <Button id='deleteForMe' variant="text" color="error" style={{fontWeight:500,fontSize:18}}>
-            DELETE FOR ME
+          <Button  variant="text" color="error" style={{fontWeight:500,fontSize:18}}>
+            DELETE CHAT FOR BOTH
           </Button>         
           <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:18}}>
              CANCEL

+ 0 - 1
src/helpers/index.ts

@@ -25,7 +25,6 @@ const timeStampEU = (updatedAt: string) => new Date(updatedAt).toLocaleString('e
 })
 
 const timeStampMessage = (updatedAt: string) => new Date(updatedAt).toLocaleString('en-GB',{
-    timeZone: 'UTC',
     hour: 'numeric',
     minute: '2-digit',
 })

+ 1 - 0
src/redux/chat/reducer/index.ts

@@ -14,6 +14,7 @@ const initialState: IChatState = {
      avatarUrl:'',
      color: '',
      online: '',
+     lastMessage: '',
      mute: false,
      sort:false,
      seen: 0,

+ 0 - 2
src/redux/chats/reducer/index.ts

@@ -11,8 +11,6 @@ const initialState: IChatsState = {
   limit: "0",
   page: "0",
   chats: [],
-  lastMessages: [],
-  lastOnline: [],
 }
 
 

+ 1 - 2
src/redux/chats/selector/index.ts

@@ -5,8 +5,7 @@ const getTotal = (state: IState) => state.chats.total;
 const getLimit = (state:IState) => state.chats.limit;
 const getPage = (state: IState) => state.chats.page;
 const getChats = (state: IState) => state.chats.chats;
-const getLastMessages = (state: IState) => state.chats.lastMessages;
 const getState = (state: IState) => state.chats;
 const getStateMemo = createSelector([getState], state => state);
 
-export { getTotal,getLimit,getPage,getChats,getLastMessages,getState,getStateMemo };
+export { getTotal,getLimit,getPage,getChats,getState,getStateMemo };

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

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

+ 1 - 7
src/typescript/redux/chats/interfaces.ts

@@ -1,12 +1,10 @@
-import { TChats,TLastMessages, TLastOnlineArr } from './types'
+import { TChats } from './types'
 
 export interface IChatsState  {
   total: string,
   limit: string,
   page: string,
   chats: TChats,
-  lastMessages: TLastMessages,
-  lastOnline: TLastOnlineArr
 }
 
 export interface IChatsPayload {
@@ -15,8 +13,6 @@ export interface IChatsPayload {
   limit: string,
   page: string,
   chats: TChats,
-  lastMessages: TLastMessages,
-  lastOnline: TLastOnlineArr
   },
 }
 
@@ -25,8 +21,6 @@ export interface IChatsRes  {
   limit: string,
   page: string,
   chats: TChats,
-  lastMessages: TLastMessages,
-  lastOnline: TLastOnlineArr
 }
 
 

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

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