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
13 changes: 13 additions & 0 deletions src/components/BuildList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,21 @@ const BuildList: FunctionComponent = () => {
}?`}</Typography>
}
onSubmit={() => {
let indexOfBuildDeleted = buildList.findIndex((e) => e.id === menuBuild.id);
let indexOfSelectedBuild = buildList.findIndex((e) => e.id === selectedBuild?.id);
deleteBuild(buildDispatch, menuBuild.id)
.then((b) => {
if (indexOfBuildDeleted === indexOfSelectedBuild) {
if (buildList.length > 1) {
if (indexOfBuildDeleted === 0) {
selectBuild(buildDispatch, buildList[1].id);
} else {
selectBuild(buildDispatch, buildList[indexOfBuildDeleted - 1].id);
}
} else {
selectBuild(buildDispatch, null);
}
}
toggleDeleteDialogOpen();
enqueueSnackbar(
`Build #${menuBuild.number || menuBuild.id} deleted`,
Expand Down
31 changes: 21 additions & 10 deletions src/contexts/build.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IGetAction {

interface ISelectAction {
type: "select";
payload: Build;
payload: Build | null;
}

interface IDeleteAction {
Expand Down Expand Up @@ -71,11 +71,18 @@ const initialState: State = {
function buildReducer(state: State, action: IAction): State {
switch (action.type) {
case "select":
return {
...state,
selectedBuildId: action.payload.id,
selectedBuild: action.payload,
};
if (action.payload === null) {
return {
...state,
selectedBuild: null
};
} else {
return {
...state,
selectedBuildId: action.payload.id,
selectedBuild: action.payload,
};
}
case "request":
return {
...state,
Expand Down Expand Up @@ -173,10 +180,14 @@ async function stopBuild(dispatch: Dispatch, id: string) {
});
}

async function selectBuild(dispatch: Dispatch, id: string) {
return buildsService.getDetails(id).then((build) => {
dispatch({ type: "select", payload: build });
});
async function selectBuild(dispatch: Dispatch, id: string | null) {
if (id === null) {
dispatch({ type: "select", payload: null });
} else {
return buildsService.getDetails(id).then((build) => {
dispatch({ type: "select", payload: build });
});
}
}

async function addBuild(dispatch: Dispatch, build: Build) {
Expand Down