Skip to content

Commit 6fc7eea

Browse files
committed
feat: added default layout when starting first time
1 parent 46ade7d commit 6fc7eea

File tree

6 files changed

+537
-35
lines changed

6 files changed

+537
-35
lines changed

src/client/Components/Overlay.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React, { useEffect, useState } from "react";
22
import { io } from "socket.io-client";
3-
import { ILabelAndTallyState, ISource } from "../../sharedcode/interfaces";
3+
import { IGlobalSettings, ILabelAndTallyState, ISettings, ISource } from "../../sharedcode/interfaces";
44
import * as IO from "../../sharedcode/IO_CONSTANTS";
55
import "../style/app.css";
66
import { SourceOverlay } from "./SourceOverlay";
77

88
const Overlay = () => {
99
const [sources, setSources] = useState<ISource[]>([]);
10+
const [globalSettings, setGlobalSettings] = useState<IGlobalSettings>({} as IGlobalSettings);
1011
const [labelAndTallyState, setLabelAndTallyState] = useState<
1112
ILabelAndTallyState[]
1213
>([]);
@@ -16,8 +17,9 @@ const Overlay = () => {
1617
console.log("socketClient :", socketClient);
1718
socketClient.emit(IO.GET_SETTINGS);
1819
socketClient
19-
.on(IO.SEND_SETTINGS, (receivedSources: ISource[]) => {
20-
setSources(receivedSources);
20+
.on(IO.SEND_SETTINGS, (receivedSettings: ISettings) => {
21+
setSources(receivedSettings.sources);
22+
setGlobalSettings(receivedSettings.globalSettings);
2123
})
2224
.on(IO.SEND_STATE, (receivedState: ILabelAndTallyState[]) => {
2325
setLabelAndTallyState(receivedState);
@@ -31,6 +33,7 @@ const Overlay = () => {
3133
<SourceOverlay
3234
key={index}
3335
source={source}
36+
globalSettings={globalSettings}
3437
labelAndTallyState={labelAndTallyState[source.emberStateIndex]}
3538
/>
3639
))}

src/client/Components/SourceOverlay.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import React from "react";
22
import {
3+
IGlobalSettings,
34
ILabelAndTallyState,
45
ISource,
56
ISourceElement,
67
} from "../../sharedcode/interfaces";
78

89
interface ISourceOverlayProps {
910
source: ISource;
11+
globalSettings: IGlobalSettings;
1012
labelAndTallyState: ILabelAndTallyState;
1113
}
1214

1315
const windowStyling = (
1416
source: ISource,
17+
globalSettings: IGlobalSettings,
1518
tally: boolean,
1619
tallyColor: string
1720
): React.CSSProperties => {
@@ -21,14 +24,17 @@ const windowStyling = (
2124
left: source.positionX,
2225
width: source.width,
2326
height: source.height,
24-
border: "solid 3px " + (tally ? tallyColor : "grey"),
27+
border: "solid " + globalSettings.borderWidth + " " + (tally ? tallyColor : "grey"),
28+
borderRadius: globalSettings.borderRadius,
2529
color: "red",
2630
fontSize: "1.5rem",
31+
fontFamily: globalSettings.fontFamily,
2732
};
2833
};
2934

3035
const labelStyling = (
3136
element: ISourceElement,
37+
globalSettings: IGlobalSettings,
3238
tallyValue: boolean,
3339
tallyColor: string
3440
): React.CSSProperties => {
@@ -42,6 +48,9 @@ const labelStyling = (
4248
height: element.height || 50,
4349
color: element.color || "white",
4450
backgroundColor: backgroundColor,
51+
fontFamily: globalSettings.fontFamily,
52+
border: "solid " + globalSettings.borderWidth + " " + (tally ? tallyColor : "grey"),
53+
borderRadius: globalSettings.borderRadius,
4554
};
4655
};
4756

@@ -50,6 +59,7 @@ export const SourceOverlay = (props: ISourceOverlayProps) => {
5059
<div
5160
style={windowStyling(
5261
props.source,
62+
props.globalSettings,
5363
props.labelAndTallyState?.tally[0],
5464
props.source.tallyColors[0]
5565
)}
@@ -60,6 +70,7 @@ export const SourceOverlay = (props: ISourceOverlayProps) => {
6070
key={index}
6171
style={labelStyling(
6272
element,
73+
props.globalSettings,
6374
props.labelAndTallyState.tally[element.tallyIndex],
6475
props.source.tallyColors[element.tallyIndex]
6576
)}

src/server/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ const server = require("http").Server(app);
44
const io = require("socket.io")(server);
55
const path = require("path");
66
import * as IO from "../sharedcode/IO_CONSTANTS";
7-
import { ILabelAndTallyState, ISource } from "../sharedcode/interfaces";
7+
import { ILabelAndTallyState, ISettings, ISource } from "../sharedcode/interfaces";
88
import {
99
getSettings,
1010
saveLabelTallyState,
1111
} from "./utils/storage";
1212
import { HandleEmberServer } from "./emberserver";
1313

14-
let sources: ISource[] = getSettings();
14+
let settings: ISettings = getSettings();
1515
let labelAndTallyState: ILabelAndTallyState[] = [];
1616

1717
const handleEmberServer = new HandleEmberServer();
@@ -25,7 +25,7 @@ app.get("/", (req: any, res: any) => {
2525
io.on("connection", (socket: any) => {
2626
console.log("User connected :", socket.id);
2727
const clientTimerState = setInterval(() => {
28-
sources = getSettings();
28+
settings = getSettings();
2929
let oldState = labelAndTallyState
3030
labelAndTallyState = handleEmberServer.getEmberState();
3131
if (JSON.stringify(oldState) !== JSON.stringify(labelAndTallyState)) {
@@ -35,15 +35,15 @@ io.on("connection", (socket: any) => {
3535
}
3636
}, 100);
3737
const clientTimerSettings = setInterval(
38-
() => socket.emit(IO.SEND_SETTINGS, sources),
38+
() => socket.emit(IO.SEND_SETTINGS, settings),
3939
2000
4040
);
4141

4242
socket
4343
.on(IO.GET_SETTINGS, () => {
4444
console.log("Client requested Source list");
4545
socket.emit(IO.SEND_STATE, labelAndTallyState);
46-
socket.emit(IO.SEND_SETTINGS, sources)
46+
socket.emit(IO.SEND_SETTINGS, settings)
4747
})
4848
.on("disconnect", () => {
4949
console.log("User disconnected");

0 commit comments

Comments
 (0)