Skip to content

Commit

Permalink
Merge pull request #35 from devniel/fix-screenplay
Browse files Browse the repository at this point in the history
fix: screenplay not loaded when importing txt or clap
  • Loading branch information
jbilcke-hf authored Aug 13, 2024
2 parents 2b91240 + ddc4e46 commit 3635e59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
10 changes: 0 additions & 10 deletions src/components/editors/ScriptEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,9 @@ export function ScriptEditor() {
const current = useScriptEditor((s) => s.current)
const setCurrent = useScriptEditor((s) => s.setCurrent)
const publish = useScriptEditor((s) => s.publish)
const loadDraftFromClap = useScriptEditor((s) => s.loadDraftFromClap)
const onDidScrollChange = useScriptEditor((s) => s.onDidScrollChange)
const jumpCursorOnLineClick = useScriptEditor((s) => s.jumpCursorOnLineClick)

const getClap = useTimeline((s: TimelineStore) => s.getClap)

useEffect(() => {
const fn = async () => {
loadDraftFromClap(await getClap())
}
fn()
}, [getClap])

const scrollHeight = useScriptEditor((s) => s.scrollHeight)

const scrollX = useTimeline((s) => s.scrollX)
Expand Down
16 changes: 15 additions & 1 deletion src/services/io/useIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ import {
clapSegmentToTimelineSegment,
} from '@aitube/timeline'
import { ParseScriptProgressUpdate, parseScriptToClap } from '@aitube/broadway'
import { IOStore, TaskCategory, TaskVisibility } from '@aitube/clapper-services'
import {
IOStore,
ScriptEditorStore,
TaskCategory,
TaskVisibility,
} from '@aitube/clapper-services'
import { create } from 'zustand'
import * as fflate from 'fflate'

Expand All @@ -52,6 +57,7 @@ import { extractScenesFromVideo } from './extractScenesFromVideo'
import { base64DataUriToFile } from '@/lib/utils/base64DataUriToFile'
import { useUI } from '../ui'
import { getTypeAndExtension } from '@/lib/utils/getTypeAndExtension'
import { useScriptEditor } from '../editors'

export const useIO = create<IOStore>((set, get) => ({
...getDefaultIOState(),
Expand Down Expand Up @@ -246,6 +252,7 @@ export const useIO = create<IOStore>((set, get) => ({
: await new Response(fileContent).text()

const timeline: TimelineStore = useTimeline.getState()
const scriptEditor: ScriptEditorStore = useScriptEditor.getState()
const task = useTasks.getState().add({
category: TaskCategory.IMPORT,
visibility: TaskVisibility.BLOCKER,
Expand Down Expand Up @@ -296,6 +303,7 @@ export const useIO = create<IOStore>((set, get) => ({
})

await timeline.setClap(clap)
scriptEditor.loadDraftFromClap(clap)

task.setProgress({
message: 'Nearly there..',
Expand All @@ -312,6 +320,7 @@ export const useIO = create<IOStore>((set, get) => ({
},
openScreenplayUrl: async (url: string) => {
const timeline: TimelineStore = useTimeline.getState()
const scriptEditor: ScriptEditorStore = useScriptEditor.getState()

const { fileName, projectName } = parseFileName(
`${url.split('/').pop() || url}`
Expand Down Expand Up @@ -355,6 +364,7 @@ export const useIO = create<IOStore>((set, get) => ({
})

await timeline.setClap(clap)
scriptEditor.loadDraftFromClap(clap)

task.setProgress({
message: 'Nearly there..',
Expand Down Expand Up @@ -389,6 +399,7 @@ export const useIO = create<IOStore>((set, get) => ({

openClapUrl: async (url: string) => {
const timeline: TimelineStore = useTimeline.getState()
const scriptEditor: ScriptEditorStore = useScriptEditor.getState()
const { setClap } = timeline

const { fileName, projectName } = parseFileName(
Expand Down Expand Up @@ -426,6 +437,7 @@ export const useIO = create<IOStore>((set, get) => ({
})

await setClap(clap)
scriptEditor.loadDraftFromClap(clap)

task.success()
} catch (err) {
Expand All @@ -435,6 +447,7 @@ export const useIO = create<IOStore>((set, get) => ({
},
openClapBlob: async (projectName: string, fileName: string, blob: Blob) => {
const timeline: TimelineStore = useTimeline.getState()
const scriptEditor: ScriptEditorStore = useScriptEditor.getState()
const { setClap } = timeline

const task = useTasks.getState().add({
Expand All @@ -459,6 +472,7 @@ export const useIO = create<IOStore>((set, get) => ({
})

await setClap(clap)
scriptEditor.loadDraftFromClap(clap)

task.success()
} catch (err) {
Expand Down

0 comments on commit 3635e59

Please sign in to comment.