From e5e1733ecedb8da8b1355a4ae5bc48d789fb8d9e Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Wed, 18 Oct 2023 16:04:33 +0200 Subject: [PATCH] chore: enums --- apps/app/src/electron/api/ApiServer.ts | 6 +++--- apps/app/src/electron/api/ProjectService.ts | 4 ++-- apps/app/src/electron/api/RundownService.ts | 4 ++-- apps/app/src/ipc/IPCAPI.ts | 7 +++++++ apps/app/src/react/api/RealtimeDataProvider.ts | 8 +++++--- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/app/src/electron/api/ApiServer.ts b/apps/app/src/electron/api/ApiServer.ts index 3bb603f2..21c1a0da 100644 --- a/apps/app/src/electron/api/ApiServer.ts +++ b/apps/app/src/electron/api/ApiServer.ts @@ -10,7 +10,7 @@ import { RundownService, RUNDOWN_CHANNEL_PREFIX } from './RundownService' import { LegacyService } from './LegacyService' import { ReportingService } from './ReportingService' import { PROJECTS_CHANNEL_PREFIX, ProjectService } from './ProjectService' -import { ClientMethods, ServiceName, ServiceTypes } from '../../ipc/IPCAPI' +import { ClientMethods, ProjectsEvents, RundownsEvents, ServiceName, ServiceTypes } from '../../ipc/IPCAPI' import { Project, ProjectBase } from '../../models/project/Project' import { PartService } from './PartService' import { GroupService } from './GroupService' @@ -40,7 +40,7 @@ export class ApiServer { this.app.use(ServiceName.PROJECTS, new ProjectService(this.app, ipcServer, clientEventBus), { methods: ClientMethods[ServiceName.PROJECTS], - serviceEvents: ['created', 'updated', 'deleted'], + serviceEvents: ['created', ProjectsEvents.UPDATED, 'deleted'], }) this.app.use(ServiceName.PARTS, new PartService(this.app, ipcServer, clientEventBus), { @@ -52,7 +52,7 @@ export class ApiServer { this.app.use(ServiceName.RUNDOWNS, new RundownService(this.app, ipcServer, clientEventBus), { // TODO: what if we made a base class for Services and made those arrays fields so that they live nearvy the implementation? methods: ClientMethods[ServiceName.RUNDOWNS], - serviceEvents: ['created', 'updated', 'deleted'], + serviceEvents: ['created', RundownsEvents.UPDATED, 'deleted'], }) this.app.use(ServiceName.REPORTING, new ReportingService(this.app, ipcServer), { diff --git a/apps/app/src/electron/api/ProjectService.ts b/apps/app/src/electron/api/ProjectService.ts index 1a64f6c3..6649a9d8 100644 --- a/apps/app/src/electron/api/ProjectService.ts +++ b/apps/app/src/electron/api/ProjectService.ts @@ -1,7 +1,7 @@ import { EverythingService } from '../EverythingService' import { Application, Params } from '@feathersjs/feathers' import EventEmitter from 'node:events' -import { ServiceTypes } from '../../ipc/IPCAPI' +import { ProjectsEvents, ServiceTypes } from '../../ipc/IPCAPI' import { Project, ProjectBase } from '../../models/project/Project' import { ClientEventBus } from '../ClientEventBus' @@ -14,7 +14,7 @@ export class ProjectService extends EventEmitter { ) { super() clientEventBus.on('updateProject', (project: Project) => { - this.emit('updated', project) + this.emit(ProjectsEvents.UPDATED, project) }) } diff --git a/apps/app/src/electron/api/RundownService.ts b/apps/app/src/electron/api/RundownService.ts index e5ef9ad7..09eaade7 100644 --- a/apps/app/src/electron/api/RundownService.ts +++ b/apps/app/src/electron/api/RundownService.ts @@ -3,7 +3,7 @@ import { Application, Params } from '@feathersjs/feathers' import { Rundown } from '../../models/rundown/Rundown' import EventEmitter from 'node:events' import { GeneralError, NotFound } from '@feathersjs/errors' -import { ServiceTypes } from '../../ipc/IPCAPI' +import { RundownsEvents, ServiceTypes } from '../../ipc/IPCAPI' import { PartialDeep } from 'type-fest/source/partial-deep' import { TimelineObj } from '../../models/rundown/TimelineObj' import { ClientEventBus } from '../ClientEventBus' @@ -34,7 +34,7 @@ export class RundownService extends EventEmitter { ) { super() clientEventBus.on('updateRundown', (rundown: Rundown) => { - this.emit('updated', rundown) + this.emit(RundownsEvents.UPDATED, rundown) }) } diff --git a/apps/app/src/ipc/IPCAPI.ts b/apps/app/src/ipc/IPCAPI.ts index c11a2a0d..fb2f7658 100644 --- a/apps/app/src/ipc/IPCAPI.ts +++ b/apps/app/src/ipc/IPCAPI.ts @@ -369,3 +369,10 @@ export interface SystemMessageOptions { displayRestartButton?: boolean } export type UpdateAppDataOptions = Pick + +export enum RundownsEvents { + UPDATED = 'updated', +} +export enum ProjectsEvents { + UPDATED = 'updated', +} diff --git a/apps/app/src/react/api/RealtimeDataProvider.ts b/apps/app/src/react/api/RealtimeDataProvider.ts index 3d8cd3dc..01283b12 100644 --- a/apps/app/src/react/api/RealtimeDataProvider.ts +++ b/apps/app/src/react/api/RealtimeDataProvider.ts @@ -1,4 +1,4 @@ -import { ServiceName, SystemMessageOptions } from '../../ipc/IPCAPI' +import { ProjectsEvents, RundownsEvents, ServiceName, SystemMessageOptions } from '../../ipc/IPCAPI' import { BridgeStatus } from '../../models/project/Bridge' import { Project } from '../../models/project/Project' import { PeripheralStatus } from '../../models/project/Peripheral' @@ -40,8 +40,10 @@ export class RealtimeDataProvider { } ) { // this is new: - app.service(ServiceName.RUNDOWNS).on('updated', (rundown) => this.updateRundown(rundown.id, rundown)) - app.service(ServiceName.PROJECTS).on('updated', (project) => this.updateProject(project)) + app.service(ServiceName.RUNDOWNS).on(RundownsEvents.UPDATED, (rundown) => + this.updateRundown(rundown.id, rundown) + ) + app.service(ServiceName.PROJECTS).on(ProjectsEvents.UPDATED, (project) => this.updateProject(project)) // app.service('project').on(...) etc. // this is temporary: