Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 890 Rev 891
Línea 3... Línea 3...
3
import Sidebar from './inmail/sidebar'
3
import Sidebar from './inmail/sidebar'
4
import { axios } from '../utils'
4
import { axios } from '../utils'
5
import { Modal } from 'react-bootstrap'
5
import { Modal } from 'react-bootstrap'
Línea 6... Línea 6...
6
 
6
 
-
 
7
export default props => {
7
export default props => {
8
    const defaultPages = { current: 1, last: 1 }
8
    const [conversations, setConversations] = useState([])
9
    const [conversations, setConversations] = useState([])
9
    const [showConversations, setShowConversations] = useState(false)
10
    const [showConversations, setShowConversations] = useState(false)
10
    const [selectedConversation, setSelectedConversation] = useState(null)
11
    const [selectedConversation, setSelectedConversation] = useState(null)
11
    const [page, setPage] = useState({ current: 1, last: 1 })
12
    const [page, setPage] = useState({ current: 1, last: 1 })
12
    const [messages, setMessages] = useState([])
13
    const [messages, setMessages] = useState([])
13
    const [isGettingMessages, setIsGettingMessages] = useState(false)
14
    const [isGettingMessages, setIsGettingMessages] = useState(false)
14
    const [visible, setVisible] = useState(false)
15
    const [visible, setVisible] = useState(false)
15
    const [searchActive, setSearchActive] = useState(false)
16
    const [searchActive, setSearchActive] = useState(false)
16
    const [inmailPersons, setInmailPersons] = useState([])
17
    const [inmailPersons, setInmailPersons] = useState([])
-
 
18
    const [search, setSearch] = useState('')
17
    const [search, setSearch] = useState('')
19
 
18
    const load = async () => {
20
    const load = async () => {
19
        try {
21
        try {
20
            const res = await axios.get(window.location.href)
22
            const res = await axios.get(window.location.href)
21
            if (res.data.success) {
23
            if (res.data.success) {
22
                setConversations(res.data.data)
24
                setConversations(res.data.data)
23
            }
25
            }
24
        } catch (error) {
26
        } catch (error) {
25
            console.log('>>: error > ', error)
27
            console.log('>>: error > ', error)
26
        }
28
        }
-
 
29
    }
27
    }
30
 
28
    useEffect(() => {
31
    useEffect(() => {
29
        const interval = setInterval(() => {
32
        const interval = setInterval(() => {
30
            load()
33
            load()
31
        }, 3000)
-
 
32
        return () => clearInterval(interval)
-
 
Línea -... Línea 34...
-
 
34
        }, 3000)
-
 
35
 
-
 
36
        return () => {
-
 
37
            clearInterval(interval)
-
 
38
        };
33
    }, [])
39
    }, []);
34
 
40
 
35
    const getMessages = async (conversation = selectedConversation, _page = page.current, justPaginate = false) => {
41
    const getMessages = async (conversation = selectedConversation, _page = defaultPages.current, justPaginate = false) => {
36
        try {
-
 
37
            const res = await axios.get(conversation.messages_link + '?page=' + _page)
-
 
38
            if (justPaginate) {
-
 
39
                setMessages([...messages, ...res.data.data])
-
 
40
            } else {
-
 
41
                setMessages(res.data.data || [])
42
        try {
42
            }
43
            const res = await axios.get(conversation.messages_link + '?page=' + _page)
43
            if (res.data.pagination?.last !== page.last) {
44
            if (res.data.pagination?.last !== page.last) {
44
                setPage({
45
                setPage({
45
                    ...page,
46
                    ...page,
46
                    last: res.data.pagination.last
47
                    last: res.data.pagination.last
-
 
48
                })
-
 
49
            }
-
 
50
            if (justPaginate) {
-
 
51
                setMessages([...res.data.data, ...messages])
-
 
52
            } else {
47
                })
53
                setMessages(res.data.data)
48
            }
54
            }
49
        } catch (error) {
55
        } catch (error) {
50
            console.log('>>: error > ', error)
56
            console.log('>>: error > ', error)
51
        } finally {
57
        } finally {
52
            if (isGettingMessages) {
58
            if (isGettingMessages) {
53
                setIsGettingMessages(false)
59
                setIsGettingMessages(false)
54
            }
60
            }
Línea 55... Línea 61...
55
        }
61
        }
56
    }
62
    }
57
 
63
 
58
    const handleChangeConversation = async conversation => {
64
    const handleChangeConversation = async conversation => {
59
        setPage({current: 1, last:1})
65
        setPage(defaultPages)
Línea 60... Línea 66...
60
        setSelectedConversation(conversation)
66
        setSelectedConversation(conversation)
61
        getMessages(conversation, page.current)
67
        getMessages(conversation, defaultPages.current)
62
    }
68
    }
Línea 69... Línea 75...
69
                }
75
                }
70
                const formData = new FormData();
76
                const formData = new FormData();
71
                Object.entries(params).map(([key, value]) => {
77
                Object.entries(params).map(([key, value]) => {
72
                    formData.append(key, value);
78
                    formData.append(key, value);
73
                });
79
                });
74
                const res = await axios.post(selectedConversation.send_link, formData)
80
                axios.post(selectedConversation.send_link, formData)
75
                setMessages([res.data.data, ...messages])
-
 
76
            } catch (error) {
81
            } catch (error) {
77
                console.log('>>: err0r > ', error)
82
                console.log('>>: err0r > ', error)
78
            } finally {
83
            } finally {
79
                getMessages(selectedConversation, 1)
84
                getMessages(selectedConversation, defaultPages.current)
80
            }
85
            }
81
        }
86
        }
82
    }
87
    }
Línea 83... Línea 88...
83
 
88