Skip to content

Commit

Permalink
more versatile open url param
Browse files Browse the repository at this point in the history
  • Loading branch information
jbilcke-hf committed Aug 28, 2024
1 parent f332f91 commit 1b1405d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,33 @@ 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`,
})

const processUserMessage = useAssistant((s) => s.processUserMessage)
const openClapUrl = useIO((s) => s.openClapUrl)

const openScreenplayUrl = useIO((s) => s.openScreenplayUrl)
useEffect(() => {
;(async () => {
if (prompt.length > 2) {
const message = `please create the first scene's segments of a new story, based on this simple pitch (you can expand it): ${prompt}`

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])
}
10 changes: 5 additions & 5 deletions packages/app/src/lib/hooks/useQueryStringParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
) {
Expand All @@ -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 }
}

0 comments on commit 1b1405d

Please sign in to comment.