devniel commited on
Commit
ddc4e46
1 Parent(s): c01ff04

fix: screenplay not loaded when importing txt or clap

Browse files
src/components/editors/ScriptEditor/index.tsx CHANGED
@@ -21,19 +21,9 @@ export function ScriptEditor() {
21
  const current = useScriptEditor((s) => s.current)
22
  const setCurrent = useScriptEditor((s) => s.setCurrent)
23
  const publish = useScriptEditor((s) => s.publish)
24
- const loadDraftFromClap = useScriptEditor((s) => s.loadDraftFromClap)
25
  const onDidScrollChange = useScriptEditor((s) => s.onDidScrollChange)
26
  const jumpCursorOnLineClick = useScriptEditor((s) => s.jumpCursorOnLineClick)
27
 
28
- const getClap = useTimeline((s: TimelineStore) => s.getClap)
29
-
30
- useEffect(() => {
31
- const fn = async () => {
32
- loadDraftFromClap(await getClap())
33
- }
34
- fn()
35
- }, [getClap])
36
-
37
  const scrollHeight = useScriptEditor((s) => s.scrollHeight)
38
 
39
  const scrollX = useTimeline((s) => s.scrollX)
 
21
  const current = useScriptEditor((s) => s.current)
22
  const setCurrent = useScriptEditor((s) => s.setCurrent)
23
  const publish = useScriptEditor((s) => s.publish)
 
24
  const onDidScrollChange = useScriptEditor((s) => s.onDidScrollChange)
25
  const jumpCursorOnLineClick = useScriptEditor((s) => s.jumpCursorOnLineClick)
26
 
 
 
 
 
 
 
 
 
 
27
  const scrollHeight = useScriptEditor((s) => s.scrollHeight)
28
 
29
  const scrollX = useTimeline((s) => s.scrollX)
src/services/io/useIO.ts CHANGED
@@ -26,7 +26,12 @@ import {
26
  clapSegmentToTimelineSegment,
27
  } from '@aitube/timeline'
28
  import { ParseScriptProgressUpdate, parseScriptToClap } from '@aitube/broadway'
29
- import { IOStore, TaskCategory, TaskVisibility } from '@aitube/clapper-services'
 
 
 
 
 
30
  import { create } from 'zustand'
31
  import * as fflate from 'fflate'
32
 
@@ -52,6 +57,7 @@ import { extractScenesFromVideo } from './extractScenesFromVideo'
52
  import { base64DataUriToFile } from '@/lib/utils/base64DataUriToFile'
53
  import { useUI } from '../ui'
54
  import { getTypeAndExtension } from '@/lib/utils/getTypeAndExtension'
 
55
 
56
  export const useIO = create<IOStore>((set, get) => ({
57
  ...getDefaultIOState(),
@@ -246,6 +252,7 @@ export const useIO = create<IOStore>((set, get) => ({
246
  : await new Response(fileContent).text()
247
 
248
  const timeline: TimelineStore = useTimeline.getState()
 
249
  const task = useTasks.getState().add({
250
  category: TaskCategory.IMPORT,
251
  visibility: TaskVisibility.BLOCKER,
@@ -296,6 +303,7 @@ export const useIO = create<IOStore>((set, get) => ({
296
  })
297
 
298
  await timeline.setClap(clap)
 
299
 
300
  task.setProgress({
301
  message: 'Nearly there..',
@@ -312,6 +320,7 @@ export const useIO = create<IOStore>((set, get) => ({
312
  },
313
  openScreenplayUrl: async (url: string) => {
314
  const timeline: TimelineStore = useTimeline.getState()
 
315
 
316
  const { fileName, projectName } = parseFileName(
317
  `${url.split('/').pop() || url}`
@@ -355,6 +364,7 @@ export const useIO = create<IOStore>((set, get) => ({
355
  })
356
 
357
  await timeline.setClap(clap)
 
358
 
359
  task.setProgress({
360
  message: 'Nearly there..',
@@ -389,6 +399,7 @@ export const useIO = create<IOStore>((set, get) => ({
389
 
390
  openClapUrl: async (url: string) => {
391
  const timeline: TimelineStore = useTimeline.getState()
 
392
  const { setClap } = timeline
393
 
394
  const { fileName, projectName } = parseFileName(
@@ -426,6 +437,7 @@ export const useIO = create<IOStore>((set, get) => ({
426
  })
427
 
428
  await setClap(clap)
 
429
 
430
  task.success()
431
  } catch (err) {
@@ -435,6 +447,7 @@ export const useIO = create<IOStore>((set, get) => ({
435
  },
436
  openClapBlob: async (projectName: string, fileName: string, blob: Blob) => {
437
  const timeline: TimelineStore = useTimeline.getState()
 
438
  const { setClap } = timeline
439
 
440
  const task = useTasks.getState().add({
@@ -459,6 +472,7 @@ export const useIO = create<IOStore>((set, get) => ({
459
  })
460
 
461
  await setClap(clap)
 
462
 
463
  task.success()
464
  } catch (err) {
 
26
  clapSegmentToTimelineSegment,
27
  } from '@aitube/timeline'
28
  import { ParseScriptProgressUpdate, parseScriptToClap } from '@aitube/broadway'
29
+ import {
30
+ IOStore,
31
+ ScriptEditorStore,
32
+ TaskCategory,
33
+ TaskVisibility,
34
+ } from '@aitube/clapper-services'
35
  import { create } from 'zustand'
36
  import * as fflate from 'fflate'
37
 
 
57
  import { base64DataUriToFile } from '@/lib/utils/base64DataUriToFile'
58
  import { useUI } from '../ui'
59
  import { getTypeAndExtension } from '@/lib/utils/getTypeAndExtension'
60
+ import { useScriptEditor } from '../editors'
61
 
62
  export const useIO = create<IOStore>((set, get) => ({
63
  ...getDefaultIOState(),
 
252
  : await new Response(fileContent).text()
253
 
254
  const timeline: TimelineStore = useTimeline.getState()
255
+ const scriptEditor: ScriptEditorStore = useScriptEditor.getState()
256
  const task = useTasks.getState().add({
257
  category: TaskCategory.IMPORT,
258
  visibility: TaskVisibility.BLOCKER,
 
303
  })
304
 
305
  await timeline.setClap(clap)
306
+ scriptEditor.loadDraftFromClap(clap)
307
 
308
  task.setProgress({
309
  message: 'Nearly there..',
 
320
  },
321
  openScreenplayUrl: async (url: string) => {
322
  const timeline: TimelineStore = useTimeline.getState()
323
+ const scriptEditor: ScriptEditorStore = useScriptEditor.getState()
324
 
325
  const { fileName, projectName } = parseFileName(
326
  `${url.split('/').pop() || url}`
 
364
  })
365
 
366
  await timeline.setClap(clap)
367
+ scriptEditor.loadDraftFromClap(clap)
368
 
369
  task.setProgress({
370
  message: 'Nearly there..',
 
399
 
400
  openClapUrl: async (url: string) => {
401
  const timeline: TimelineStore = useTimeline.getState()
402
+ const scriptEditor: ScriptEditorStore = useScriptEditor.getState()
403
  const { setClap } = timeline
404
 
405
  const { fileName, projectName } = parseFileName(
 
437
  })
438
 
439
  await setClap(clap)
440
+ scriptEditor.loadDraftFromClap(clap)
441
 
442
  task.success()
443
  } catch (err) {
 
447
  },
448
  openClapBlob: async (projectName: string, fileName: string, blob: Blob) => {
449
  const timeline: TimelineStore = useTimeline.getState()
450
+ const scriptEditor: ScriptEditorStore = useScriptEditor.getState()
451
  const { setClap } = timeline
452
 
453
  const task = useTasks.getState().add({
 
472
  })
473
 
474
  await setClap(clap)
475
+ scriptEditor.loadDraftFromClap(clap)
476
 
477
  task.success()
478
  } catch (err) {