Skip to content

Commit

Permalink
feat: bring back button to full-screen
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanlundberg committed Nov 6, 2024
1 parent 1f82db4 commit c5f0765
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 59 deletions.
7 changes: 7 additions & 0 deletions src/components/navigation/buttons/button-navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
CircleIcon,
CubeIcon,
DesktopIcon,
EnterFullScreenIcon,
FileIcon,
GearIcon,
MixerHorizontalIcon,
Expand All @@ -36,6 +37,7 @@ import { useRouter } from "next/navigation";
import { useTheme } from "next-themes";
import genId from "@/lib/genId";
import { useTranslations } from "next-intl";
import { useFullScreen } from "@/hooks/useFullScreen";

interface ListItem {
icon: React.ReactNode;
Expand All @@ -52,6 +54,7 @@ export default function ButtonNavbar() {
const t = useTranslations("Index");
const [open, setOpen] = React.useState(false);
const { setTheme } = useTheme();
const { toggleFullScreen } = useFullScreen();
React.useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
Expand Down Expand Up @@ -221,6 +224,10 @@ export default function ButtonNavbar() {
/>
);
})}
<CommandItem onSelect={() => toggleFullScreen()}>
<EnterFullScreenIcon />
Fullscreen
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading={t("SettingsPage.account")}>
Expand Down
25 changes: 0 additions & 25 deletions src/components/timer/FullscreenOption.tsx

This file was deleted.

35 changes: 1 addition & 34 deletions src/hooks/useFullScreen.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
import { useState, useEffect } from "react";

export function useFullScreen() {
const [isFullScreen, setIsFullScreen] = useState<boolean>(true);

useEffect(() => {
const handleFullScreenChange = () => {
setIsFullScreen(!!document.fullscreenElement);
};

handleFullScreenChange();

document.addEventListener("fullscreenchange", handleFullScreenChange);
document.addEventListener("mozfullscreenchange", handleFullScreenChange);
document.addEventListener("webkitfullscreenchange", handleFullScreenChange);
document.addEventListener("msfullscreenchange", handleFullScreenChange);

return () => {
document.removeEventListener("fullscreenchange", handleFullScreenChange);
document.removeEventListener(
"mozfullscreenchange",
handleFullScreenChange
);
document.removeEventListener(
"webkitfullscreenchange",
handleFullScreenChange
);
document.removeEventListener(
"msfullscreenchange",
handleFullScreenChange
);
};
}, []);

const toggleFullScreen = () => {
const element = document.documentElement;

Expand Down Expand Up @@ -62,5 +29,5 @@ export function useFullScreen() {
}
};

return { isFullScreen, toggleFullScreen };
return { toggleFullScreen };
}

0 comments on commit c5f0765

Please sign in to comment.