Browse Source

msgs block routing fixed

Ivar 3 years ago
parent
commit
23065c89a9
5 changed files with 10 additions and 10 deletions
  1. 1 1
      src/App.js
  2. 2 2
      src/actions/msgActions.js
  3. 1 1
      src/components/Msg.jsx
  4. 2 1
      src/components/MsgList.jsx
  5. 4 5
      src/pages/MsgPage.jsx

+ 1 - 1
src/App.js

@@ -100,7 +100,7 @@ const CAuthSwitch = connect(state => ({ token: state.auth.token || null }))(Auth
 
 function App() {
 
-  // window.addEventListener("contextmenu", e => e.preventDefault());
+  window.addEventListener("contextmenu", e => e.preventDefault());
 
   return (
     <Router history={history}>

+ 2 - 2
src/actions/msgActions.js

@@ -69,8 +69,8 @@ export const actionFullMsgsByChat = (chatId, currentCount, limitCount=50) => (
 
       let chat = getState().chats[chatId]
 
-      if (!chat || ( (chat.messages && chat.messages[0]?._id !== chat.firstMsgId) &&
-                        ( (chat.messages?.length ?? 0) < currentCount + limitCount) )
+      if (!chat || !chat.messages || ( (chat.messages[0]?._id !== chat.firstMsgId)  &&
+                        ( (chat.messages?.length ?? 0) < currentCount + limitCount)  )
                         ) {
          // console.log(chat)
 

+ 1 - 1
src/components/Msg.jsx

@@ -211,7 +211,7 @@ const Msg = ({ msg, myProfile, onEdit }) => {
          </Popover>
 
 
-         <div onClick={handleClick}
+         <div onContextMenu={handleClick}
 
             style={  (myId === owner._id) ? 
                         ( (nextMsg?.owner?._id === owner._id) ? 

+ 2 - 1
src/components/MsgList.jsx

@@ -13,10 +13,11 @@ const msgsWrapper = {
    paddingBottom: "5px"
 }
 
-const MsgList = ({chats={}, chatId, onEdit }) => {
+const MsgList = ({chats, chatId, onEdit }) => {
 
    const msgArr = chats[chatId]?.messages
 
+
    return (
       <div 
          style={msgsWrapper}

+ 4 - 5
src/pages/MsgPage.jsx

@@ -57,18 +57,18 @@ const MsgBlock = ({ chatId, getMsgs, setLastVizited, msgsCount=20 }) => {
 
    const [msgsBlock, setMsgsBlock] = useState(0)
 
-
+   
    const divRef = useRef(null)
 
 
-   useEffect(() => {
+   useEffect( () => {
+      console.log(chatId)
       getMsgs(chatId, msgsBlock, msgsCount)
    },[msgsBlock])
 
 
    useEffect(() => {
       // console.log(chatId, "МАУНТ СООБЩЕНИЙ")
-
       const date = (new Date()).getTime()
       setLastVizited({
             _id: chatId, 
@@ -78,7 +78,6 @@ const MsgBlock = ({ chatId, getMsgs, setLastVizited, msgsCount=20 }) => {
 
       return () => {
          // console.log(chatId, "АНМАУНТ СООБЩЕНИЙ")
-
          const date = (new Date()).getTime()
          setLastVizited({
                _id: chatId, 
@@ -143,5 +142,5 @@ const MsgPage = ({ match:{params:{_id}}, chats }) => {
    }
 
 }
-export const CMsgPage = connect( state => ({ chats: state.chats || {} }) )(MsgPage)
+export const CMsgPage = connect( state => ({ chats: state.chats }) )(MsgPage)