瀏覽代碼

min-widht height and appbar visble

amenpunk 3 年之前
父節點
當前提交
8d9d8b6fa2

+ 5 - 0
psicoadmin/src/App.css

@@ -123,3 +123,8 @@
123 123
     padding : 15px;
124 124
     margin: 0px;
125 125
 }
126
+.content-section{
127
+    min-height:100vh !important;
128
+}
129
+
130
+

+ 193 - 0
psicoadmin/src/Components/AppBar.js

@@ -0,0 +1,193 @@
1
+import React, { useEffect, useState, useRef } from 'react';
2
+import { styled, createTheme, ThemeProvider } from '@mui/material/styles';
3
+import useAuth from '../Auth/useAuth';
4
+import { Outlet, useNavigate} from "react-router-dom";
5
+
6
+import Typography from '@mui/material/Typography';
7
+import IconButton from '@mui/material/IconButton';
8
+import MenuIcon from '@mui/icons-material/Menu';
9
+import Menu from '@mui/material/Menu';
10
+// import Container from '@mui/material/Container';
11
+import Badge from '@mui/material/Badge';
12
+import Avatar from '@mui/material/Avatar';
13
+import FullscreenIcon from '@mui/icons-material/Fullscreen';
14
+
15
+import MenuItem from '@mui/material/MenuItem';
16
+import MailIcon from '@mui/icons-material/Mail';
17
+import ProfilePicture from '../Images/man.png';
18
+import MuiAppBar from '@mui/material/AppBar';
19
+import NotificationsIcon from '@mui/icons-material/Notifications';
20
+import Toolbar from '@mui/material/Toolbar';
21
+import Box from '@mui/material/Box';
22
+
23
+const drawerWidth = 240;
24
+
25
+const useCheckMobileScreen = () => {
26
+    const [width, setWidth] = useState(window.innerWidth);
27
+    const handleWindowSizeChange = () => {
28
+        let size = window.innerWidth;
29
+        setWidth(size);
30
+    }
31
+
32
+    useEffect(() => {
33
+        window.addEventListener('resize', handleWindowSizeChange);
34
+        return () => {
35
+            window.removeEventListener('resize', handleWindowSizeChange);
36
+        }
37
+    }, []);
38
+
39
+    let isMobile = width <= 1000
40
+
41
+    return (isMobile);
42
+}
43
+
44
+const AppBar = styled(MuiAppBar, {
45
+    shouldForwardProp: (prop) => prop !== 'open',
46
+})(({ theme, open }) => ({
47
+    transition: theme.transitions.create(['margin', 'width'], {
48
+        easing: theme.transitions.easing.sharp,
49
+        duration: theme.transitions.duration.leavingScreen,
50
+    }),
51
+    ...(open && {
52
+        width: `calc(100% - ${drawerWidth}px)`,
53
+        marginLeft: `${drawerWidth}px`,
54
+        transition: theme.transitions.create(['margin', 'width'], {
55
+            easing: theme.transitions.easing.easeOut,
56
+            duration: theme.transitions.duration.enteringScreen,
57
+        }),
58
+    }),
59
+}));
60
+
61
+export default function AppBarComponent (){
62
+
63
+    const [open, setOpen] = React.useState(true);
64
+    const elRef = useRef();
65
+
66
+
67
+    const auth = useAuth();
68
+    const navigate = useNavigate()
69
+    const [anchorEl, setAnchorEl] = React.useState(null);
70
+
71
+    const [anchorElMovil, setAnchorElMov] = React.useState(null);
72
+
73
+    const toggleDrawer = () => setOpen(!open);
74
+    const open_profile = Boolean(anchorEl);
75
+    const handleClick = (event) => setAnchorEl(event.currentTarget);
76
+    const handleClose = () => setAnchorEl(null)
77
+    const openMov = Boolean(anchorElMovil);
78
+    const handleCloseMov = () => {
79
+        setAnchorElMov(null);
80
+    };
81
+
82
+    const MenuResponsive = ()  => {
83
+        setAnchorElMov(elRef.current);
84
+    } 
85
+
86
+    const CerrarSession = () => {
87
+        console.log('cerrando session')
88
+        // auth.logout();
89
+        // navigate('/')
90
+    } 
91
+
92
+    return(
93
+        <AppBar 
94
+            style={{ backgroundColor : '#fff', boxShadow : 'None' }} 
95
+            position="fixed" 
96
+            open={useCheckMobileScreen() ? false : open} >
97
+
98
+            <Toolbar sx={{ borderBottom : "1px solid #ec5e69"}} >
99
+
100
+                <div ref={elRef}>
101
+                    <IconButton 
102
+                        edge="start" 
103
+                        color="inherit" 
104
+                        aria-label="open drawer" 
105
+                        onClick={ useCheckMobileScreen() ? MenuResponsive : toggleDrawer } 
106
+                        sx={{ marginRight: '36px', ...( !useCheckMobileScreen() && open && { display: 'none' }), }} >
107
+                        <MenuIcon  style={{
108
+                            background: '#ec5e69',
109
+                            fontSize: "40",
110
+                            color: "#fff"
111
+                        }}/>
112
+                    </IconButton>
113
+
114
+                    <Menu
115
+                        id="basic-menu"
116
+                        anchorEl={anchorElMovil}
117
+                        open={openMov}
118
+                        onClose={handleCloseMov}
119
+                        MenuListProps={{
120
+                            'aria-labelledby': 'basic-button',
121
+                        }}>
122
+                        <MenuItem onClick={ () => navigate('/perfil') }>Perfil</MenuItem>
123
+                        <MenuItem onClick={handleCloseMov}>My account</MenuItem>
124
+                        <MenuItem onClick={handleCloseMov}>Logout</MenuItem>
125
+                    </Menu>
126
+
127
+                </div>
128
+
129
+                <Typography component="h1" variant="h6" color="inherit" noWrap sx={{ flexGrow: 1 }} >
130
+                    {
131
+                        !useCheckMobileScreen() && open ? (
132
+                            <React.Fragment>
133
+
134
+                                <IconButton onClick={toggleDrawer}>
135
+                                    <MenuIcon />
136
+                                </IconButton>
137
+
138
+                                <IconButton onClick={ (event) =>  event.target.requestFullscreen() }>
139
+                                    <FullscreenIcon style={{ paddinLeft : 15 }}/>
140
+                                </IconButton>
141
+
142
+
143
+                            </React.Fragment>
144
+                        ) : undefined
145
+                    }
146
+                </Typography>
147
+
148
+
149
+                <Box sx={{ display: { xs: 'none', md: 'flex' } }}>
150
+                    <IconButton size="large" aria-label="show 4 new mails" color="inherit">
151
+                        <Badge badgeContent={4} color="error">
152
+                            <MailIcon style={{ color : '#212529' }} />
153
+                        </Badge>
154
+                    </IconButton>
155
+                    <IconButton
156
+                        size="large"
157
+                        aria-label="show 17 new notifications"
158
+                        color="inherit">
159
+                        <Badge badgeContent={17} color="error">
160
+                            <NotificationsIcon style={{ color : '#212529' }}/>
161
+                        </Badge>
162
+                    </IconButton>
163
+
164
+
165
+                    <IconButton
166
+                        size="small"
167
+                        edge="end"
168
+                        aria-label="account of current user"
169
+                        aria-haspopup="true"
170
+                        aria-expanded={open_profile ? 'true' : undefined}
171
+                        onClick={handleClick}
172
+                        color="inherit"
173
+                    >
174
+                        <Avatar alt="Cindy Baker" src={ProfilePicture} />
175
+
176
+                    </IconButton>
177
+                    <Menu
178
+                        id="basic-menu"
179
+                        anchorEl={anchorEl}
180
+                        open={open_profile}
181
+                        onClose={handleClose}
182
+                        MenuListProps={{ 'aria-labelledby': 'basic-button', }}>
183
+                        <MenuItem onClick={() => navigate('perfil') }>Profile</MenuItem>
184
+                        <MenuItem onClick={() => console.log('opcion 2')}>My account</MenuItem>
185
+                        <MenuItem onClick={CerrarSession}>Logout</MenuItem>
186
+                    </Menu>
187
+
188
+                </Box>
189
+
190
+            </Toolbar>
191
+        </AppBar>
192
+    )
193
+}

+ 1 - 1
psicoadmin/src/Components/Dashboard.js

@@ -250,7 +250,7 @@ function DashboardContent() {
250 250
                     </Toolbar>
251 251
                     <Divider />
252 252
                     <List>
253
-                        <MainListItems/>
253
+                        <MainListItems AppBarVisible={open} />
254 254
                     </List>
255 255
                     <Divider />
256 256
                     <List>

+ 20 - 6
psicoadmin/src/Components/listItems.js

@@ -68,7 +68,7 @@ function Item (props) {
68 68
 
69 69
     function change (event){
70 70
         props.change(event, props.index)
71
-        console.log('is logged', auth.isLogged())
71
+        // console.log('is logged', auth.isLogged())
72 72
 
73 73
         if(!auth.isLogged()){
74 74
             return navigate('/')
@@ -104,9 +104,10 @@ function Item (props) {
104 104
 }
105 105
 
106 106
 
107
-export const MainListItems = () =>  {
107
+export const MainListItems = (props) =>  {
108 108
 
109 109
     const [selectedIndex, setSelectedIndex] = React.useState(0);
110
+    let SubMenuIndex = [5,6,7,8,9] 
110 111
 
111 112
 
112 113
     const handleListItemClick = (event, index) => {
@@ -116,10 +117,23 @@ export const MainListItems = () =>  {
116 117
     const [open, setOpen] = React.useState(false);
117 118
 
118 119
     const showPruebas = () => {
119
-        handleListItemClick(-1)
120
-        setOpen(!open);
120
+        console.log(props ,open,  selectedIndex   )
121
+        if(props.AppBarVisible){
122
+            // handleListItemClick(-1)
123
+            setOpen(!open);
124
+        }
121 125
     };
122 126
 
127
+    React.useEffect(() => {
128
+        if(!props.AppBarVisible && open){
129
+            setOpen(false)
130
+        }else{
131
+            if( SubMenuIndex.includes(selectedIndex)  ){
132
+                setOpen(true)
133
+            }
134
+        }
135
+    },[props,  selectedIndex])
136
+
123 137
 
124 138
     return(
125 139
         <List>
@@ -131,8 +145,8 @@ export const MainListItems = () =>  {
131 145
             <Item icon={<EqualizerIcon/>} selected={selectedIndex}  change={handleListItemClick} index={4} title="Resultados" route="resultados" />
132 146
             {/* <Item icon={<FingerprintIcon/>} selected={selectedIndex}  change={handleListItemClick} index={5} title="Pruebas" route="/pruebas" /> */}
133 147
 
134
-
135
-            <ListItem  onClick={showPruebas}>
148
+           <ListItem selected={  SubMenuIndex.includes(selectedIndex) && !props.AppBarVisible} onClick={showPruebas}>
149
+           {/* <ListItem selected={  SubMenuIndex.includes(selectedIndex)j } onClick={showPruebas}> */}
136 150
                 <ListItemIcon>
137 151
                     <FingerprintIcon />
138 152
                 </ListItemIcon>

+ 5 - 1
psicoadmin/src/Pages/Contras.js

@@ -1,5 +1,9 @@
1 1
 export function Contras() {
2 2
     return (
3
-        <h1>Passwords</h1>
3
+        <div className="content-section">
4
+            <div className="main">
5
+                <h1>Passwords</h1>
6
+            </div>
7
+        </div>
4 8
     )
5 9
 }

+ 5 - 1
psicoadmin/src/Pages/Expedientes.js

@@ -1,5 +1,9 @@
1 1
 export function Expedientes() {
2 2
     return (
3
-        <h1>Expedientes</h1>
3
+        <div className="content-section">
4
+            <div className="main">
5
+                <h1>Expedientes</h1>
6
+            </div>
7
+        </div>
4 8
     )
5 9
 }

+ 5 - 1
psicoadmin/src/Pages/Resultados.js

@@ -1,5 +1,9 @@
1 1
 export function Resultados() {
2 2
     return (
3
-        <h1>Resultados</h1>
3
+        <div className="content-section">
4
+            <div className="main">
5
+                <h1>Resultados</h1>
6
+            </div>
7
+        </div>
4 8
     )
5 9
 }