Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #115 from Taliayaya/Organisation
Browse files Browse the repository at this point in the history
Organisations
  • Loading branch information
Taliayaya authored Sep 11, 2022
2 parents f64e2f8 + 993c87b commit 4f03245
Show file tree
Hide file tree
Showing 52 changed files with 5,058 additions and 2,009 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"@types/react": ">=16",
"firebase": "^9.6.8",
"firebase": "^9.8.4",
"firebase-admin": "^10.0.2",
"mui": "^0.0.1",
"prettier": "^2.5.1",
Expand All @@ -29,6 +29,7 @@
"react-player": "^2.10.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.0",
"react-swipeable-views": "^0.14.0",
"react-syntax-highlighter": "^15.4.5",
"rehype-katex": "^6.0.2",
"rehype-mathjax": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="La plateforme de communication permettant aux élèves de rester connecter avant, pendant et après les cours en toute sérénité. Rejoignez-nous maintenant !"
content="La plateforme de communication permettant aux élèves de rester connecté avant, pendant et après les cours en toute sérénité. Rejoignez-nous maintenant !"
/>

<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Backgrounds/Summer/SummerStyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const HomePageBanner = styled.div`
height: 100vh;
width: 100vw;
position: relative;
overflow: hidden;
overflow-x: hidden;
`

const HomePagePalmTree = styled.div`
Expand Down
46 changes: 14 additions & 32 deletions src/components/CategorieUser/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
where,
} from 'firebase/firestore'
import { db } from '../../utils/firebase/config'
import Server from '../../utils/server'

function CategorieUser() {
const { currentServer, userList, setUserList } = useChannel()
Expand All @@ -20,21 +21,12 @@ function CategorieUser() {
const usersList = async () => {
if (userList.length === 0 && currentServer?.id) {
// On récupère ici la liste des utilisateurs présents dans le server
const q = query(
collection(db, 'users'),
where('serversid', 'array-contains', currentServer?.id)
)
const querySnapshot = await getDocs(q)
const queryUserList = []
querySnapshot.forEach((doc) => {
const data = { id: doc.id, data: doc.data() }
queryUserList.push(data)
})
const queryUserList = await Server.getUserList(currentServer)

if (queryUserList?.length > 0) {
// On les trie en fonction de leur différente de temps
const userListSorted = queryUserList.sort((a, b) => {
return b.data.data.lastLogin - a.data.data.lastLogin
return b.data.lastLogin - a.data.lastLogin
})
setUserList(userListSorted)
}
Expand All @@ -47,21 +39,11 @@ function CategorieUser() {
useEffect(() => {
const usersListInterval = setInterval(async () => {
// On récupère ici la liste des utilisateurs présents dans le server
const q = query(
collection(db, 'users'),
where('serversid', 'array-contains', currentServer?.id)
)

const querySnapshot = await getDocs(q)
const queryUserList = []
querySnapshot.forEach((doc) => {
const data = { id: doc.id, data: doc.data() }
queryUserList.push(data)
})
const queryUserList = await Server.getUserList(currentServer)
if (queryUserList?.length > 0) {
// On les trie en fonction de leur différente de temps
const userListSorted = queryUserList.sort((a, b) => {
return b.data.data.lastLogin - a.data.data.lastLogin
return b.data.lastLogin - a.data.lastLogin
})
setUserList(userListSorted)
}
Expand All @@ -78,12 +60,12 @@ function CategorieUser() {
// est ce que l'indice précédent était en ligne ?
// Oui -> on n'affiche pas la catégorie
let lastLogin =
Timestamp.fromDate(new Date()) - data.data.lastLogin
Timestamp.fromDate(new Date()) - data.lastLogin
return previousOnline && lastLogin <= 120 ? (
<UserStatus
name={data.data.name}
name={data.name}
datediff={lastLogin}
avatar={data.data.avatar}
avatar={data.avatar}
logged="true"
key={id}
uid={id}
Expand All @@ -94,9 +76,9 @@ function CategorieUser() {
{(previousOnline = true)}
<StyleCategorie>En ligne</StyleCategorie>
<UserStatus
name={data.data.name}
name={data.name}
datediff={lastLogin}
avatar={data.data.avatar}
avatar={data.avatar}
logged="true"
uid={id}
key={id}
Expand All @@ -106,9 +88,9 @@ function CategorieUser() {
previousOffline ? (
// Oui -> on affiche seulement le name
<UserStatus
name={data.data.name}
name={data.name}
datediff={lastLogin}
avatar={data.data.avatar}
avatar={data.avatar}
key={id}
uid={id}
/>
Expand All @@ -118,9 +100,9 @@ function CategorieUser() {
{(previousOffline = true)}
<StyleCategorie>Hors-Ligne</StyleCategorie>
<UserStatus
name={data.data.name}
name={data.name}
datediff={lastLogin}
avatar={data.data.avatar}
avatar={data.avatar}
uid={id}
key={id}
/>
Expand Down
27 changes: 14 additions & 13 deletions src/components/ChannelList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getUserRole } from '../../utils/function'
import ChannelName from '../ChannelName'
import { getDatabase, onValue, ref } from 'firebase/database'
import { askNotification } from '../../utils/notification'
import User from '../../utils/user'

/**
* The left side bar component of the app.
Expand All @@ -27,6 +28,7 @@ function ChannelList() {
const { currentServer, setCurrentServer, channelList, setChannelList } =
useChannel()
const [serverList, setServerList] = useState([])
const [orgaServers, setOrgaServers] = useState([])
const { showChannel, setUserRole } = useAuth()
const auth = getAuth()
const user = auth.currentUser
Expand All @@ -42,7 +44,7 @@ function ChannelList() {
useEffect(() => {
const setRole = async () => {
if (currentServer) {
const role = await getUserRole(user.uid, currentServer?.id)
const role = await User.getRole(user.uid, currentServer?.id)
setUserRole(role?.role)
}
}
Expand All @@ -54,19 +56,16 @@ function ChannelList() {
* Load the server list for the user
*/
const loadServerList = async () => {
if (serverList?.length === 0) {
const userRef = doc(db, 'users', user.uid)
const userSnap = await getDoc(userRef)
if (userSnap.exists()) {
const serverList = userSnap.data().servers
// If the user has joined at least a server
// It will set this one as selected
if (serverList?.length > 0) {
setCurrentServer(serverList[0])
setServerList(serverList)
}
if (serverList?.length > 0) return
User.get(user.uid).then((data) => {
if (data?.servers?.length > 0) {
setCurrentServer(data.servers[0])
setServerList(data.servers)
}
}
if (data?.orgaServers?.length > 0) {
setOrgaServers(data.orgaServers)
}
})
}
loadServerList()
// firstLoadChannel()
Expand Down Expand Up @@ -137,6 +136,8 @@ function ChannelList() {
<LeftMenu
serverList={serverList}
setChannelList={setChannelList}
setShowMenu={setShowMenu}
orgaServers={orgaServers}
/>
</Menu>

Expand Down
6 changes: 5 additions & 1 deletion src/components/ChannelName/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ const ChannelName = ({ id_channel, name, seen, lastMessageData }) => {
setCurrentChannel({ id: id_channel, name: name })
// Reset the message list, so that new messages can be loaded
setMessageList([])
navigate(`${currentServer.name}/${currentServer.id}/${id_channel}`)
let isOrga = currentServer?.isSubServer ?? 'default'
navigate(
`${isOrga}/${currentServer.name}/${currentServer.id}/${id_channel}`
)
}
}

Expand All @@ -74,6 +77,7 @@ const ChannelName = ({ id_channel, name, seen, lastMessageData }) => {
user.uid,
id_channel,
currentServer.id,
currentServer?.isSubServer ?? 'default',
lastMessageData.lastMessageImg,
lastMessageData.lastMessage,
name,
Expand Down
36 changes: 36 additions & 0 deletions src/components/CustomizedSnackBar/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react'
import Stack from '@mui/material/Stack'
import Button from '@mui/material/Button'
import Snackbar from '@mui/material/Snackbar'
import MuiAlert from '@mui/material/Alert'

const Alert = React.forwardRef(function Alert(props, ref) {
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />
})

export default function CustomizedSnackbars({
message,
open,
setOpen,
severity,
}) {
const handleClose = (event, reason) => {
if (reason === 'clickaway') {
return
}

setOpen(false)
}

return (
<Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
<Alert
onClose={handleClose}
severity={severity}
sx={{ width: '100%' }}
>
{message}
</Alert>
</Snackbar>
)
}
8 changes: 3 additions & 5 deletions src/components/Footer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ const StyledFooterLink = styled(Link)`
&:active,
&:focus,
&:hover {
{
color: #3366cc;
text-decoration: none;
}
color: #3366cc;
text-decoration: none;
}
`

Expand All @@ -25,7 +23,7 @@ export default function Footer() {
<address>
<a
className="footer__btn"
href="mailto:pando.contact.mayeux@gmail.com"
href="mailto:apando[email protected]"
>
Nous contacter
</a>
Expand Down
26 changes: 26 additions & 0 deletions src/components/LeftMenu/DisplayServerList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { List, ListItem, ListItemText } from '@mui/material'
import PropTypes from 'prop-types'
import React from 'react'

function DisplayServerList({ serverList, handleSelect, isSubServer = null }) {
return (
<List sx={{ pt: 0 }}>
{serverList.map(({ id, name }) => (
<ListItem
key={id}
button
onClick={() => handleSelect(id, name, isSubServer)}
>
<ListItemText>{name}</ListItemText>
</ListItem>
))}
</List>
)
}

DisplayServerList.propTypes = {
serverList: PropTypes.arrayOf(PropTypes.object).isRequired,
handleSelect: PropTypes.func.isRequired,
}

export default DisplayServerList
82 changes: 82 additions & 0 deletions src/components/LeftMenu/ServerSelection.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
Accordion,
AccordionDetails,
AccordionSummary,
Button,
Dialog,
DialogContent,
DialogTitle,
Divider,
List,
ListItem,
ListItemText,
Typography,
} from '@mui/material'
import React from 'react'
import PropTypes from 'prop-types'
import { ExpandMore } from '@mui/icons-material'
import DisplayServerList from './DisplayServerList'

function ServerSelection({ serverList, handleServerSelect, orgaServers }) {
const [open, setOpen] = React.useState(false)
const handleSelect = (id, name, isSubServer = false) => {
handleServerSelect(id, name, isSubServer)
handleClose()
}

const handleClose = () => {
setOpen(false)
}

return (
<React.Fragment>
<Button onClick={() => setOpen(true)}>Changer de Serveur</Button>
<Dialog onClose={handleClose} open={open} scroll="paper">
<DialogTitle>Selectionner un serveur</DialogTitle>
<DialogContent>
<Typography
sx={{ paddingBottom: 1 }}
color="text.secondary"
variant="body1"
>
Organisations
</Typography>
<Divider />
{orgaServers.map(({ name, servers }) => (
<Accordion sx={{ marginTop: 2 }} key={name}>
<AccordionSummary expandIcon={<ExpandMore />}>
{name}
</AccordionSummary>
<AccordionDetails>
<DisplayServerList
serverList={servers}
handleSelect={handleSelect}
isSubServer={name}
/>
</AccordionDetails>
</Accordion>
))}
<Typography
sx={{ paddingTop: 2, paddingBottom: 1 }}
color="text.secondary"
variant="body1"
>
Serveurs
</Typography>
<Divider />
<DisplayServerList
serverList={serverList}
handleSelect={handleSelect}
/>
</DialogContent>
</Dialog>
</React.Fragment>
)
}

ServerSelection.propTypes = {
handleServerSelect: PropTypes.func.isRequired,
serverList: PropTypes.arrayOf(PropTypes.objectOf(PropTypes.string)),
}

export default ServerSelection
Loading

0 comments on commit 4f03245

Please sign in to comment.