Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: screenplay not loaded when importing txt or clap #35

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading