Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 3,301 Bytes
624088c 932a7fd 624088c 932a7fd 624088c 932a7fd 8c5d17c 624088c 932a7fd 624088c 932a7fd 624088c 932a7fd 624088c 932a7fd 624088c 8c5d17c 932a7fd 624088c 932a7fd 624088c 932a7fd 624088c 8c5d17c 932a7fd 8c5d17c 82d85df 8c5d17c 82d85df 8c5d17c 82d85df 8c5d17c 932a7fd 8c5d17c 624088c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
"use client"
import { useEffect, useTransition } from "react"
import { useSearchParams } from "next/navigation"
import { PresetName, defaultPreset, getPreset } from "@/app/engine/presets"
import { cn } from "@/lib/utils"
import { TopMenu } from "./interface/top-menu"
import { FontName, defaultFont } from "@/lib/fonts"
import { getRandomLayoutName, layouts } from "./layouts"
import { useStore } from "./store"
import { Zoom } from "./interface/zoom"
export default function Main() {
const [_isPending, startTransition] = useTransition()
const searchParams = useSearchParams()
const requestedPreset = (searchParams.get('preset') as PresetName) || defaultPreset
const requestedFont = (searchParams.get('font') as FontName) || defaultFont
const requestedPrompt = (searchParams.get('prompt') as string) || ""
const font = useStore(state => state.font)
const setFont = useStore(state => state.setFont)
const preset = useStore(state => state.preset)
const setPreset = useStore(state => state.setPreset)
const prompt = useStore(state => state.prompt)
const setPrompt = useStore(state => state.setPrompt)
const layout = useStore(state => state.layout)
const setLayout = useStore(state => state.setLayout)
const setPanels = useStore(state => state.setPanels)
const zoomLevel = useStore(state => state.zoomLevel)
// react to URL params
useEffect(() => {
if (requestedPreset && requestedPreset !== preset.label) { setPreset(getPreset(requestedPreset)) }
}, [requestedPreset])
useEffect(() => {
if (requestedFont && requestedFont !== font) { setFont(requestedFont) }
}, [requestedFont])
useEffect(() => {
if (requestedPrompt && requestedPrompt !== prompt) { setPrompt(requestedPrompt) }
}, [requestedPrompt])
// react to prompt changes
useEffect(() => {
if (!prompt) { return }
const newLayout = getRandomLayoutName()
console.log("using layout " + newLayout)
setLayout(newLayout)
// TODO call the LLM here!
const panelPrompt = preset.imagePrompt(prompt).join(", ")
// what we want is for it to invent a small "story"
setPanels([ panelPrompt, panelPrompt, panelPrompt, panelPrompt ])
}, [prompt, preset]) // important: we need to react to preset changes too
const LayoutElement = (layouts as any)[layout]
return (
<div>
<TopMenu />
<div className={cn(
`flex items-start w-screen h-screen pt-[120px] px-16 md:pt-[72px] overflow-y-scroll`,
`transition-all duration-200 ease-in-out`
)}>
<div className="flex flex-col items-center w-full">
<div
className={cn(
`flex flex-col items-center justify-start`,
// we are trying to reach a "book" look
// we are using aspect-[297/210] because it matches A4 (297mm x 210mm)
// `aspect-[210/297]`,
`aspect-[250/297]`,
`transition-all duration-100 ease-in-out`,
`border border-stone-200`,
`shadow-2xl`
)}
style={{
width: `${zoomLevel}%`,
padding: `${Math.round((zoomLevel / 100) * 16)}px`
}}
>
<LayoutElement />
</div>
</div>
</div>
<Zoom />
</div>
)
} |