This repository was archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathboardManagerReducer.ts
88 lines (85 loc) · 2.86 KB
/
boardManagerReducer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { versionCompare } from "../../../common/sharedUtilities/utils";
import * as actions from "../actions";
import * as util from "../utils/util";
const initalState = {
platforms: [],
categories: ["All", "Updatable"],
requesting: false,
errorMessage: "",
installingBoardName: "",
installErrorMessage: "",
uninstallingBoardName: "",
uninstallErrorMessage: "",
};
export default function boardManagerReducer(state = initalState, action) {
switch (action.type) {
case actions.BOARD_PACKAGES_REQUEST:
return {
...state,
errorMessage: "",
requesting: true,
categories: ["All", "Updatable", "Installed"],
};
case actions.BOARD_PACKAGES_SUCCESS: {
const categories = util.parseGroups(action.platforms, "category");
// Sorting versions in descending order.
action.platforms.forEach((element) => {
element.versions = element.versions.sort(versionCompare).reverse();
});
return {
...state,
errorMessage: "",
requesting: false,
platforms: action.platforms,
categories: ["All", "Updatable", "Installed"].concat(categories.sort()),
};
}
case actions.BOARD_PACKAGES_FAILURE:
return {
...state,
errorMessage: action.errorMessage,
requesting: false,
platforms: [],
};
case actions.INSTALL_BOARD_REQUEST:
return {
...state,
installingBoardName: action.boardName,
installErrorMessage: "",
};
case actions.INSTALL_BOARD_SUCCESS:
return {
...state,
installingBoardName: "",
installErrorMessage: "",
};
case actions.INSTALL_BOARD_FAILURE:
return {
...state,
installingBoardName: "",
installErrorMessage: action.errorMessage,
};
case actions.UNINSTALL_BOARD_REQUEST:
return {
...state,
uninstallingBoardName: action.boardName,
uninstallErrorMessage: "",
};
case actions.UNINSTALL_BOARD_SUCCESS:
return {
...state,
uninstallingBoardName: "",
uninstallErrorMessage: "",
};
case actions.UNINSTALL_BOARD_FAILURE:
return {
...state,
uninstallingBoardName: "",
uninstallErrorMessage: action.errorMessage,
};
default:
return state;
}
}