Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6946 | Rev 6960 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 6946 Rev 6956
Línea 1... Línea -...
1
import React, { useCallback, useEffect, useState } from 'react'
-
 
2
import { axios } from '../../utils'
1
import React from 'react'
3
import { useSelector } from 'react-redux'
2
import { useSelector } from 'react-redux'
4
import { Avatar, Tab, Tabs } from '@mui/material'
-
 
5
import styled from 'styled-components'
3
import styled from 'styled-components'
6
import SearchIcon from '@mui/icons-material/Search'
4
import Avatar from '@mui/material/Avatar'
Línea 7... Línea 5...
7
 
5
 
8
import Options from '../UI/Option'
6
import Options from '../UI/Option'
9
import EmptySection from '../UI/EmptySection'
-
 
10
import ContactsModal from '../modals/ContactsModal'
-
 
11
import CreateGroupModal from '../modals/CreateGroupModal'
-
 
12
 
-
 
Línea 13... Línea 7...
13
const notifyAudio = new Audio('/audio/chat.mp3')
7
import EmptySection from '../UI/EmptySection'
14
 
8
 
15
const StyledContact = styled.div`
9
const StyledContact = styled.div`
16
  align-items: center;
10
  align-items: center;
Línea 31... Línea 25...
31
    overflow: hidden;
25
    overflow: hidden;
32
    text-overflow: ellipsis;
26
    text-overflow: ellipsis;
33
    max-width: 20ch;
27
    max-width: 20ch;
34
  }
28
  }
35
`
29
`
36
const StyledTab = styled(Tab)`
-
 
37
  flex-grow: 1;
-
 
38
  color: var(--subtitle-color) !important;
-
 
39
  font-weight: bold !important;
-
 
40
  padding: 0.5rem 1rem !important;
-
 
41
  min-height: auto !important;
-
 
42
  &.Mui-selected {
-
 
43
    color: var(--font-color) !important;
-
 
44
  }
-
 
45
`
-
 
46
 
-
 
47
const Contacts = ({ selectedConversation, changeConversation }) => {
-
 
48
  const [showContactModal, setShowContactModal] = useState(false)
-
 
49
  const [showGroupModal, setShowGroupModal] = useState(false)
-
 
50
  const [conversations, setConversations] = useState([])
-
 
51
  const [search, setSearch] = useState('')
-
 
52
  const [tab, setTab] = useState('user')
-
 
53
 
-
 
54
  const options = [
-
 
55
    {
-
 
56
      label: 'Iniciar conversación',
-
 
57
      action: () => setShowContactModal(!showContactModal),
-
 
58
    },
-
 
59
    { label: 'Crear grupo', action: () => setShowGroupModal(!showGroupModal) },
-
 
60
  ]
-
 
61
 
-
 
62
  const onCreateConversation = (url) => {
-
 
63
    const conversation = conversations.find((user) => user.url_send === url)
-
 
64
    changeConversation(conversation)
-
 
65
  }
-
 
66
 
-
 
67
  const heartBeat = async () => {
-
 
68
    axios.get('/chat/heart-beat').then((response) => {
-
 
69
      const { data: entities, success } = response.data
-
 
70
 
-
 
71
      if (!success) {
-
 
72
        return
-
 
73
      }
-
 
74
 
-
 
75
      entities.map(
-
 
76
        (entity) =>
-
 
77
          entity.not_received_messages &&
-
 
78
          playNewMessage(entity.url_mark_received)
-
 
79
      )
-
 
80
 
-
 
81
      setConversations(entities)
-
 
82
    })
-
 
83
  }
-
 
84
 
-
 
85
  const playNewMessage = async (url) => {
-
 
86
    notifyAudio.play()
-
 
87
    const { data } = await axios.post(url)
-
 
88
    return data.success
-
 
89
  }
-
 
Línea 90... Línea 30...
90
 
30
 
91
  const getConversations = useCallback(
-
 
92
    () => conversations.filter((conversation) => conversation.type === tab),
-
 
93
    [tab, conversations]
-
 
94
  )
-
 
95
 
-
 
96
  const filterConversations = useCallback(
-
 
97
    (conversations) =>
-
 
98
      conversations.filter((conversation) =>
-
 
99
        conversation.name.toLowerCase().includes(search.toLowerCase())
-
 
100
      ),
-
 
101
 
-
 
102
    [search]
-
 
103
  )
-
 
104
 
-
 
105
  useEffect(() => {
31
const Contacts = ({ children }) => {
106
    const heartBeatInterval = setInterval(heartBeat, 3000)
-
 
107
    heartBeat()
32
  return <aside className="chat_contacts">{children}</aside>
108
 
-
 
109
    return () => {
-
 
110
      clearInterval(heartBeatInterval)
-
 
111
    }
-
 
Línea -... Línea 33...
-
 
33
}
112
  }, [])
34
 
113
 
-
 
114
  return (
-
 
115
    <>
35
const Header = ({ options = {}, children }) => {
116
      <aside className="chat_contacts">
-
 
117
        <div className="position-relative">
-
 
118
          <h1>Chat</h1>
-
 
119
          <Options options={options} />
-
 
120
        </div>
-
 
121
 
-
 
122
        <Tabs
-
 
123
          value={tab}
-
 
124
          onChange={(e, newValue) => setTab(newValue)}
-
 
125
          sx={{
-
 
126
            width: '100%',
-
 
127
            minHeight: 'auto',
-
 
128
            '& .MuiTabs-indicator': {
-
 
129
              backgroundColor: 'var(--font-color)',
-
 
130
            },
-
 
131
          }}
-
 
132
        >
-
 
133
          <StyledTab label="Personas" value="user" disableRipple />
-
 
134
          <StyledTab label="Grupos" value="group" disableRipple />
-
 
135
        </Tabs>
-
 
136
 
-
 
137
        <div className="contact__search show">
-
 
138
          <SearchIcon />
-
 
139
          <input
-
 
140
            type="text"
-
 
141
            placeholder="Buscar"
-
 
142
            onChange={(e) => setSearch(e.target.value)}
36
  return (
143
          />
-
 
144
        </div>
-
 
145
 
37
    <div className="position-relative">
146
        <Contacts.List
-
 
147
          contacts={filterConversations(getConversations())}
-
 
148
          onChange={changeConversation}
-
 
149
          currentConversation={selectedConversation}
-
 
150
        />
-
 
151
      </aside>
-
 
152
      <ContactsModal
-
 
153
        show={showContactModal}
-
 
154
        onClose={() => setShowContactModal(false)}
-
 
155
        onComplete={onCreateConversation}
-
 
156
      />
-
 
157
      <CreateGroupModal
-
 
158
        isOpen={showGroupModal}
-
 
159
        onClose={() => setShowGroupModal(false)}
38
      {children}
160
      />
39
      {!!options.length && <Options options={options} />}
161
    </>
40
    </div>
Línea 162... Línea 41...
162
  )
41
  )
163
}
42
}
Línea 199... Línea 78...
199
      <StyledContactInfo>
78
      <StyledContactInfo>
200
        <span>{contact.name}</span>
79
        <span>{contact.name}</span>
201
        {contact.last_message && (
80
        {contact.last_message && (
202
          <p>
81
          <p>
203
            {`${contact.count_not_seen_messages} ${labels.new_messages} |
82
            {`${contact.count_not_seen_messages} ${labels.new_messages} |
204
            ${contact.last_message}`}
83
              ${contact.last_message}`}
205
          </p>
84
          </p>
206
        )}
85
        )}
207
      </StyledContactInfo>
86
      </StyledContactInfo>
208
    </StyledContact>
87
    </StyledContact>
209
  )
88
  )
210
}
89
}
Línea 211... Línea 90...
211
 
90
 
212
List.Item = Item
91
List.Item = Item
-
 
92
Contacts.List = List
Línea 213... Línea 93...
213
Contacts.List = List
93
Contacts.Header = Header