-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: WIP implementation of Client data model
- Loading branch information
Showing
11 changed files
with
296 additions
and
17 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:react-hooks/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react-hooks/recommended'], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], | ||
'no-unused-vars': 'off', | ||
'@typescript-eslint/no-unused-vars': [ | ||
'warn', // or "error" | ||
{ | ||
argsIgnorePattern: '^_', | ||
varsIgnorePattern: '^_', | ||
caughtErrorsIgnorePattern: '^_', | ||
}, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import uuid from 'uuid'; | ||
|
||
export function randomId() { | ||
return uuid.v4() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Part, PartDisplayType, PartId, ProtectedString, protectString } from 'packages/shared/model/dist' | ||
import { RundownStore } from '../stores/RundownStore' | ||
import { randomId } from '../lib/lib' | ||
import { makeAutoObservable } from 'mobx' | ||
|
||
export class UILine { | ||
slug: string = '' | ||
|
||
rank: number = 0 | ||
|
||
identifier: string | null = null | ||
|
||
lineType: { | ||
label: string | ||
|
||
style: LineType | ||
} | null = null | ||
|
||
script: string | null = null | ||
|
||
expectedDuration: number | null = null | ||
|
||
isNew: boolean = false | ||
|
||
ready: boolean = false | ||
|
||
constructor(private store: RundownStore, public partId: PartId, public id = protectString<UILineId>(randomId())) { | ||
makeAutoObservable(this) | ||
|
||
void this.store | ||
} | ||
|
||
updateFromJson(json: Part) { | ||
this.identifier = json.identifier ?? null | ||
this.slug = json.label | ||
this.rank = json.rank | ||
this.script = json.scriptContents ?? null | ||
this.isNew = json.isNew ?? false | ||
this.expectedDuration = json.expectedDuration ?? null | ||
this.lineType = { | ||
label: json.display.label, | ||
style: partDisplayTypeToLineTypeStyle(json.display.type), | ||
} | ||
|
||
this.ready = true | ||
} | ||
|
||
remove() {} | ||
} | ||
|
||
export type UILineId = ProtectedString<'UILineId', string> | ||
|
||
function partDisplayTypeToLineTypeStyle(_type: PartDisplayType): LineType { | ||
return LineType.VT | ||
} | ||
|
||
export enum LineType { | ||
VT = 'vt', | ||
LiveSpeak = 'liveSpeak', | ||
Remote = 'remote', | ||
Split = 'split', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { computed, makeAutoObservable, observable } from 'mobx' | ||
import { ProtectedString, RundownPlaylist, RundownPlaylistId, protectString } from 'packages/shared/model/dist' | ||
import { UISegment, UISegmentId } from './UISegment' | ||
import { RundownStore } from '../stores/RundownStore' | ||
import { randomId } from '../lib/lib' | ||
|
||
export class UIRundown { | ||
name: string = '' | ||
|
||
ready: boolean = false | ||
|
||
segments = observable.map<UISegmentId, UISegment>() | ||
|
||
constructor( | ||
private store: RundownStore, | ||
public playlistId: RundownPlaylistId, | ||
public id = protectString<UIRundownId>(randomId()) | ||
) { | ||
makeAutoObservable(this, { | ||
segmentIdsInOrder: computed, | ||
}) | ||
|
||
void this.store | ||
|
||
// get all segments | ||
// this.store.connection.segment.find({ | ||
// query: { | ||
// playlistId: | ||
// } | ||
// }) | ||
|
||
// register callbacks for events | ||
// this.store.connection.segment.on('created') | ||
} | ||
|
||
updateFromJson(json: RundownPlaylist) { | ||
this.name = json.label | ||
this.ready = true | ||
} | ||
|
||
get segmentIdsInOrder(): UISegmentId[] { | ||
return [] | ||
} | ||
|
||
dispose(): void { | ||
// unregister event handlers from services | ||
} | ||
} | ||
|
||
export type UIRundownId = ProtectedString<'UIRundownId', string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// a lightweight domain object for tracking rundowns without their contents | ||
export class UIRundownEntry { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { computed, makeAutoObservable, observable, values } from 'mobx' | ||
import { ProtectedString, Segment, SegmentId, protectString } from 'packages/shared/model/dist' | ||
import { UILineId, UILine } from './UILine' | ||
import { RundownStore } from '../stores/RundownStore' | ||
import { randomId } from '../lib/lib' | ||
|
||
export class UISegment { | ||
rank: number = 0 | ||
|
||
name: string = '' | ||
|
||
ready: boolean = false | ||
|
||
lines = observable.map<UILineId, UILine>([]) | ||
|
||
constructor( | ||
private store: RundownStore, | ||
public segmentId: SegmentId, | ||
public id = protectString<UISegmentId>(randomId()) | ||
) { | ||
makeAutoObservable(this, { | ||
lineIdsInOrder: computed, | ||
}) | ||
|
||
// fetch owned parts and register event handlers for parts | ||
} | ||
|
||
updateFromJson(json: Segment) { | ||
this.name = json.label | ||
this.rank = json.rank | ||
|
||
this.ready = true | ||
} | ||
|
||
get lineIdsInOrder(): UILineId[] { | ||
return values(this.lines).slice().sort((a, b) => a.rank - b.rank).map((line) => line.id) | ||
} | ||
|
||
remove(): void { | ||
this.store.openRundown?.segments.delete(this.id) | ||
// unregister event handlers | ||
} | ||
} | ||
|
||
export type UISegmentId = ProtectedString<'UISegmentId', string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { makeAutoObservable, action } from 'mobx' | ||
import { RundownStore } from './RundownStore' | ||
import { APIConnection } from '../api/ApiConnection' | ||
|
||
export class AppStore { | ||
connected = false | ||
rundownStore: RundownStore | ||
connection = new APIConnection() | ||
|
||
constructor() { | ||
makeAutoObservable(this) | ||
this.rundownStore = new RundownStore(this, this.connection) | ||
|
||
this.connection.on( | ||
'connected', | ||
action('setConnected', () => { | ||
this.connected = true | ||
}) | ||
) | ||
|
||
this.connection.on( | ||
'disconnected', | ||
action('setDisconnected', () => { | ||
this.connected = false | ||
}) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { makeAutoObservable, observable, action } from 'mobx' | ||
import { RundownPlaylistId } from 'packages/shared/model/dist' | ||
import { AppStore } from './AppStore' | ||
import { APIConnection } from '../api/ApiConnection' | ||
import { UIRundown } from '../model/UIRundown' | ||
import { UIRundownEntry } from '../model/UIRundownEntry' | ||
|
||
export class RundownStore { | ||
showingOnlyScripts = false | ||
|
||
allRundowns = observable.array<UIRundownEntry>() | ||
openRundown: UIRundown | null = null | ||
|
||
constructor(public appStore: AppStore, public connection: APIConnection) { | ||
makeAutoObservable(this, {}) | ||
|
||
// get all rundowns | ||
this.connection.playlist.on('created', () => {}) | ||
this.loadAllRudnowns() | ||
} | ||
|
||
loadAllRudnowns() { | ||
this.connection.playlist.find().then( | ||
action('receiveRundowns', () => { | ||
// add UIRundownEntries to allRundowns | ||
}) | ||
) | ||
} | ||
|
||
loadRundown(id: RundownPlaylistId) { | ||
console.log(id) | ||
// get a full rundown from backend and create a UIRundown object | ||
// assign to openRundown | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters