Force desktop frame via useFrameViewport hook in Layout — applies to all pages
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8c6a79f222
commit
ba23d59b3d
2 changed files with 25 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ import { NavLink } from 'react-router-dom'
|
||||||
import { CalendarClock, Settings, LogOut } from 'lucide-react'
|
import { CalendarClock, Settings, LogOut } from 'lucide-react'
|
||||||
import { can } from '../types'
|
import { can } from '../types'
|
||||||
import type { User } from '../types'
|
import type { User } from '../types'
|
||||||
|
import { useFrameViewport } from '../hooks/useFrameViewport'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
user: User
|
user: User
|
||||||
|
|
@ -9,6 +10,8 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Layout({ user, children }: Props) {
|
export function Layout({ user, children }: Props) {
|
||||||
|
useFrameViewport('desktop')
|
||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
await fetch('/api/auth/logout', { method: 'POST', credentials: 'include' })
|
await fetch('/api/auth/logout', { method: 'POST', credentials: 'include' })
|
||||||
window.location.href = '/'
|
window.location.href = '/'
|
||||||
|
|
|
||||||
22
frontend/src/hooks/useFrameViewport.ts
Normal file
22
frontend/src/hooks/useFrameViewport.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
|
type ViewportMode = 'desktop' | 'responsive'
|
||||||
|
|
||||||
|
const DESKTOP = 'width=1280'
|
||||||
|
const RESPONSIVE = 'width=device-width, initial-scale=1.0'
|
||||||
|
|
||||||
|
function setMetaViewport(content: string) {
|
||||||
|
const meta = document.querySelector<HTMLMetaElement>('meta[name="viewport"]')
|
||||||
|
if (meta) meta.content = content
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useFrameViewport(mode: ViewportMode) {
|
||||||
|
useEffect(() => {
|
||||||
|
setMetaViewport(mode === 'desktop' ? DESKTOP : RESPONSIVE)
|
||||||
|
window.parent.postMessage({ type: 'hnf:viewport', mode }, '*')
|
||||||
|
return () => {
|
||||||
|
setMetaViewport(RESPONSIVE)
|
||||||
|
window.parent.postMessage({ type: 'hnf:viewport', mode: 'responsive' }, '*')
|
||||||
|
}
|
||||||
|
}, [mode])
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue