diff --git a/src/components/Chat.js b/src/components/Chat.js index 93fa95e..af178f3 100644 --- a/src/components/Chat.js +++ b/src/components/Chat.js @@ -24,9 +24,15 @@ import { UserContext } from "../context"; const useStyles = makeStyles((theme) => ({ chatPanel: { + height: "var(--chat-height, auto)", display: "flex", flexDirection: "column", }, + chatHidden: { + [theme.breakpoints.down("sm")]: { + height: "auto !important", + }, + }, chatHeader: { transition: "text-shadow 0.5s", "&:hover": { @@ -94,6 +100,7 @@ function Chat({ const [input, setInput] = useState(""); const [menuOpenIdx, setMenuOpenIdx] = useState(null); const [chatHidden, setChatHidden] = useStorage("chat-hidden", "no"); + const isHidden = chatHidden === "yes"; const databasePath = gameId ? `chats/${gameId}` : "lobbyChat"; const messagesQuery = useMemo( @@ -105,7 +112,7 @@ function Chat({ .limitToLast(messageLimit), [databasePath, messageLimit] ); - const messages = useFirebaseQuery(messagesQuery); + const messages = useFirebaseQuery(isHidden ? null : messagesQuery); const mentionRE = useMemo(() => makeMentionRE(user.name), [user.name]); const addMentioned = (cls, message) => { @@ -128,7 +135,7 @@ function Chat({ } function toggleChat() { - setChatHidden(chatHidden === "yes" ? "no" : "yes"); + setChatHidden(isHidden ? "no" : "yes"); } const [anchorEl, setAnchorEl] = useState(null); @@ -194,11 +201,11 @@ function Chat({ return (
- {title} {chatHidden === "yes" && "(Hidden)"} + {title} {isHidden && "(Hidden)"} {Object.entries(items) @@ -212,70 +219,70 @@ function Chat({ startedAt={startedAt} /> ) : ( - chatHidden !== "yes" && ( -
- {timeTooltip( - item.time, - - {formatTime(item.time)} - - : {item.message} - - )} - {user.admin && ( - handleClickVertIcon(e, key)} +
+ {timeTooltip( + item.time, + + {formatTime(item.time)} + - )} + : {item.message} + + )} + {user.admin && ( + handleClickVertIcon(e, key)} + /> + )} - - handleDelete(key)}> - Delete message - - handleDeleteAll(item.user)}> - Delete all from user - - -
- ) + + handleDelete(key)}> + Delete message + + handleDeleteAll(item.user)}> + Delete all from user + + +
) )}
-
- - setInput(e.target.value)} - placeholder="Type a message..." - maxLength={250} - disabled={chatDisabled} - /> - -
+ {!isHidden && ( +
+ + setInput(e.target.value)} + placeholder="Type a message..." + maxLength={250} + disabled={chatDisabled} + /> + +
+ )}
); } diff --git a/src/hooks/useFirebaseQuery.js b/src/hooks/useFirebaseQuery.js index 1326d1d..b4d6bcb 100644 --- a/src/hooks/useFirebaseQuery.js +++ b/src/hooks/useFirebaseQuery.js @@ -8,6 +8,8 @@ function useFirebaseQuery(query) { const state = useRef({}); useEffect(() => { + if (!query) return; + function update() { clearInterval(timer.current); timer.current = setTimeout(() => { diff --git a/src/pages/LobbyPage.js b/src/pages/LobbyPage.js index 7fafee8..29a8d62 100644 --- a/src/pages/LobbyPage.js +++ b/src/pages/LobbyPage.js @@ -35,7 +35,7 @@ const useStyles = makeStyles((theme) => ({ "--table-height": "480px", }, [theme.breakpoints.up("md")]: { - "--table-height": "calc(min(100vh - 140px, 720px))", + "--table-height": "calc(min(100vh - 200px, 720px))", }, }, gamesTable: { @@ -64,37 +64,30 @@ const useStyles = makeStyles((theme) => ({ }, }, gameCounters: { - "& > p": { - marginBottom: "0.2em", - }, - [theme.breakpoints.up("sm")]: { - position: "absolute", - bottom: 4, - }, - [theme.breakpoints.down("xs")]: { - marginTop: 4, - display: "flex", - justifyContent: "space-between", + margin: "1.2em 0.2em 0.2em 0.2em", + display: "flex", + justifyContent: "space-between", + [theme.breakpoints.down("sm")]: { + order: -1, + margin: "0 0.2em 1em 0.2em", }, }, actionButtons: { - [theme.breakpoints.up("sm")]: { - height: "100%", - display: "flex", - flexDirection: "column", - justifyContent: "center", - "& button": { - margin: "12px 0", - }, + display: "flex", + margin: "1em 0 1em 0", + "& button:first-of-type": { + marginRight: "0.5em", }, - [theme.breakpoints.down("xs")]: { - "& button": { - marginBottom: theme.spacing(1), - }, + "& button:last-of-type": { + marginLeft: "0.5em", + }, + [theme.breakpoints.down("sm")]: { + marginBottom: "0.2em", }, }, chatColumn: { - maxHeight: "calc(var(--table-height) + 16px)", + display: "flex", + flexDirection: "column", [theme.breakpoints.up("md")]: { marginTop: 36, }, @@ -103,18 +96,10 @@ const useStyles = makeStyles((theme) => ({ padding: 8, display: "flex", flexDirection: "column", - height: "100%", - }, - chatPanel: { - display: "flex", - flexDirection: "column", + "--chat-height": "calc(var(--table-height) - 16px)", }, - buttonColumn: { - position: "relative", - maxHeight: "calc(var(--table-height) + 16px)", - [theme.breakpoints.up("sm")]: { - marginTop: 36, - }, + gamesColumn: { + paddingBottom: "0 !important", }, })); @@ -195,15 +180,33 @@ function LobbyPage() { return ( - - + + +
+ + + {loadingStats + ? "---" + : humanize((stats && stats.onlineUsers) || 0)} + {" "} + users online + + + + {loadingStats + ? "---,---" + : humanize((stats && stats.gameCount) || 0)} + {" "} + games played + +
- - + + - - - -
-
- - - {loadingStats - ? "---" - : humanize((stats && stats.onlineUsers) || 0)} - {" "} - users online - - - - {loadingStats - ? "---,---" - : humanize((stats && stats.gameCount) || 0)} - {" "} - games played - -