Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/contexts/socket.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
deleteTestRun,
} from "./testRun.context";
import { API_URL } from "../_config/env.config";
import { useProjectState } from "./project.context";

interface IConnectAction {
type: "connect";
Expand Down Expand Up @@ -53,6 +54,7 @@ function socketReducer(state: State, action: IAction): State {
function SocketProvider({ children }: SocketProviderProps) {
const [state, dispatch] = React.useReducer(socketReducer, initialState);
const { selectedBuild } = useBuildState();
const { selectedProjectId } = useProjectState();
const testRunDispatch = useTestRunDispatch();
const buildDispatch = useBuildDispatch();

Expand All @@ -65,11 +67,16 @@ function SocketProvider({ children }: SocketProviderProps) {
state.socket.removeAllListeners();

state.socket.on("build_created", function (build: Build) {
addBuild(buildDispatch, build);
if (build.projectId === selectedProjectId) {
addBuild(buildDispatch, build);
}
});

state.socket.on("build_updated", function (builds: Array<Build>) {
updateBuild(buildDispatch, builds);
updateBuild(
buildDispatch,
builds.filter((build) => build.projectId === selectedProjectId)
);
});

state.socket.on("testRun_created", function (testRuns: Array<TestRun>) {
Expand Down Expand Up @@ -104,7 +111,13 @@ function SocketProvider({ children }: SocketProviderProps) {
);
});
}
}, [state.socket, selectedBuild, buildDispatch, testRunDispatch]);
}, [
state.socket,
selectedBuild,
selectedProjectId,
buildDispatch,
testRunDispatch,
]);

return (
<SocketStateContext.Provider value={state}>
Expand Down
1 change: 1 addition & 0 deletions src/types/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Build {
id: string;
ciBuildId: string;
number: number;
projectId: string;
projectName: string;
branchName: string;
status: BuildStatus;
Expand Down