Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

fullscreen button workee wooo fullscreening i lov fullscreening woooo… (#524)

PickleNik725ed4bec31a
diff --git a/apps/web/src/app/challenge/[id]/wrapper.tsx b/apps/web/src/app/challenge/[id]/wrapper.tsx
index a5e538a9..6f5338d8 100644
--- a/apps/web/src/app/challenge/[id]/wrapper.tsx
+++ b/apps/web/src/app/challenge/[id]/wrapper.tsx
@@ -36,9 +36,9 @@ function SettingsElements() {
return (
<>
<ResetEditorButton />
- <FullscreenButton />
- <SettingsButton />
<EditorShortcutsButton />
+ <SettingsButton />
+ <FullscreenButton />
</>
);
}
diff --git a/apps/web/src/app/challenge/_components/challenge-layout.tsx b/apps/web/src/app/challenge/_components/challenge-layout.tsx
index 59a9e5b2..15d0bd80 100644
--- a/apps/web/src/app/challenge/_components/challenge-layout.tsx
+++ b/apps/web/src/app/challenge/_components/challenge-layout.tsx
@@ -3,11 +3,11 @@
import { useEffect, useRef, type ReactNode } from 'react';
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
+import { useFullscreenSettingsStore } from './fullscreen';
export const DEFAULT_SETTINGS = {
width: '500px',
height: '300px',
- isFullscreen: false,
};
type Settings = typeof DEFAULT_SETTINGS;
@@ -39,6 +39,7 @@ export function ChallengeLayout({ left, right }: ChallengeLayoutProps) {
const leftSide = useRef<HTMLDivElement>(null);
const rightSide = useRef<HTMLDivElement>(null);
const { settings, updateSettings } = useLayoutSettingsStore();
+ const { fssettings, updateFSSettings } = useFullscreenSettingsStore();
useEffect(() => {
if (!leftSide.current || !rightSide.current || !resizer.current) {
@@ -159,25 +160,38 @@ export function ChallengeLayout({ left, right }: ChallengeLayoutProps) {
};
}, [settings, updateSettings]);
+ // TODO apply different logic on resizer ref on top if fssettings.isFullscreen
+ // useEffect(() => {
+ // if (!parent.current || !leftSide.current) {
+ // return;
+ // }
+ // const parentRef = parent.current;
+ // const leftRef = leftSide.current;
+ // if (fssettings.isFullscreen) {
+ // leftRef.classList.remove('lg:min-w-[500px]');
+ // leftRef.style.width = '0%';
+ // parentRef.style.height = '100vh';
+ // } else {
+ // leftRef.classList.add('lg:min-w-[500px]');
+ // parentRef.style.height = 'calc(100dvh - 3.5rem)';
+ // }
+ // }, [fssettings, updateFSSettings]);
+
return (
<div
className="flex flex-col px-4 pb-4 lg:flex-row"
ref={parent}
- style={{ height: 'calc(100dvh - 3.5rem)' }}
+ style={{ height: fssettings.isFullscreen ? '100vh' : 'calc(100dvh - 3.5rem)' }}
>
- {!settings.isFullscreen && (
- <>
- <div
- className="min-h-[318px] w-full overflow-hidden rounded-l-2xl rounded-r-xl border border-zinc-300 bg-white dark:border-zinc-700 dark:bg-zinc-800 lg:min-w-[500px]"
- ref={leftSide}
- >
- {left}
- </div>
- <div className="resizer relative p-2" ref={resizer}>
- <div className="absolute left-1/2 top-1/2 h-1 w-24 -translate-x-1/2 -translate-y-1/2 rounded-full bg-neutral-400 duration-300 group-hover:bg-neutral-600 group-active:bg-emerald-400 group-active:duration-75 dark:bg-neutral-700 group-hover:dark:bg-neutral-500 lg:h-24 lg:w-1" />
- </div>
- </>
- )}
+ <div
+ className="min-h-[318px] w-full overflow-hidden rounded-l-2xl rounded-r-xl border border-zinc-300 bg-white dark:border-zinc-700 dark:bg-zinc-800 lg:min-w-[500px]"
+ ref={leftSide}
+ >
+ {left}
+ </div>
+ <div className="resizer relative cursor-col-resize p-2" ref={resizer}>
+ <div className="absolute left-1/2 top-1/2 h-1 w-24 -translate-x-1/2 -translate-y-1/2 rounded-full bg-neutral-400 duration-300 group-hover:bg-neutral-600 group-active:bg-emerald-400 group-active:duration-75 dark:bg-neutral-700 group-hover:dark:bg-neutral-500 lg:h-24 lg:w-1" />
+ </div>
<div
className="flex min-h-[90px] w-full flex-1 flex-col overflow-hidden rounded-l-xl rounded-r-2xl border border-zinc-300 dark:border-zinc-700 lg:min-w-[500px]"
ref={rightSide}
diff --git a/apps/web/src/app/challenge/_components/fullscreen.tsx b/apps/web/src/app/challenge/_components/fullscreen.tsx
index ac88d54a..c7cafe38 100644
--- a/apps/web/src/app/challenge/_components/fullscreen.tsx
+++ b/apps/web/src/app/challenge/_components/fullscreen.tsx
@@ -1,14 +1,47 @@
import { Tooltip, TooltipContent, TooltipTrigger } from '@repo/ui';
import { Maximize2 } from '@repo/ui/icons';
-import { useLayoutSettingsStore } from './challenge-layout';
+import { Minimize2 } from 'lucide-react';
+import { useEffect } from 'react';
+import { create } from 'zustand';
+
+export const FS_SETTINGS = {
+ isFullscreen: false,
+};
+
+type FSSettings = typeof FS_SETTINGS;
+
+interface FSState {
+ fssettings: FSSettings;
+ updateFSSettings: (settings: Partial<FSSettings>) => void;
+}
+
+export const useFullscreenSettingsStore = create<FSState>()((set, get) => ({
+ fssettings: FS_SETTINGS,
+ updateFSSettings: (fssettings) => set({ fssettings: { ...get().fssettings, ...fssettings } }),
+}));
export function FullscreenButton() {
- const { settings, updateSettings } = useLayoutSettingsStore();
+ const { fssettings, updateFSSettings } = useFullscreenSettingsStore();
const handleToggleFullscreen = () => {
- updateSettings({ ...settings, isFullscreen: !settings.isFullscreen });
+ if (!document.fullscreenElement) {
+ document.documentElement.requestFullscreen();
+ } else if (document.exitFullscreen) {
+ document.exitFullscreen();
+ }
+ updateFSSettings({ ...fssettings, isFullscreen: !fssettings.isFullscreen });
};
+ useEffect(() => {
+ const fullscreenchanged = () => {
+ if (!document.fullscreenElement) {
+ updateFSSettings({ ...fssettings, isFullscreen: false });
+ }
+ };
+ document.addEventListener('fullscreenchange', fullscreenchanged);
+ return () => document.removeEventListener('fullscreenchange', fullscreenchanged);
+ }, [fssettings, updateFSSettings]);
+
return (
<Tooltip>
<TooltipTrigger asChild>
@@ -16,7 +49,11 @@ export function FullscreenButton() {
className="focus:outline-none focus-visible:ring-2"
onClick={handleToggleFullscreen}
>
- <Maximize2 className="stroke-zinc-500 stroke-1 hover:stroke-zinc-400" size={20} />
+ {fssettings.isFullscreen ? (
+ <Minimize2 className="stroke-zinc-500 stroke-1 hover:stroke-zinc-400" size={20} />
+ ) : (
+ <Maximize2 className="stroke-zinc-500 stroke-1 hover:stroke-zinc-400" size={20} />
+ )}
</button>
</TooltipTrigger>
<TooltipContent>
diff --git a/apps/web/src/components/ui/navigation.tsx b/apps/web/src/components/ui/navigation.tsx
index 3ec6e100..9c2616ab 100644
--- a/apps/web/src/components/ui/navigation.tsx
+++ b/apps/web/src/components/ui/navigation.tsx
@@ -17,6 +17,7 @@ import Link from 'next/link';
import { usePathname, useRouter } from 'next/navigation';
import { useContext, useEffect, useState } from 'react';
import { FeatureFlagContext } from '~/app/feature-flag-provider';
+import { useFullscreenSettingsStore } from '../../app/challenge/_components/fullscreen';
export function getAdminUrl() {
// reference for vercel.com
@@ -29,87 +30,90 @@ export function getAdminUrl() {
}
export function Navigation() {
+ const { fssettings } = useFullscreenSettingsStore();
const pathname = usePathname();
const featureFlags = useContext(FeatureFlagContext);
return (
<header className="z-10 w-full">
- <nav
- className={`flex h-14 items-center text-sm font-medium ${
- pathname?.startsWith('/challenge') ? 'px-4' : 'container'
- }`}
- >
- <div className="flex w-full items-center justify-between">
- <div className="relative flex items-center gap-3">
- <a
- className="flex items-center space-x-2 focus:outline-none focus-visible:ring-2"
- href="/"
- >
- <svg
- className="h-8 w-8 rounded-md bg-[#3178C6] p-[2px]"
- viewBox="0 0 512 512"
- xmlns="http://www.w3.org/2000/svg"
+ {!fssettings.isFullscreen && (
+ <nav
+ className={`flex h-14 items-center text-sm font-medium ${
+ pathname?.startsWith('/challenge') ? 'px-4' : 'container'
+ }`}
+ >
+ <div className="flex w-full items-center justify-between">
+ <div className="relative flex items-center gap-3">
+ <a
+ className="flex items-center space-x-2 focus:outline-none focus-visible:ring-2"
+ href="/"
>
- <g clipPath="url(#clip0_1_2)">
- <path
- d="M462 0H50C22.3858 0 0 22.3858 0 50V462C0 489.614 22.3858 512 50 512H462C489.614 512 512 489.614 512 462V50C512 22.3858 489.614 0 462 0Z"
- fill="#3178C6"
- />
- <path
- clipRule="evenodd"
- d="M239.78 284.082H304V243H125V284.082H188.906V467H239.78V284.082Z"
- fill="white"
- fillRule="evenodd"
- />
- <path
- d="M303.13 466.986V242.986H349.72V335.818H418.427V242.986H465.13V466.986H418.427V373.827H349.72V466.986H303.13Z"
- fill="white"
- />
- </g>
- <defs>
- <clipPath id="clip0_1_2">
- <rect fill="white" height="512" width="512" />
- </clipPath>
- </defs>
- </svg>
-
- <span className="font-bold leading-3">
- type
- <br />
- hero
- </span>
- </a>
- {featureFlags?.exploreButton ? (
- <Link href="/explore" className="ml-4">
- <div
- className={clsx('hover:text-foreground text-foreground/80 transition-colors', {
- '!text-foreground': pathname === '/explore',
- })}
+ <svg
+ className="h-8 w-8 rounded-md bg-[#3178C6] p-[2px]"
+ viewBox="0 0 512 512"
+ xmlns="http://www.w3.org/2000/svg"
>
- Explore
- </div>
- </Link>
- ) : null}
- {featureFlags?.tracksButton ? (
- <Link href="/tracks" className="ml-4">
- <div
- className={clsx('hover:text-foreground text-foreground/80 transition-colors', {
- '!text-foreground': pathname === '/tracks',
- })}
- >
- Tracks
- </div>
- </Link>
- ) : null}
- </div>
- <div className="flex">
- <div className="flex items-center justify-end gap-2">
- <ThemeButton />
- {featureFlags?.loginButton ? <LoginButton /> : null}
+ <g clipPath="url(#clip0_1_2)">
+ <path
+ d="M462 0H50C22.3858 0 0 22.3858 0 50V462C0 489.614 22.3858 512 50 512H462C489.614 512 512 489.614 512 462V50C512 22.3858 489.614 0 462 0Z"
+ fill="#3178C6"
+ />
+ <path
+ clipRule="evenodd"
+ d="M239.78 284.082H304V243H125V284.082H188.906V467H239.78V284.082Z"
+ fill="white"
+ fillRule="evenodd"
+ />
+ <path
+ d="M303.13 466.986V242.986H349.72V335.818H418.427V242.986H465.13V466.986H418.427V373.827H349.72V466.986H303.13Z"
+ fill="white"
+ />
+ </g>
+ <defs>
+ <clipPath id="clip0_1_2">
+ <rect fill="white" height="512" width="512" />
+ </clipPath>
+ </defs>
+ </svg>
+
+ <span className="font-bold leading-3">
+ type
+ <br />
+ hero
+ </span>
+ </a>
+ {featureFlags?.exploreButton ? (
+ <Link href="/explore" className="ml-4">
+ <div
+ className={clsx('hover:text-foreground text-foreground/80 transition-colors', {
+ '!text-foreground': pathname === '/explore',
+ })}
+ >
+ Explore
+ </div>
+ </Link>
+ ) : null}
+ {featureFlags?.tracksButton ? (
+ <Link href="/tracks" className="ml-4">
+ <div
+ className={clsx('hover:text-foreground text-foreground/80 transition-colors', {
+ '!text-foreground': pathname === '/tracks',
+ })}
+ >
+ Tracks
+ </div>
+ </Link>
+ ) : null}
+ </div>
+ <div className="flex">
+ <div className="flex items-center justify-end gap-2">
+ <ThemeButton />
+ {featureFlags?.loginButton ? <LoginButton /> : null}
+ </div>
</div>
</div>
- </div>
- </nav>
+ </nav>
+ )}
</header>
);
}