From 1b1405dbe259afbe459ca985842e82e36f2ab93c Mon Sep 17 00:00:00 2001 From: Julian Bilcke Date: Thu, 29 Aug 2024 00:15:08 +0200 Subject: [PATCH] more versatile open url param --- .../top-menu/file/useQueryStringLoader.ts | 16 ++++++++++------ .../app/src/lib/hooks/useQueryStringParams.ts | 10 +++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/app/src/components/toolbars/top-menu/file/useQueryStringLoader.ts b/packages/app/src/components/toolbars/top-menu/file/useQueryStringLoader.ts index cb3632f9..8c515fc4 100644 --- a/packages/app/src/components/toolbars/top-menu/file/useQueryStringLoader.ts +++ b/packages/app/src/components/toolbars/top-menu/file/useQueryStringLoader.ts @@ -6,7 +6,7 @@ import { useQueryStringParams } from '@/lib/hooks' import { useAssistant, useIO } from '@/services' export function useQueryStringLoader() { - const { clapUrl, startAt, interactive, prompt, imageStrategy } = + const { fileUrl, startAt, interactive, prompt, imageStrategy } = useQueryStringParams({ // clapUrl: `/samples/test.clap`, // clapUrl: `/samples/Afterglow%20v10%20X%20Rewrite%20Bryan%20E.%20Harris%202023.clap`, @@ -14,7 +14,7 @@ export function useQueryStringLoader() { const processUserMessage = useAssistant((s) => s.processUserMessage) const openClapUrl = useIO((s) => s.openClapUrl) - + const openScreenplayUrl = useIO((s) => s.openScreenplayUrl) useEffect(() => { ;(async () => { if (prompt.length > 2) { @@ -22,13 +22,17 @@ export function useQueryStringLoader() { console.log('initializing using message', prompt) processUserMessage(message) - } else if (clapUrl) { - console.log(`loading ${clapUrl}`) - await openClapUrl(clapUrl) + } else if (fileUrl) { + console.log(`loading ${fileUrl}`) + if (fileUrl.toLocaleLowerCase().endsWith(".clap")) { + await openClapUrl(fileUrl) + } else { + openScreenplayUrl(fileUrl) + } } else { console.log('No clap URL provided') return } })() - }, [prompt, openClapUrl, clapUrl, interactive, imageStrategy]) + }, [prompt, openClapUrl, openScreenplayUrl, fileUrl, interactive, imageStrategy]) } diff --git a/packages/app/src/lib/hooks/useQueryStringParams.ts b/packages/app/src/lib/hooks/useQueryStringParams.ts index 433c6987..2ecc77c1 100644 --- a/packages/app/src/lib/hooks/useQueryStringParams.ts +++ b/packages/app/src/lib/hooks/useQueryStringParams.ts @@ -7,19 +7,19 @@ export function useQueryStringParams( interactive: defaultInteractive = false, startAt: defaultStartAt = 0, prompt: defaultPrompt = '', - clapUrl: defaultClapUrl = '', + fileUrl: defaultFileUrl = '', imageStrategy: defaultImageStrategy = RenderingStrategy.ON_DEMAND, }: { interactive?: boolean startAt?: number prompt?: string - clapUrl?: string + fileUrl?: string imageStrategy?: RenderingStrategy } = { interactive: false, startAt: 0, prompt: '', - clapUrl: '', + fileUrl: '', imageStrategy: RenderingStrategy.ON_DEMAND, } ) { @@ -43,7 +43,7 @@ export function useQueryStringParams( .trim() .toLowerCase() === 'true' - const clapUrl = (searchParams?.get('clap') as string) || defaultClapUrl + const fileUrl = (searchParams?.get('open') as string) || defaultFileUrl - return { prompt, interactive, startAt, clapUrl, imageStrategy } + return { prompt, interactive, startAt, fileUrl, imageStrategy } }