refactor: type improvements (#751)

This commit is contained in:
Carlos Valente
2024-01-31 14:42:33 +01:00
committed by GitHub
parent 7eb9ee8d03
commit cf08bfc796
17 changed files with 48 additions and 37 deletions
@@ -23,7 +23,7 @@ class ErrorBoundary extends React.Component {
componentDidCatch(error, info) {
this.setState({
error: error,
error,
errorInfo: info,
});
@@ -12,7 +12,7 @@ import {
useDisclosure,
} from '@chakra-ui/react';
import { useLocalStorage } from '../../../common/hooks/useLocalStorage';
import { useLocalStorage } from '../../hooks/useLocalStorage';
import ParamInput from './ParamInput';
import { ParamField } from './types';
@@ -7,7 +7,7 @@ import { IoTrashOutline } from '@react-icons/all-files/io5/IoTrashOutline';
import { SupportedEvent } from 'ontime-types';
import { useEventAction } from '../../common/hooks/useEventAction';
import { useEventSelection } from '../../features/rundown/useEventSelection';
import { useEventSelection } from '../rundown/useEventSelection';
const RundownMenu = ({ children }: { children: ReactNode }) => {
const { clearSelectedEvents } = useEventSelection();
@@ -52,7 +52,7 @@ export default function Operator() {
const scrollRef = useRef<HTMLDivElement | null>(null);
const scrollToComponent = useFollowComponent({
followRef: selectedRef,
scrollRef: scrollRef,
scrollRef,
doFollow: !lockAutoScroll,
topOffset: selectedOffset,
});
@@ -44,7 +44,7 @@ export const useEventSelection = create<EventSelectionStore>()((set, get) => ({
selectedEvents.delete(id);
return set({
selectedEvents: selectedEvents,
selectedEvents,
anchoredIndex: newAnchoredIndex?.index ?? 0,
});
}
+1 -1
View File
@@ -200,7 +200,7 @@ export const startServer = async () => {
* @param overrideConfig
* @return {Promise<void>}
*/
export const startOSCServer = async (overrideConfig = null) => {
export const startOSCServer = async (overrideConfig?: { port: number }) => {
checkStart(OntimeStartOrder.InitIO);
const { osc } = DataProvider.getData();
@@ -10,8 +10,6 @@ export class SimpleTimer {
private startedAt: number | null = null;
private pausedAt: number | null = null;
constructor() {}
public reset() {
this.state = {
duration: 0,
@@ -72,7 +72,8 @@ describe('SimpleTimer count-down', () => {
expect(newState).toStrictEqual(expected);
newState = timer.update(1800);
(expected.current = initialTime - 1800 + pausedTime), expect(newState).toStrictEqual(expected);
expected.current = initialTime - 1800 + pausedTime;
expect(newState).toStrictEqual(expected);
});
test('stopping the timer clears the running data', () => {
@@ -52,7 +52,7 @@ export function updateEvent(
const event = EventLoader.getEventWithId(eventId);
if (event) {
if (!isOntimeEvent(event)) {
throw new Error(`Can only update events`);
throw new Error('Can only update events');
}
const propertiesToUpdate = { [propertyName]: newValue };
@@ -115,7 +115,7 @@ const parseAndApply = async (file, _req, res, options) => {
*/
const getNetworkInterfaces = () => {
const nets = networkInterfaces();
const results = [];
const results: { name: string; address: string }[] = [];
for (const name of Object.keys(nets)) {
for (const net of nets[name]) {
+1 -1
View File
@@ -12,7 +12,7 @@ export const populateDemo = () => {
Promise.all(
resolveDemoPath.map((to, index) => {
const from = pathToStartDemo[index];
copyFile(from, to);
return copyFile(from, to);
}),
);
} catch (_) {
@@ -34,18 +34,10 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
}
this.initSubscriptions(subscriptions);
try {
return {
success: true,
message: `HTTP integration client ready`,
};
} catch (error) {
return {
success: false,
message: `Failed initialising HTTP integration: ${error}`,
};
}
return {
success: true,
message: 'HTTP integration client ready',
};
}
initSubscriptions(subscriptionOptions: HttpSubscription) {
@@ -99,6 +99,10 @@ export class OscIntegration implements IIntegration<OscSubscriptionOptions> {
}
emit(path: string, payload?: ArgumentType) {
if (!this.oscClient) {
return;
}
const message = new Message(path);
if (payload) {
try {
@@ -14,8 +14,6 @@ import * as runtimeState from '../../stores/runtimeState.js';
class RuntimeService {
private eventTimer: TimerService | null = null;
constructor() {}
init(resumable: RestorePoint | null) {
logger.info(LogOrigin.Server, 'Runtime service started');
// TODO: refresh at 32ms, slowing down now to keep UI responsive while we dont have granular updates
@@ -339,6 +337,11 @@ class RuntimeService {
const { selectedEventId, playback } = restorePoint;
if (playback === Playback.Roll) {
this.roll();
return;
}
if (!selectedEventId) {
return;
}
// the db would have to change for the event not to exist
+15 -2
View File
@@ -1,4 +1,4 @@
import { MaybeNumber, OntimeEvent, TimerType } from 'ontime-types';
import { MaybeNumber, MaybeString, OntimeEvent, TimerType } from 'ontime-types';
import { dayInMs } from 'ontime-utils';
import { RuntimeState } from '../stores/runtimeState.js';
import { sortArrayByProperty } from '../utils/arrayUtils.js';
@@ -94,13 +94,26 @@ export function skippedOutOfEvent(state: RuntimeState, previousTime: number, ski
return hasSkipped && (adjustedClock > adjustedExpectedFinish || adjustedClock < startedAt);
}
type RollTimers = {
nowIndex: MaybeNumber;
nowId: MaybeString;
publicIndex: MaybeNumber;
nextIndex: MaybeNumber;
publicNextIndex: MaybeNumber;
timeToNext: MaybeNumber;
nextEvent: OntimeEvent | null;
nextPublicEvent: OntimeEvent | null;
currentEvent: OntimeEvent | null;
currentPublicEvent: OntimeEvent | null;
};
/**
* Finds loading information given a current rundown and time
* @param {OntimeEvent[]} rundown - List of playable events
* @param {number} timeNow - time now in ms
* @returns {{}}
*/
export const getRollTimers = (rundown: OntimeEvent[], timeNow: number) => {
export const getRollTimers = (rundown: OntimeEvent[], timeNow: number): RollTimers => {
let nowIndex: number | null = null; // index of event now
let nowId: string | null = null; // id of event now
let publicIndex: number | null = null; // index of public event now
+5 -5
View File
@@ -100,7 +100,7 @@ class Sheet {
this.authServerTimeout = setTimeout(
() => {
Sheet.authUrl = null;
server.unref;
server.unref();
},
2 * 60 * 1000,
);
@@ -140,7 +140,7 @@ class Sheet {
}
if (!searchParams.has('code')) {
res.end('No authentication code provided.');
logger.info(LogOrigin.Server, `Sheet: Cannot read authentication code`);
logger.info(LogOrigin.Server, 'Sheet: Cannot read authentication code');
return;
}
const code = searchParams.get('code');
@@ -151,7 +151,7 @@ class Sheet {
client.credentials = tokens;
Sheet.client = client;
res.end('Authentication successful! Please close this tab and return to OnTime.');
logger.info(LogOrigin.Server, `Sheet: Authentication successful`);
logger.info(LogOrigin.Server, 'Sheet: Authentication successful');
} catch (e) {
logger.error(LogOrigin.Server, `Sheet: ${e}`);
} finally {
@@ -277,7 +277,7 @@ class Sheet {
spreadsheetId: id,
valueRenderOption: 'FORMATTED_VALUE',
majorDimension: 'ROWS',
range: range,
range,
});
if (readResponse.status === 200) {
const { rundownMetadata } = parseExcel(readResponse.data.values, options);
@@ -364,7 +364,7 @@ class Sheet {
const dataFromSheet = parseExcel(googleResponse.data.values, options);
res.data.rundown = parseRundown(dataFromSheet);
if (res.data.rundown.length < 1) {
throw new Error(`Sheet: Could not find data to import in the worksheet`);
throw new Error('Sheet: Could not find data to import in the worksheet');
}
res.data.userFields = parseUserFields(dataFromSheet);
return res;
@@ -7,8 +7,8 @@ import { ensureDirectory } from './fileManagement.js';
import { getAppDataPath } from '../setup.js';
function generateNewFileName(filePath, callback) {
let baseName = path.basename(filePath, path.extname(filePath));
let extension = path.extname(filePath);
const baseName = path.basename(filePath, path.extname(filePath));
const extension = path.extname(filePath);
let counter = 1;
const checkExistence = (newPath) => {
@@ -24,7 +24,7 @@ function generateNewFileName(filePath, callback) {
});
};
let newPath = path.join(path.dirname(filePath), `${baseName} (${counter})${extension}`);
const newPath = path.join(path.dirname(filePath), `${baseName} (${counter})${extension}`);
checkExistence(newPath);
}
@@ -75,6 +75,6 @@ const filterAllowed = (req, file, cb) => {
// Build multer uploader for a single file
export const uploadFile = multer({
storage: storage,
storage,
fileFilter: filterAllowed,
}).single('userFile');