Skip to content

Commit

Permalink
add fullscreen controls
Browse files Browse the repository at this point in the history
  • Loading branch information
naueramant committed May 22, 2024
1 parent 77f75a9 commit ab4823c
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/views/Game/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import {
Typography,
useTheme,
} from "@mui/material";
import { FunctionComponent, useEffect, useState } from "react";
import { FunctionComponent, useEffect, useRef, useState } from "react";
import { AiOutlineFullscreen, AiOutlineFullscreenExit } from "react-icons/ai";
import { IoExitOutline } from "react-icons/io5";
import { useNavigate } from "react-router-dom";
import { useFullscreen, useToggle } from "react-use";
import { useSounds } from "../../../hooks/sounds";
import useGame from "../../../stores/game";
import { useGameMetrics } from "../../../stores/metrics";
Expand All @@ -23,6 +25,15 @@ const Header: FunctionComponent = () => {
const theme = useTheme();
const navigate = useNavigate();

const [fullscreen, toggleFullscreen] = useToggle(false);
const isFullscreen = useFullscreen(
useRef(document.documentElement),
fullscreen,
{
onClose: () => toggleFullscreen(false),
},
);

const sound = useSounds();

const game = useGame((state) => ({
Expand Down Expand Up @@ -208,7 +219,25 @@ const Header: FunctionComponent = () => {
</IconButton>
</Tooltip> */}

<Tooltip title="Exit game" placement="left">
<Tooltip
title={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
placement="bottom"
>
<IconButton
sx={{
color: "primary.contrastText",
}}
onClick={toggleFullscreen}
>
{isFullscreen ? (
<AiOutlineFullscreenExit />
) : (
<AiOutlineFullscreen />
)}
</IconButton>
</Tooltip>

<Tooltip title="Exit game" placement="bottom">
<IconButton
sx={{
color: "primary.contrastText",
Expand Down

0 comments on commit ab4823c

Please sign in to comment.