-const projectsReducer = (state: ProjectState = { items: [], currentItemId: "" }, action: ProjectAction) => {
- return actions.match(action, {
- CREATE_PROJECT: project => ({
- ...state,
- items: state.items.concat({
- id: project.uuid,
- open: false,
- active: false,
- status: TreeItemStatus.Loaded,
- toggled: false,
- items: [],
- data: project
- })
- }),
+const updateCreator = (state: ProjectState, creator: Partial<ProjectCreator>) => ({
+ ...state,
+ creator: {
+ ...state.creator,
+ ...creator
+ }
+});
+
+const initialState: ProjectState = {
+ items: [],
+ currentItemId: "",
+ creator: {
+ opened: false,
+ pending: false,
+ ownerUuid: ""
+ }
+};
+
+
+export const projectsReducer = (state: ProjectState = initialState, action: ProjectAction) => {
+ return projectActions.match(action, {
+ OPEN_PROJECT_CREATOR: ({ ownerUuid }) => updateCreator(state, { ownerUuid, opened: true, pending: false }),
+ CLOSE_PROJECT_CREATOR: () => updateCreator(state, { opened: false }),
+ CREATE_PROJECT: () => updateCreator(state, { error: undefined }),
+ CREATE_PROJECT_SUCCESS: () => updateCreator(state, { opened: false, ownerUuid: "" }),