Connect, collaborate, and grow with a community of TypeScript developers
feat: switch panel placement in a challenge (#1617)
Nafis Rezaecdc9b8003f3
diff --git a/apps/web/src/app/challenge/[slug]/right-wrapper.tsx b/apps/web/src/app/challenge/[slug]/right-wrapper.tsxindex 7fa98191..f876e844 100644--- a/apps/web/src/app/challenge/[slug]/right-wrapper.tsx+++ b/apps/web/src/app/challenge/[slug]/right-wrapper.tsx@@ -10,13 +10,15 @@ import { SettingsButton } from '../_components/settings/settings-button';import type { ChallengeRouteData } from './getChallengeRouteData';import { SubmissionOverview } from './submissions/[[...catchAll]]/_components/overview';import { saveSubmission } from './submissions/[[...catchAll]]/save-submission.action';+import SwapPanelButton from '../_components/swap-panel-button';interface Props {challenge: ChallengeRouteData['challenge'];track: ChallengeRouteData['track'];+ toggleDirection: () => void;}-export function RightWrapper({ track, challenge }: Props) {+export function RightWrapper({ track, challenge, toggleDirection }: Props) {const router = useRouter();const segments = useSelectedLayoutSegments();const { data: session } = useSession();@@ -55,17 +57,22 @@ export function RightWrapper({ track, challenge }: Props) {return handleSuccessfulSubmission(submission.isSuccessful, submission.id, track?.slug);}}submissionDisabled={!session?.user}- settingsElement={<SettingsElements />}+ settingsElement={<SettingsElements toggleDirection={toggleDirection} />}/>);}-function SettingsElements() {+interface SettingsElementsProps {+ toggleDirection: () => void;+}++function SettingsElements({ toggleDirection }: SettingsElementsProps) {return (<><ResetEditorButton /><EditorShortcutsButton /><SettingsButton />+ <SwapPanelButton toggleDirection={toggleDirection} /><FullscreenButton /></>);diff --git a/apps/web/src/app/challenge/_components/challenge-layout-wrapper.tsx b/apps/web/src/app/challenge/_components/challenge-layout-wrapper.tsxindex 1de827a6..f7199177 100644--- a/apps/web/src/app/challenge/_components/challenge-layout-wrapper.tsx+++ b/apps/web/src/app/challenge/_components/challenge-layout-wrapper.tsx@@ -21,11 +21,17 @@ export function ChallengeLayoutWrapper({ challenge, track, children }: Props) {}, [challenge, setCurrentChallenge]);const [isDesktop, setIsDesktop] = useState(window.innerWidth > MOBILE_BREAKPOINT);+ const [isReversed, setIsReversed] = useState(false);+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);+ const toggleDirection = () => {+ setIsReversed((prev) => !prev);+ };+const props = {setIsDesktop,isDesktop,@@ -38,6 +44,7 @@ export function ChallengeLayoutWrapper({ challenge, track, children }: Props) {return (<ChallengeLayout+ isReversed={isReversed}left={<LeftWrapperchallenge={challenge}@@ -48,7 +55,7 @@ export function ChallengeLayoutWrapper({ challenge, track, children }: Props) {{children}</LeftWrapper>}- right={<RightWrapper track={track} challenge={challenge} />}+ right={<RightWrapper track={track} challenge={challenge} toggleDirection={toggleDirection} />}{...props}/>);diff --git a/apps/web/src/app/challenge/_components/challenge-layout.tsx b/apps/web/src/app/challenge/_components/challenge-layout.tsxindex d8e4b36f..8d91eb51 100644--- a/apps/web/src/app/challenge/_components/challenge-layout.tsx+++ b/apps/web/src/app/challenge/_components/challenge-layout.tsx@@ -38,6 +38,7 @@ export interface ChallengeLayoutProps {adjustPanelSize: (divideByW: number, divideByH: number, newDimensionValue: number) => void;isLeftPanelCollapsed: () => boolean;isPlayground?: boolean;+ isReversed?: boolean;}export const MOBILE_BREAKPOINT = 1025;@@ -55,6 +56,7 @@ export function ChallengeLayout({expandPanel,isLeftPanelCollapsed,isPlayground,+ isReversed = false,}: ChallengeLayoutProps) {const parent = useRef<HTMLDivElement>(null);const resizer = useRef<HTMLDivElement>(null);@@ -141,11 +143,18 @@ export function ChallengeLayout({height: 0,};+ // swap the logic for dragging left and right+ const adjustedDx = isReversed ? -dx : dx;const newDimensionValue = isDesktop- ? ((leftWidth + dx) * 100) / divideByW+ ? ((leftWidth + adjustedDx) * 100) / divideByW: ((topHeight + dy) * 100) / divideByH;- if (currPos <= COLLAPSE_BREAKPOINT) {+ // Adjust collapse check for reversed layout+ const shouldCollapse = isReversed+ ? currPos >= parent.current!.getBoundingClientRect().width - COLLAPSE_BREAKPOINT+ : currPos <= COLLAPSE_BREAKPOINT;++ if (shouldCollapse) {collapsePanel();} else {adjustPanelSize(divideByW, divideByH, newDimensionValue);@@ -277,11 +286,12 @@ export function ChallengeLayout({updateSettings,_COLLAPSED_DESKTOP_WIDTH,_COLLAPSED_MOBILE_HEIGHT,+ isReversed,]);return (<div- className="flex flex-col px-4 pb-4 lg:flex-row"+ className={`flex flex-col px-4 pb-4 ${isReversed ? 'lg:flex-row-reverse' : 'lg:flex-row'}`}ref={parent}style={{ height: fssettings.isFullscreen ? '100vh' : 'calc(100vh - 3.5rem)' }}>diff --git a/apps/web/src/app/challenge/_components/swap-panel-button.tsx b/apps/web/src/app/challenge/_components/swap-panel-button.tsxnew file mode 100644index 00000000..0e5c6558--- /dev/null+++ b/apps/web/src/app/challenge/_components/swap-panel-button.tsx@@ -0,0 +1,21 @@+import { ArrowRightLeft } from '@repo/ui/icons';+import { Tooltip, TooltipContent, TooltipTrigger } from '@repo/ui/components/tooltip';++interface props {+ toggleDirection: () => void;+}++const SwapPanelButton = ({ toggleDirection }: props) => {+ return (+ <Tooltip>+ <TooltipTrigger asChild>+ <button onClick={toggleDirection} className="hidden lg:block">+ <ArrowRightLeft className="stroke-zinc-500 stroke-1 hover:stroke-zinc-400" size={20} />+ </button>+ </TooltipTrigger>+ <TooltipContent className="px-2 py-1">Swap Panels</TooltipContent>+ </Tooltip>+ );+};++export default SwapPanelButton;diff --git a/packages/ui/src/icons.ts b/packages/ui/src/icons.tsindex e6394103..1b273420 100644--- a/packages/ui/src/icons.ts+++ b/packages/ui/src/icons.ts@@ -4,6 +4,7 @@ export {ArrowLeft,ArrowUp,ArrowUpNarrowWide,+ ArrowRightLeft,ArrowUpRight,AtSign,Award,