Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3602 | Rev 3604 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3599 stevensc 1
import React, { useState } from 'react';
2
import { Grid, Box, Typography } from '@mui/material';
3577 stevensc 3
 
3599 stevensc 4
import { useFetch, usePagination } from '@shared/hooks';
3581 stevensc 5
 
3580 stevensc 6
import { Spinner } from '@shared/components';
3599 stevensc 7
import { ConversationsList, MessagesList } from '@inmail/components';
3580 stevensc 8
 
3577 stevensc 9
export function InmailPage() {
3580 stevensc 10
  const [selectedConversation, setSelectedConversation] = useState(null);
11
 
3597 stevensc 12
  const { data: conversations, loading } = useFetch('/email');
3599 stevensc 13
  const {
14
    items: messages,
3603 stevensc 15
    isLoading: loadingMessages,
16
    hasMore,
17
    nextPage
3599 stevensc 18
  } = usePagination(selectedConversation?.messages_url, {
3603 stevensc 19
    resetOnUrlChange: true,
20
    autoLoadFirstPage: true
3599 stevensc 21
  });
3577 stevensc 22
 
3599 stevensc 23
  // Para demostración, usar datos de prueba cuando no hay conversación seleccionada
3603 stevensc 24
  const displayMessages = selectedConversation && messages;
25
  const displayLoading = selectedConversation && loadingMessages;
26
  const displayHasMore = selectedConversation && hasMore;
3580 stevensc 27
 
3578 stevensc 28
  if (loading || !conversations) {
3577 stevensc 29
    return <Spinner />;
30
  }
31
 
32
  return (
3599 stevensc 33
    <Grid container spacing={2} sx={{ height: 'calc(100vh - 100px)' }}>
3577 stevensc 34
      <Grid item xs={12} md={3}>
3580 stevensc 35
        <ConversationsList
36
          conversations={conversations}
37
          onSelectConversation={setSelectedConversation}
3577 stevensc 38
        />
39
      </Grid>
40
      <Grid item xs={12} md={9}>
3599 stevensc 41
        <Box sx={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
42
          {selectedConversation && (
43
            <Box sx={{ p: 2, borderBottom: 1, borderColor: 'divider' }}>
44
              <Typography variant='h6'>Conversación con {selectedConversation.name}</Typography>
45
            </Box>
46
          )}
47
          <Box sx={{ flex: 1, overflow: 'hidden' }}>
48
            <MessagesList
49
              messages={displayMessages}
50
              onLoadMore={nextPage}
51
              loading={displayLoading}
3603 stevensc 52
              hasMore={displayHasMore}
3599 stevensc 53
            />
54
          </Box>
55
        </Box>
3577 stevensc 56
      </Grid>
57
    </Grid>
58
  );
59
}