Skip to content

Commit

Permalink
fix: set rundown rank using playlist.rundownIdsInOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Jan 17, 2024
1 parent ea6084b commit 82b24d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export class RundownPlaylistHandler extends DataHandler {

if (!playlist) {
this.store.playlists.remove(this.convertId(id))
this.transformers.rundowns.updateCorePlaylist(id, undefined)
} else {
this.store.playlists.create(this.convert(playlist))
this.transformers.rundowns.updateCorePlaylist(id, playlist)
}
}
private onChanged(id: Core.RundownPlaylistId): void {
Expand All @@ -35,8 +37,10 @@ export class RundownPlaylistHandler extends DataHandler {

if (!playlist) {
this.store.playlists.remove(this.convertId(id))
this.transformers.rundowns.updateCorePlaylist(id, undefined)
} else {
this.store.playlists.update(this.convert(playlist))
this.transformers.rundowns.updateCorePlaylist(id, playlist)
}
}
private onRemoved(id: Core.RundownPlaylistId): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class RundownTransformer {
// public readonly rundowns = observable.map<RundownId, Rundown>()

private readonly coreRundowns = observable.map<Core.RundownId, Core.Rundown>()
private readonly corePlaylistsInfo = observable.map<Core.RundownPlaylistId, CorePlaylistInfo>()

constructor() {
makeObservable(this, {
Expand Down Expand Up @@ -51,15 +52,21 @@ export class RundownTransformer {
const coreRundown = this.coreRundowns.get(coreRundownId)
if (!coreRundown) return undefined

const playlist = this.corePlaylistsInfo.get(coreRundown.playlistId)
if (!playlist) return undefined

const rank = playlist.rundownIdsInOrder.indexOf(coreRundownId)

return {
_id: this.convertId<Core.RundownId, RundownId>(coreRundown._id),

playlistId: this.convertId<Core.RundownPlaylistId, RundownPlaylistId>(coreRundown.playlistId),
label: coreRundown.name,
rank: 0, // todo
rank: rank,
}
})

/** This is called whenever the data from Core changes */
updateCoreRundown(coreRundownId: Core.RundownId, coreRundown: Core.Rundown | undefined) {
if (coreRundown) {
if (!isEqual(this.coreRundowns.get(coreRundownId), coreRundown)) {
Expand All @@ -71,6 +78,20 @@ export class RundownTransformer {
}
}
}
/** This is called whenever the data from Core changes */
updateCorePlaylist(id: Core.RundownPlaylistId, playlist: Core.DBRundownPlaylist | undefined) {
if (playlist) {
const corePlaylistInfo: CorePlaylistInfo = {
rundownRanksAreSetInSofie: playlist.rundownRanksAreSetInSofie,
rundownIdsInOrder: playlist.rundownIdsInOrder,
}
if (!isEqual(this.corePlaylistsInfo.get(id), corePlaylistInfo)) {
this.corePlaylistsInfo.set(id, corePlaylistInfo)
}
} else {
this.corePlaylistsInfo.delete(id)
}
}

get showStyleBaseIds(): Core.ShowStyleBaseId[] {
const showStyleBaseIds = new Set<Core.ShowStyleBaseId>()
Expand All @@ -93,3 +114,5 @@ export class RundownTransformer {
return id as any
}
}

type CorePlaylistInfo = Pick<Core.DBRundownPlaylist, 'rundownRanksAreSetInSofie' | 'rundownIdsInOrder'>

0 comments on commit 82b24d9

Please sign in to comment.