Skip to content

Commit d0335d0

Browse files
authored
Merge pull request #22 from Visual-Regression-Tracker/61-build-status-update
build update event handle added
2 parents 14bd408 + 590d3f3 commit d0335d0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/contexts/build.context.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ interface IAddAction {
2727
payload: Build;
2828
}
2929

30+
interface IUpdateAction {
31+
type: "update";
32+
payload: Build;
33+
}
34+
3035
type IAction =
3136
| IRequestAction
3237
| IGetAction
3338
| IDeleteAction
3439
| IAddAction
40+
| IUpdateAction
3541
| ISelectAction;
3642

3743
type Dispatch = (action: IAction) => void;
@@ -82,6 +88,16 @@ function buildReducer(state: State, action: IAction): State {
8288
...state,
8389
buildList: [action.payload, ...state.buildList],
8490
};
91+
case "update":
92+
return {
93+
...state,
94+
buildList: state.buildList.map((p) => {
95+
if (p.id === action.payload.id) {
96+
return action.payload
97+
}
98+
return p;
99+
}),
100+
};
85101
default:
86102
return state;
87103
}
@@ -149,6 +165,10 @@ async function addBuild(dispatch: Dispatch, build: Build) {
149165
dispatch({ type: "add", payload: build });
150166
}
151167

168+
async function updateBuild(dispatch: Dispatch, build: Build) {
169+
dispatch({ type: "update", payload: build });
170+
}
171+
152172
export {
153173
BuildProvider,
154174
useBuildState,
@@ -157,4 +177,5 @@ export {
157177
deleteBuild,
158178
selectBuild,
159179
addBuild,
180+
updateBuild,
160181
};

src/contexts/socket.context.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from "react";
22
import socketIOClient from "socket.io-client";
3-
import { useBuildState, useBuildDispatch, addBuild } from "./build.context";
3+
import { useBuildState, useBuildDispatch, addBuild, updateBuild } from "./build.context";
44
import { Build, TestRun } from "../types";
55
import { useTestRunDispatch, addTestRun } from "./testRun.context";
66

@@ -57,6 +57,10 @@ function SocketProvider({ children }: SocketProviderProps) {
5757
addBuild(buildDispatch, build);
5858
});
5959

60+
state.socket.on("build_updated", function (build: Build) {
61+
updateBuild(buildDispatch, build);
62+
});
63+
6064
state.socket.on(`testRun_created`, function (testRun: TestRun) {
6165
if (testRun.buildId === selectedBuildId) {
6266
addTestRun(testRunDispatch, testRun);

0 commit comments

Comments
 (0)