Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3122 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3122 Rev 3123
Línea 94... Línea 94...
94
 
94
 
95
  const handleCloseConversation = async (entity) => {
95
  const handleCloseConversation = async (entity) => {
96
    try {
96
    try {
97
      const { data } = await axios.post(entity.url_close)
97
      const { data } = await axios.post(entity.url_close)
98
      if (!data.success) console.log('Error in entity close')
98
      if (!data.success) console.log('Error in entity close')
-
 
99
      setActiveChats(activeChats.filter(prevActiveChats => prevActiveChats.id !== entity.id))
99
      return setActiveChats(activeChats.filter(prevActiveChats => prevActiveChats.id !== entity.id))
100
      return true
100
    } catch (error) {
101
    } catch (error) {
101
      console.log(error)
102
      console.log(error)
102
    }
103
    }
Línea 103... Línea 104...
103
  }
104
  }
104
 
-
 
105
  const handleOpenConversation = async (entity, minimized = false) => {
105
 
106
    if (activeChats.some((el) => el.id === entity.id)) return
106
  const handleOpenConversation = async (entity, minimized = false) => {
-
 
107
    if (activeChats.length >= 3) {
107
    if (activeChats.length >= 3) {
108
      const closeComplete = handleCloseConversation(activeChats[0]).then((result)=> result)
108
      handleCloseConversation(activeChats[0])
109
      !closeComplete && false
109
    }
110
    }
110
    try {
111
    try {
111
      const { data } = await axios.post(entity.url_open)
112
      const { data } = await axios.post(entity.url_open)
-
 
113
      if (!data.success) console.log('Error in open conversation')
-
 
114
      const notRepeatActiveChats = new Set([...activeChats, { ...entity, minimized: minimized }])
112
      if (!data.success) console.log('Error in open conversation')
115
      setActiveChats(notRepeatActiveChats)
113
      return setActiveChats(prevActiveChats => [...prevActiveChats, { ...entity, minimized: minimized }])
116
      return true
114
    } catch (error) {
117
    } catch (error) {
115
      console.log(error)
118
      console.log(error)
Línea 127... Línea 130...
127
    } catch (error) {
130
    } catch (error) {
128
      console.log(`Error: ${error}`)
131
      console.log(`Error: ${error}`)
129
    }
132
    }
130
  };
133
  };
Línea 131... Línea 134...
131
 
134
 
132
  const handleMinimizeChat = (chatIndex, minimize) => {
135
  const handleMinimizeConversation = (entity, minimized = null) => {
133
    const newActiveChats = [...activeChats];
-
 
134
    switch (minimize) {
-
 
135
      case false:
136
    return setActiveChats(prevActiveChats => [...prevActiveChats].map(chat => {
136
        newActiveChats[chatIndex].minimized = false;
-
 
137
        break;
-
 
138
      default:
-
 
139
        newActiveChats[chatIndex].minimized =
-
 
140
          !newActiveChats[chatIndex].minimized;
137
      if (entity.id === chat.id) return { ...chat, minimized: minimized ?? !entity.minimized }
141
        break;
138
      return chat
142
    }
-
 
143
    setActiveChats(newActiveChats);
139
    }))
Línea 144... Línea 140...
144
  };
140
  }
145
 
141
 
Línea 146... Línea 142...
146
  const handleNotSeenMessage = (entity) => {
142
  const handleNotSeenMessage = (entity) => {
Línea 314... Línea 310...
314
            key={entity.id}
310
            key={entity.id}
315
            entity={entity}
311
            entity={entity}
316
            not_seen_messages={entity.not_seen_messages}
312
            not_seen_messages={entity.not_seen_messages}
317
            index={index}
313
            index={index}
318
            onClose={handleCloseConversation}
314
            onClose={handleCloseConversation}
319
            onMinimize={handleMinimizeChat}
315
            onMinimize={handleMinimizeConversation}
320
            onRead={handleReadConversation}
316
            onRead={handleReadConversation}
321
            loading={loading}
317
            loading={loading}
322
          />
318
          />
323
        ))}
319
        ))}
324
      </div>
320
      </div>