Skip to content

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

Fixed playground left panel, moved back to simple panel + introduced … (#847)

Amanuel Odichob8a09d1e7b2a
diff --git a/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/ChallengePlaygroundWrapper.tsx b/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/ChallengePlaygroundWrapper.tsx
deleted file mode 100644
index 0915022a..00000000
--- a/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/ChallengePlaygroundWrapper.tsx
+++ /dev/null
@@ -1,17 +0,0 @@
-'use client';
-
-import { type ReactNode } from 'react';
-import { ChallengeLayoutWrapper } from '../../challenge/_components/challenge-layout-wrapper';
-import { useChallengePlaygroundStore } from './challenge-playground-store';
-import type { ChallengeRouteData } from '../../challenge/[id]/getChallengeRouteData';
-
-interface Props {
- children: ReactNode;
-}
-
-export function ChallengePlaygroundWrapper({ children }: Props) {
- const { values } = useChallengePlaygroundStore();
-
- const challenge = values.challenge as ChallengeRouteData;
- return <ChallengeLayoutWrapper challenge={challenge}>{children}</ChallengeLayoutWrapper>;
-}
diff --git a/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/challenge-playground-layout-wrapper.tsx b/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/challenge-playground-layout-wrapper.tsx
new file mode 100644
index 00000000..fc336501
--- /dev/null
+++ b/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/challenge-playground-layout-wrapper.tsx
@@ -0,0 +1,33 @@
+'use client';
+import { useState, type ReactNode } from 'react';
+import usePanelAdjustments from '../../challenge/_components/usePanelAdjustments';
+import { LeftWrapper } from './left-wrapper';
+import { Wrapper } from './wrapper';
+import { ChallengeLayout, MOBILE_BREAKPOINT } from '../../challenge/_components/challenge-layout';
+
+export function ChallengePlaygroundLayoutWrapper({ children }: { children: ReactNode }) {
+ const [isDesktop, setIsDesktop] = useState(window.innerWidth > MOBILE_BREAKPOINT);
+ const LEFT_PANEL_BREAKPOINT = isDesktop ? 500 : 318;
+ const DEFAULT_DESKTOP_WIDTH_PX = `${LEFT_PANEL_BREAKPOINT}px`;
+ const { leftSide, adjustPanelSize, expandPanel, collapsePanel, isLeftPanelCollapsed } =
+ usePanelAdjustments(DEFAULT_DESKTOP_WIDTH_PX, LEFT_PANEL_BREAKPOINT, isDesktop, true);
+
+ const props = {
+ setIsDesktop,
+ isDesktop,
+ leftSide,
+ adjustPanelSize,
+ expandPanel,
+ collapsePanel,
+ isLeftPanelCollapsed,
+ };
+
+ return (
+ <ChallengeLayout
+ left={<LeftWrapper>{children}</LeftWrapper>}
+ right={<Wrapper />}
+ isPlayground
+ {...props}
+ />
+ );
+}
diff --git a/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/layout.tsx b/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/layout.tsx
index 9563cb0c..0dff7957 100644
--- a/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/layout.tsx
+++ b/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/layout.tsx
@@ -2,7 +2,7 @@ import { ForceRenderUntilClient } from '@repo/ui/components/force-render-until-c
import { getServerAuthSession } from '@repo/auth/server';
import { isAdminOrModerator } from '~/utils/auth-guards';
import { redirect } from 'next/navigation';
-import { ChallengePlaygroundWrapper } from './ChallengePlaygroundWrapper';
+import { ChallengePlaygroundLayoutWrapper } from './challenge-playground-layout-wrapper';
export default async function LayoutData({ children }: { children: React.ReactNode }) {
const session = await getServerAuthSession();
@@ -12,7 +12,7 @@ export default async function LayoutData({ children }: { children: React.ReactNo
return (
<ForceRenderUntilClient>
- <ChallengePlaygroundWrapper>{children}</ChallengePlaygroundWrapper>
+ <ChallengePlaygroundLayoutWrapper>{children}</ChallengePlaygroundLayoutWrapper>
</ForceRenderUntilClient>
);
}
diff --git a/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/left-wrapper.tsx b/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/left-wrapper.tsx
new file mode 100644
index 00000000..8372c497
--- /dev/null
+++ b/apps/web/src/app/[locale]/(playgrounds)/challenge-playground/left-wrapper.tsx
@@ -0,0 +1,11 @@
+'use client';
+
+import { type ReactNode } from 'react';
+
+interface Props {
+ children: ReactNode;
+}
+
+export function LeftWrapper({ children }: Props) {
+ return <div className="flex h-full w-full flex-col">{children}</div>;
+}
diff --git a/apps/web/src/app/[locale]/challenge/_components/challenge-layout.tsx b/apps/web/src/app/[locale]/challenge/_components/challenge-layout.tsx
index bcf6d98a..d9ec8a44 100644
--- a/apps/web/src/app/[locale]/challenge/_components/challenge-layout.tsx
+++ b/apps/web/src/app/[locale]/challenge/_components/challenge-layout.tsx
@@ -39,6 +39,7 @@ export interface ChallengeLayoutProps {
expandPanel: () => void;
adjustPanelSize: (divideByW: number, divideByH: number, newDimensionValue: number) => void;
isLeftPanelCollapsed: () => boolean;
+ isPlayground?: boolean;
}
export const MOBILE_BREAKPOINT = 1025;
@@ -55,6 +56,7 @@ export function ChallengeLayout({
collapsePanel,
expandPanel,
isLeftPanelCollapsed,
+ isPlayground,
}: ChallengeLayoutProps) {
const parent = useRef<HTMLDivElement>(null);
const resizer = useRef<HTMLDivElement>(null);
@@ -66,23 +68,26 @@ export function ChallengeLayout({
const LEFT_PANEL_BREAKPOINT = isDesktop ? 500 : 318;
const COLLAPSE_BREAKPOINT = isCollapsed ? 50 : 300;
+ const _COLLAPSED_MOBILE_HEIGHT = isPlayground ? 0 : COLLAPSED_MOBILE_HEIGHT;
+ const _COLLAPSED_DESKTOP_WIDTH = isPlayground ? 0 : COLLAPSED_DESKTOP_WIDTH;
+
const DEFAULT_DESKTOP_WIDTH_PX = `${LEFT_PANEL_BREAKPOINT}px`;
const isPanelCollapsed = useMemo(() => {
const height = parseFloat(settings.height);
const width = parseFloat(settings.width);
- return height <= COLLAPSED_MOBILE_HEIGHT || width <= COLLAPSED_DESKTOP_WIDTH;
- }, [settings.height, settings.width]);
+ return height <= _COLLAPSED_MOBILE_HEIGHT || width <= _COLLAPSED_DESKTOP_WIDTH;
+ }, [settings.height, settings.width, _COLLAPSED_MOBILE_HEIGHT, _COLLAPSED_DESKTOP_WIDTH]);
const leftStyle = useMemo(() => {
const leftStyleIfDesktopCollapsed = {
- width: `${COLLAPSED_DESKTOP_WIDTH}px`,
- minWidth: `${COLLAPSED_DESKTOP_WIDTH}px`,
+ width: `${_COLLAPSED_DESKTOP_WIDTH}px`,
+ minWidth: `${_COLLAPSED_DESKTOP_WIDTH}px`,
};
const leftStyleIfMobileCollapsed = {
- height: `${COLLAPSED_MOBILE_HEIGHT}px`,
- minHeight: `${COLLAPSED_MOBILE_HEIGHT}px`,
+ height: `${_COLLAPSED_MOBILE_HEIGHT}px`,
+ minHeight: `${_COLLAPSED_MOBILE_HEIGHT}px`,
};
if (isDesktop) {
@@ -99,7 +104,15 @@ export function ChallengeLayout({
height: settings.height,
minHeight: `${LEFT_PANEL_BREAKPOINT}px`,
};
- }, [isDesktop, isPanelCollapsed, settings.height, settings.width, LEFT_PANEL_BREAKPOINT]);
+ }, [
+ isDesktop,
+ isPanelCollapsed,
+ settings.height,
+ settings.width,
+ LEFT_PANEL_BREAKPOINT,
+ _COLLAPSED_MOBILE_HEIGHT,
+ _COLLAPSED_DESKTOP_WIDTH,
+ ]);
useEffect(() => {
const ref = resizer.current;
@@ -208,13 +221,13 @@ export function ChallengeLayout({
const height = parseFloat(leftRef.style.height);
const width = parseFloat(leftRef.style.width);
- if (height <= COLLAPSED_MOBILE_HEIGHT || width <= COLLAPSED_DESKTOP_WIDTH) {
+ if (height <= _COLLAPSED_MOBILE_HEIGHT || width <= _COLLAPSED_DESKTOP_WIDTH) {
if (isDesktop) {
- leftRef.style.width = `${COLLAPSED_DESKTOP_WIDTH}px`;
- updateSettings({ width: `${COLLAPSED_DESKTOP_WIDTH}px`, height: '300px' });
+ leftRef.style.width = `${_COLLAPSED_DESKTOP_WIDTH}px`;
+ updateSettings({ width: `${_COLLAPSED_DESKTOP_WIDTH}px`, height: '300px' });
} else {
- leftRef.style.height = `${COLLAPSED_MOBILE_HEIGHT}px`;
- updateSettings({ width: '500px', height: `${COLLAPSED_MOBILE_HEIGHT}px` });
+ leftRef.style.height = `${_COLLAPSED_MOBILE_HEIGHT}px`;
+ updateSettings({ width: '500px', height: `${_COLLAPSED_MOBILE_HEIGHT}px` });
}
}
};
@@ -264,6 +277,8 @@ export function ChallengeLayout({
leftSide,
settings,
updateSettings,
+ _COLLAPSED_DESKTOP_WIDTH,
+ _COLLAPSED_MOBILE_HEIGHT,
]);
return (
@@ -273,7 +288,9 @@ export function ChallengeLayout({
style={{ height: fssettings.isFullscreen ? '100vh' : 'calc(100vh - 3.5rem)' }}
>
<div
- className="w-full overflow-hidden rounded-l-2xl rounded-r-xl border border-zinc-300 bg-white dark:border-zinc-700 dark:bg-zinc-800"
+ className={`w-full overflow-hidden rounded-l-2xl rounded-r-xl border-zinc-300 bg-white dark:border-zinc-700 dark:bg-zinc-800 ${
+ !isPlayground && 'border'
+ }`}
ref={leftSide}
style={{ ...leftStyle }}
>
diff --git a/apps/web/src/app/[locale]/challenge/_components/usePanelAdjustments.ts b/apps/web/src/app/[locale]/challenge/_components/usePanelAdjustments.ts
index 8879ca3c..064636c1 100644
--- a/apps/web/src/app/[locale]/challenge/_components/usePanelAdjustments.ts
+++ b/apps/web/src/app/[locale]/challenge/_components/usePanelAdjustments.ts
@@ -5,6 +5,7 @@ const usePanelAdjustments = (
DEFAULT_DESKTOP_WIDTH_PX: string,
LEFT_PANEL_BREAKPOINT: number,
isDesktop: boolean,
+ isPlayground?: boolean,
) => {
const leftSide = useRef<HTMLDivElement | null>(null);
@@ -24,13 +25,17 @@ const usePanelAdjustments = (
const collapsePanel = useCallback(() => {
if (!leftSide.current) return;
if (isDesktop) {
- leftSide.current.style.width = `${COLLAPSED_DESKTOP_WIDTH}px`;
- leftSide.current.style.minWidth = `${COLLAPSED_DESKTOP_WIDTH}px`;
+ leftSide.current.style.width = `${isPlayground ? '0' : COLLAPSED_DESKTOP_WIDTH}px`;
+ leftSide.current.style.minWidth = `${isPlayground ? '0' : COLLAPSED_DESKTOP_WIDTH}px`;
} else {
- leftSide.current.style.height = `${COLLAPSED_MOBILE_HEIGHT}px`;
- leftSide.current.style.minHeight = `${COLLAPSED_MOBILE_HEIGHT}px`;
+ leftSide.current.style.height = `${isPlayground ? '0' : COLLAPSED_MOBILE_HEIGHT}px`;
+ leftSide.current.style.minHeight = `${isPlayground ? '0' : COLLAPSED_MOBILE_HEIGHT}px`;
}
- }, [isDesktop]);
+
+ if (isPlayground) {
+ leftSide.current.style.opacity = '0%';
+ }
+ }, [isDesktop, isPlayground]);
const isLeftPanelCollapsed = useCallback(() => {
if (!leftSide.current) return false;