Skip to content

Commit

Permalink
screen size translate page
Browse files Browse the repository at this point in the history
for the chat scroll area
  • Loading branch information
nichtsam committed Jan 3, 2025
1 parent 31be0f4 commit 207acef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { type MetaFunction, type LinksFunction } from '@remix-run/node'
import { Links, Meta, Outlet, Scripts } from '@remix-run/react'
import stylesheet from '#app/styles/app.css?url'
import { SiteHeader } from './components/site-header'
import { useScreenSize } from './utils/screen-size.ts'
import { cn } from './utils/ui.ts'

export const meta: MetaFunction = () => [
{ title: 'Polyglotize' },
Expand Down Expand Up @@ -34,10 +36,14 @@ export function Layout({ children }: { children: React.ReactNode }) {
}

export default function App() {
const screenSize = useScreenSize()

return (
<div className="flex min-h-svh flex-col">
<div
className={cn('flex min-h-svh flex-col', screenSize && 'h-svh max-h-svh')}
>
<SiteHeader />
<div className="flex flex-grow flex-col">
<div className={cn('flex flex-grow flex-col', screenSize && 'min-h-0')}>
<Outlet />
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion app/routes/translate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { Button } from '#app/components/ui/button.tsx'
import { Card, CardContent } from '#app/components/ui/card.tsx'
import { ScrollArea } from '#app/components/ui/scroll-area.tsx'
import { type ScreenSizeHandle } from '#app/utils/screen-size.ts'
import { targetLangConfig } from '#app/utils/translation.ts'
import { getSettingsSession, Translator } from '#app/utils/translator.server.ts'
import { useIsPending } from '#app/utils/ui.ts'
Expand All @@ -28,6 +29,10 @@ export const schema = z.object({
.max(120, 'Expression is limited to 120 characters.'),
})

export const handle: ScreenSizeHandle = {
screenSize: true,
}

export const loader = async ({ request }: LoaderFunctionArgs) => {
const settings = await getSettingsSession(request)

Expand Down Expand Up @@ -90,7 +95,7 @@ export default function Page() {
const allErrors = Object.values(form.allErrors).flat()

return (
<div className="mx-auto flex w-full max-w-[85ch] flex-grow flex-col font-serif">
<div className="mx-auto flex min-h-0 w-full max-w-[85ch] flex-grow flex-col font-serif">
<ScrollArea className="flex-grow px-4">
{actionData?.data && (
<div className="flex flex-col gap-y-4 py-4">
Expand Down
17 changes: 17 additions & 0 deletions app/utils/screen-size.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useMatches } from '@remix-run/react'
import { z } from 'zod'

const screenSizeSchema = z.boolean()
const screenSizeHandleSchema = z.object({ screenSize: screenSizeSchema })

export type ScreenSizeHandle = z.infer<typeof screenSizeHandleSchema>

export const useScreenSize = () => {
const matches = useMatches()
const screenSize = matches.some(({ handle }) => {
const result = screenSizeHandleSchema.safeParse(handle)
return result.success && result.data.screenSize
})

return screenSize
}

0 comments on commit 207acef

Please sign in to comment.