diff --git a/client-v3/src/stores/script.ts b/client-v3/src/stores/script.ts index e16c3f19..1e8fb89a 100644 --- a/client-v3/src/stores/script.ts +++ b/client-v3/src/stores/script.ts @@ -2,6 +2,7 @@ import { defineStore } from 'pinia'; import log from 'loglevel'; import { makeURL } from '@/js/utils'; import { toast } from '@/js/toast'; +import { useScriptConfigStore } from '@/stores/scriptConfig'; import type { ScriptLine, StageDirectionStyle, @@ -47,6 +48,17 @@ export const useScriptStore = defineStore('script', { } }, + async scriptPageChanged(data: { page: number }): Promise { + const pageStr = String(data.page); + if (Object.hasOwn(this.script, pageStr)) { + await this.loadScriptPage(data.page); + const scriptConfigStore = useScriptConfigStore(); + if (Object.hasOwn(scriptConfigStore.tmpScript, pageStr)) { + scriptConfigStore.addPage(data.page, this.getScriptPage(data.page)); + } + } + }, + async saveNewPage(page: number, lines: ScriptLine[]): Promise { const params = new URLSearchParams({ page: String(page) }); const response = await fetch(`${makeURL('/api/v1/show/script')}?${params}`, { diff --git a/client/src/store/modules/script.ts b/client/src/store/modules/script.ts index cb7e453d..740f9c9a 100644 --- a/client/src/store/modules/script.ts +++ b/client/src/store/modules/script.ts @@ -145,6 +145,13 @@ const module: Module = { await context.dispatch('LOAD_CUES'); await context.dispatch('GET_CUTS'); }, + async SCRIPT_PAGE_CHANGED(context, msg: { DATA: { page: number } }) { + const page = String(msg.DATA.page); + if (Object.hasOwn(context.state.script, page)) { + await context.dispatch('LOAD_SCRIPT_PAGE', page); + await context.dispatch('ADD_BLANK_PAGE', page); + } + }, async LOAD_SCRIPT_PAGE(context, page: string | number) { const searchParams = new URLSearchParams({ page: String(page) }); const response = await fetch(`${makeURL('/api/v1/show/script')}?${searchParams}`, { diff --git a/server/controllers/api/show/script/script.py b/server/controllers/api/show/script/script.py index cd61959a..cb9b6212 100644 --- a/server/controllers/api/show/script/script.py +++ b/server/controllers/api/show/script/script.py @@ -269,6 +269,9 @@ async def post(self): CompiledScript.compile_script, self.application, revision.id ) ) + await self.application.ws_send_to_all( + "NOOP", "SCRIPT_PAGE_CHANGED", {"page": page} + ) else: self.set_status(404) await self.finish({"message": ERROR_SHOW_NOT_FOUND}) @@ -663,11 +666,15 @@ async def patch(self): (revision.id, line["id"]), ) # Spawn a callback to create a compiled version of the script + session.commit() IOLoop.current().add_callback( partial( CompiledScript.compile_script, self.application, revision.id ) ) + await self.application.ws_send_to_all( + "NOOP", "SCRIPT_PAGE_CHANGED", {"page": page} + ) else: self.set_status(404) await self.finish({"message": ERROR_SHOW_NOT_FOUND})