-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove layouts when mobile
- Loading branch information
1 parent
3f74985
commit 9a68638
Showing
10 changed files
with
97 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,11 @@ | ||
import { ReactNode } from 'react' | ||
|
||
import PageLayout from 'app/(connected)/(with-sidebar)/PageLayout' | ||
import sidebarLayout from 'app/(connected)/(with-sidebar)/sidebar.module.css' | ||
import Sidebar from 'components/Sidebar' | ||
|
||
export default async function LayoutWithoutChat({ | ||
children, | ||
}: { | ||
children: ReactNode | ||
}) { | ||
return ( | ||
<div className='flex h-screen supports-[height:100dvh]:h-dvh w-screen'> | ||
<div className={sidebarLayout.sidebar}> | ||
<Sidebar /> | ||
</div> | ||
|
||
<PageLayout fullWidth={false}>{children}</PageLayout> | ||
</div> | ||
) | ||
return <PageLayout fullWidth={false}>{children}</PageLayout> | ||
} |
11 changes: 1 addition & 10 deletions
11
app/(connected)/(with-sidebar)/(without-chat-full-screen)/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
import { ReactNode } from 'react' | ||
|
||
import PageLayout from 'app/(connected)/(with-sidebar)/PageLayout' | ||
import sidebarLayout from 'app/(connected)/(with-sidebar)/sidebar.module.css' | ||
import Sidebar from 'components/Sidebar' | ||
|
||
export default async function LayoutWithoutChatFullScreen({ | ||
children, | ||
}: { | ||
children: ReactNode | ||
}) { | ||
return ( | ||
<div className='flex h-screen supports-[height:100dvh]:h-dvh w-screen'> | ||
<div className={sidebarLayout.sidebar}> | ||
<Sidebar /> | ||
</div> | ||
|
||
<PageLayout fullWidth={true}>{children}</PageLayout> | ||
</div> | ||
) | ||
return <PageLayout fullWidth={true}>{children}</PageLayout> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use client' | ||
|
||
import { ReactNode } from 'react' | ||
|
||
import Sidebar from 'components/Sidebar' | ||
import { useMobileViewport } from 'utils/mobileViewportContext' | ||
|
||
export default function LayoutWithSidebar({ | ||
children, | ||
}: { | ||
children: ReactNode | ||
}) { | ||
const isMobileViewport = useMobileViewport() | ||
|
||
return ( | ||
<div className='flex h-screen supports-[height:100dvh]:h-dvh w-screen'> | ||
{!isMobileViewport && <Sidebar />} | ||
|
||
{children} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use client' | ||
|
||
import { | ||
createContext, | ||
ReactNode, | ||
useContext, | ||
useEffect, | ||
useState, | ||
} from 'react' | ||
|
||
import { MIN_DESKTOP_WIDTH } from 'components/globals' | ||
|
||
const MobileViewportContext = createContext<boolean | undefined>(undefined) | ||
|
||
export function MobileViewportProvider({ children }: { children: ReactNode }) { | ||
const [isMobileViewport, setIsMobileViewport] = useState<boolean>(true) | ||
|
||
useEffect(() => { | ||
const handleResize = () => | ||
setIsMobileViewport(window.innerWidth < MIN_DESKTOP_WIDTH) | ||
|
||
window.addEventListener('resize', handleResize) | ||
handleResize() | ||
|
||
return () => window.removeEventListener('resize', handleResize) | ||
}, []) | ||
|
||
return ( | ||
<MobileViewportContext.Provider value={isMobileViewport}> | ||
{children} | ||
</MobileViewportContext.Provider> | ||
) | ||
} | ||
|
||
export function useMobileViewport(): boolean { | ||
const mobileViewportContext = useContext(MobileViewportContext) | ||
if (mobileViewportContext === undefined) { | ||
throw new Error( | ||
'useMobileViewport must be used within MobileViewportProvider' | ||
) | ||
} | ||
|
||
return mobileViewportContext | ||
} |