-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add page exceptions and move pages to pages folder * move timerlist component * add page exceptions and move pages to pages folder * checkin * Created RoomList component * Center roomList component * fix css and add more public page func (#82) * remove css * fix table * checkin * checkin * checkin * checkin * checkin * Update App.tsx * Update RoomList.styled.tsx * checkin
- Loading branch information
Showing
29 changed files
with
733 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useContext, useEffect, useState } from "react"; | ||
import { ThemeContext } from "styled-components"; | ||
import socket from "../../components/Socket/socket"; | ||
import { Centered } from "./StatRoom.styled"; | ||
import Header from "../../components/Header/Header"; | ||
|
||
import { theme } from "../../../common/theme"; | ||
import Footer from "../../components/Footer/Footer"; | ||
import ConnectionState from "../../components/ConnectionState/ConnectionState"; | ||
|
||
import PublicRoomRouter from "./PublicRoomRouter"; | ||
import { AdminContext } from "../../../common/common"; | ||
import { ITimerRooms } from "../../components/RoomList/RoomList"; | ||
import { GlobalStyle } from "../../components/Room/Room.styled"; | ||
|
||
export interface IPublicRoom { | ||
isBreak: boolean; | ||
globalUsersConnected: number; | ||
isConnected: boolean; | ||
roomName: string; | ||
} | ||
|
||
export const PublicRoom = (props: IPublicRoom): JSX.Element => { | ||
const { isBreak, globalUsersConnected, isConnected, roomName } = props; | ||
const [timerRooms, setTimerRooms] = useState<ITimerRooms[]>([]); | ||
|
||
const isAdminMode = useContext<boolean>(AdminContext); | ||
|
||
const onPublicTimers = ({ | ||
roomStats, | ||
}: { | ||
roomStats: ITimerRooms[]; | ||
}): void => { | ||
setTimerRooms(roomStats); | ||
}; | ||
|
||
const { themeGroup } = useContext(ThemeContext); | ||
|
||
const { workBackground, breakBackground } = | ||
theme[themeGroup as keyof typeof theme]; | ||
|
||
useEffect(() => { | ||
socket.on("publicTimers", onPublicTimers); | ||
|
||
return () => { | ||
socket.off("publicTimers", onPublicTimers); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<Header isBreak={isBreak} /> | ||
<GlobalStyle | ||
backColor={!isBreak ? workBackground : breakBackground} | ||
/> | ||
<Centered> | ||
<PublicRoomRouter | ||
isBreak={isBreak} | ||
globalUsersConnected={globalUsersConnected} | ||
isConnected={isConnected} | ||
roomName={roomName} | ||
isAdminMode={isAdminMode} | ||
timerRooms={timerRooms} | ||
/> | ||
</Centered> | ||
<Footer | ||
numUsers={globalUsersConnected} | ||
isBreak={isBreak} | ||
connectionStatus={<ConnectionState isConnected={isConnected} />} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { ThemeContext } from "styled-components"; | ||
import { useContext } from "react"; | ||
|
||
import { IPublicRoom } from "./PublicRoom"; | ||
import { theme } from "../../../common/theme"; | ||
import { StyledTitle } from "./StatRoom.styled"; | ||
import RoomList, { ITimerRooms } from "../../components/RoomList/RoomList"; | ||
import DefaultRoom from "../../components/DefaultRoom/DefaultRoom"; | ||
|
||
interface IPublicRoomRouter extends IPublicRoom { | ||
isAdminMode: boolean; | ||
timerRooms: ITimerRooms[]; | ||
} | ||
|
||
const PublicRoomRouter = (props: IPublicRoomRouter): JSX.Element => { | ||
const { | ||
isBreak, | ||
globalUsersConnected, | ||
isConnected, | ||
roomName, | ||
isAdminMode, | ||
timerRooms, | ||
} = props; | ||
|
||
const { themeGroup } = useContext(ThemeContext); | ||
|
||
const { workGrey } = theme[themeGroup as keyof typeof theme]; | ||
|
||
if (roomName === "public-timers") { | ||
return ( | ||
<> | ||
<StyledTitle color={workGrey}>Public Timers</StyledTitle> | ||
<RoomList | ||
rooms={timerRooms} | ||
isBreak={isBreak} | ||
isAdminMode={isAdminMode} | ||
roomName={roomName} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
if (roomName === "admin") { | ||
if (isAdminMode) { | ||
return ( | ||
<> | ||
<StyledTitle color={workGrey}>Admin</StyledTitle> | ||
<RoomList | ||
rooms={timerRooms} | ||
isBreak={isBreak} | ||
isAdminMode={isAdminMode} | ||
roomName={roomName} | ||
/> | ||
</> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<DefaultRoom | ||
globalUsersConnected={globalUsersConnected} | ||
isBreak={isBreak} | ||
isConnected={isConnected} | ||
/> | ||
); | ||
}; | ||
|
||
export default PublicRoomRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import styled from "styled-components"; | ||
|
||
export const Centered = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
flex-direction: column; | ||
`; | ||
|
||
export const StyledTitle = styled.h2<{ color: string }>` | ||
color: ${({ color }): string => color}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useEffect } from "react"; | ||
import socket from "../../components/Socket/socket"; | ||
import { PublicRoom } from "./PublicRoom"; | ||
|
||
interface IStatRoomRouterProps { | ||
setIsConnected: (isConnected: boolean) => void; | ||
roomName: string; | ||
userName: string; | ||
isBreak: boolean; | ||
globalUsersConnected: number; | ||
isConnected: boolean; | ||
} | ||
|
||
const StatRoomRouter = (props: IStatRoomRouterProps): JSX.Element => { | ||
const { | ||
setIsConnected, | ||
roomName, | ||
userName, | ||
isBreak, | ||
globalUsersConnected, | ||
isConnected, | ||
} = props; | ||
|
||
const onConnect = (): void => { | ||
socket.emit("join", { roomName, userName: userName || "defaultUser" }); | ||
setIsConnected(true); | ||
}; | ||
|
||
const onDisconnect = (): void => { | ||
setIsConnected(false); | ||
}; | ||
|
||
useEffect(() => { | ||
socket.on("connect", onConnect); | ||
socket.on("disconnect", onDisconnect); | ||
|
||
return () => { | ||
socket.off("connect", onConnect); | ||
socket.off("disconnect", onDisconnect); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<PublicRoom | ||
isBreak={isBreak} | ||
globalUsersConnected={globalUsersConnected} | ||
isConnected={isConnected} | ||
roomName={roomName} | ||
/> | ||
); | ||
}; | ||
|
||
export default StatRoomRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.