Skip to content

Commit

Permalink
wip: basic storing of data
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Jan 25, 2024
1 parent 7952481 commit a102c7d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 24 deletions.
10 changes: 8 additions & 2 deletions packages/apps/backend/src/api-server/services/PartService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ export class PartService extends EventEmitter<Definition.Events> implements Defi
throw new NotImplemented(`Not supported`)
}

public async updateScript(_id: Id, _scriptContents: ScriptContents): Promise<void> {
throw new NotImplemented(`Not implemented`)
public async updateScript(
data: {
partId: Id
script: ScriptContents
},
_params?: Params
): Promise<void> {
this.store.parts.updateScript(data.partId, data.script)
}
}
type Result = Definition.Result
Expand Down
39 changes: 27 additions & 12 deletions packages/apps/backend/src/data-stores/PartStore.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { IReactionDisposer, action, autorun, makeObservable, observable } from 'mobx'
import isEqual from 'lodash.isequal'
import { Part, PartId } from '@sofie-prompter-editor/shared-model'
import { Part, PartId, ScriptContents } from '@sofie-prompter-editor/shared-model'
import { Transformers } from '../sofie-core-connection/dataTransformers/Transformers.js'

import * as Core from '../sofie-core-connection/CoreDataTypes/index.js'

export class PartStore {
public readonly parts = observable.map<PartId, Part>()

private readonly _partScripts = observable.map<PartId, ScriptContents>()

private partAutoruns = new Map<Core.PartId, IReactionDisposer>()

constructor() {
makeObservable(this, {
_updatePart: action,
_removePart: action,
})
}
connectTransformers(transformers: Transformers) {
// Observe and retrieve parts from the transformer:
autorun(() => {
Expand Down Expand Up @@ -56,10 +52,29 @@ export class PartStore {
}
})
}
_updatePart(partId: PartId, part: Part) {
this.parts.set(partId, part)
}
_removePart(partId: PartId) {

updateScript = action((id: PartId, scriptContents: string) => {
this._partScripts.set(id, scriptContents)

const part = this.parts.get(id)
if (!part) throw new Error('Not found')

this.parts.set(id, {
...part,
editedScriptContents: scriptContents,
})
})

private _updatePart = action((partId: PartId, part: Omit<Part, 'editedScriptContents'>) => {
const partExtended: Part = {
...part,
editedScriptContents: this._partScripts.get(partId),
}

this.parts.set(partId, partExtended)
})
private _removePart = action((partId: PartId) => {
this.parts.delete(partId)
}
this._partScripts.delete(partId)
})
}
9 changes: 5 additions & 4 deletions packages/apps/client/src/components/RundownOutput/Line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ export const Line = observer(function Line({ line }: { line: UILine }): React.Re
return (
<>
<h3>{line.slug}</h3>
{!line.script ? <p>&nbsp;</p> : null}
{line.script?.split('\n').map((paragraph) => (
<p key={paragraph}>{paragraph}</p>
))}
{!line.script ? (
<p>&nbsp;</p>
) : (
line.script.split('\n').map((paragraph, i) => <p key={paragraph + '_' + i}>{paragraph}</p>)
)}
</>
)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/client/src/lib/prosemirrorDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export function toMarkdown(nodes: ProsemirrorNode[]): string {

function stringifyMarkdown(mdAst: MdAstNode): string {
if (mdAst.type === 'root') {
return mdAst.children.map(stringifyMarkdown).join('')
return mdAst.children.map(stringifyMarkdown).join('\n')
} else if (mdAst.type === 'paragraph') {
return mdAst.children.map(stringifyMarkdown).join('') + '\n'
return mdAst.children.map(stringifyMarkdown).join('')
} else if (mdAst.type === 'text') {
return mdAst.value
} else if (mdAst.type === 'emphasis' || mdAst.type === 'strong' || mdAst.type === 'reverse') {
Expand Down
8 changes: 5 additions & 3 deletions packages/apps/client/src/model/UIRundown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ export class UIRundown {
existing.updateFromJson(json)
})

async updatePartScript(id: PartId, script: ScriptContents): Promise<void> {
// TODO - is this in the correct place?
await this.store.connection.part.updateScript(id, script)
async updatePartScript(partId: PartId, script: ScriptContents): Promise<void> {
await this.store.connection.part.updateScript({
partId,
script,
})

// TODO - should this have any side effects?
}
Expand Down
8 changes: 7 additions & 1 deletion packages/shared/model/src/client-server-api/PartService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ interface Methods extends Omit<ServiceMethods, 'patch'> {

/** updates .isNew */
// setIsNew(read: boolean): Promise<void>
updateScript(id: Id, scriptContents: ScriptContents): Promise<void>
updateScript(
data: {
partId: Id
script: ScriptContents
},
params?: Params
): Promise<void>
}
export interface Service extends Methods, EventEmitter<Events> {}

Expand Down
2 changes: 2 additions & 0 deletions packages/shared/model/src/model/Part.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export interface Part extends DataObject {
label: string // ie sourceLayer.name in Sofie
}

/** scriptContents from Core */
scriptContents?: ScriptContents
/** edited scriptContents. While this is set, display this in favor of scriptContents */
editedScriptContents?: ScriptContents
}

Expand Down

0 comments on commit a102c7d

Please sign in to comment.