Base générale d'UI

This commit is contained in:
2019-12-01 22:12:13 +01:00
parent c6851f3f42
commit 048ef49933
49 changed files with 1913 additions and 88 deletions

View File

@ -0,0 +1,41 @@
import { SAVE_BOARD_SUCCESS, FETCH_BOARDS_SUCCESS } from "../actions/boards";
export const defaultState = {
byID: {},
};
export function boardsReducer(state = defaultState, action) {
switch(action.type) {
case SAVE_BOARD_SUCCESS:
return handleSaveBoardSuccess(state, action);
case FETCH_BOARDS_SUCCESS:
return handleFetchBoardsSuccess(state, action);
default:
return state;
}
}
function handleSaveBoardSuccess(state, action) {
return {
...state,
byID: {
...state.byID,
[action.board.id.toString()]: {
...action.board,
}
}
};
}
function handleFetchBoardsSuccess(state, action) {
const boardsByID = action.boards.reduce((byID, board) => {
byID[board.id] = board;
return byID;
}, {});
return {
...state,
byID: {
...boardsByID,
}
};
}

View File

@ -0,0 +1,22 @@
const defaultState = {
actions: {}
};
export function flagsReducer(state = defaultState, action) {
const matches = (/^(.*)_((SUCCESS)|(FAILURE)|(REQUEST))$/).exec(action.type);
if(!matches) return state;
const actionPrefix = matches[1];
return {
...state,
actions: {
...state.actions,
[actionPrefix]: {
isLoading: matches[2] === 'REQUEST'
}
}
};
}

View File

@ -1,5 +1,27 @@
import { FETCH_ISSUES_SUCCESS } from "../actions/issues";
export function issuesReducer(state = {}, action) {
const defaultState = {
byProject: {}
};
return state;
export function issuesReducer(state = defaultState, action) {
switch(action.type) {
case FETCH_ISSUES_SUCCESS:
return handleFetchIssuesSuccess(state, action);
default:
return state;
}
}
function handleFetchIssuesSuccess(state, action) {
return {
...state,
byProject: {
...state.byProject,
[action.project]: [
...action.issues,
]
}
}
}

View File

@ -0,0 +1,74 @@
import { BUILD_KANBOARD_SUCCESS, MOVE_CARD } from "../actions/kanboards";
export const defaultState = {
byID: {},
};
export function kanboardsReducer(state = defaultState, action) {
switch(action.type) {
case BUILD_KANBOARD_SUCCESS:
return handleBuildKanboardSuccess(state, action);
case MOVE_CARD:
return handleMoveCard(state, action);
default:
return state;
}
}
function handleBuildKanboardSuccess(state, action) {
return {
...state,
byID: {
...state.byID,
[action.kanboard.id]: {
...action.kanboard,
}
}
};
}
function handleMoveCard(state, action) {
const {
boardID, fromLaneID,
fromPosition, toLaneID,
toPosition
} = action;
const kanboard = state.byID[boardID];
const lanes = [ ...kanboard.lanes ];
const fromLane = lanes[fromLaneID];
const toLane = lanes[toLaneID];
const card = fromLane.cards[fromPosition];
const fromCards = [ ...fromLane.cards ];
if (fromLaneID !== toLaneID) {
fromCards.splice(fromPosition, 1);
lanes[fromLaneID] = {
...fromLane,
cards: fromCards,
};
const toCards = [ ...toLane.cards ];
toCards.splice(toPosition, 0, card);
lanes[toLaneID] = {
...toLane,
cards: toCards,
};
} else {
fromCards.splice(fromPosition, 1);
fromCards.splice(toPosition, 0, card);
console.log(fromCards)
}
return {
...state,
byID: {
...state.byID,
[boardID]: {
...state.byID[boardID],
lanes,
},
}
};
}

View File

@ -0,0 +1,27 @@
import { FETCH_PROJECTS_SUCCESS } from "../actions/projects";
export const defaultState = {
byName: {},
};
export function projectsReducer(state = defaultState, action) {
switch(action.type) {
case FETCH_PROJECTS_SUCCESS:
return handleFetchProjectsSuccess(state, action);
default:
return state;
}
}
function handleFetchProjectsSuccess(state, action) {
const projectsByName = action.projects.reduce((byName, project) => {
byName[project.full_name] = project;
return byName;
}, {});
return {
...state,
byName: {
...projectsByName,
}
};
}

View File

@ -1,6 +1,14 @@
import { combineReducers } from 'redux';
import { issuesReducer } from './issues';
import { boardsReducer } from './boards';
import { flagsReducer } from './flags';
import { projectsReducer } from './projects';
import { kanboardsReducer } from './kanboards';
export const rootReducer = combineReducers({
issues: issuesReducer,
boards: boardsReducer,
kanboards: kanboardsReducer,
flags: flagsReducer,
projects: projectsReducer
});