- Clear stage (progress update), moving branches to verify some outputs.
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import update from "immutability-helper";
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
|
||||
const updateLanes = (state, lanes) => update(state, { lanes: { $set: lanes } });
|
||||
|
||||
const updateLaneCards = (lane, cards) => update(lane, { cards: { $set: cards } });
|
||||
|
||||
const LaneHelper = {
|
||||
@@ -53,42 +53,78 @@ const LaneHelper = {
|
||||
return updateLanes(state, newLanes);
|
||||
},
|
||||
|
||||
// TODO: Unverified, needs to be hoisted.
|
||||
removeCardFromLane: (state, { laneId, cardId }) => {
|
||||
const lanes = state.lanes.map((lane) => {
|
||||
if (lane.id === laneId) {
|
||||
const newCards = lane.cards.filter((card) => card.id !== cardId);
|
||||
return updateLaneCards(lane, newCards);
|
||||
} else {
|
||||
return lane;
|
||||
}
|
||||
// Clone the state to avoid mutation
|
||||
const newLanes = cloneDeep(state.lanes);
|
||||
|
||||
// Find the lane from which the card will be removed
|
||||
const lane = newLanes.find((lane) => lane.id === laneId);
|
||||
|
||||
// Find the card in the lane
|
||||
const cardIndex = lane.cards.findIndex((card) => card.id === cardId);
|
||||
if (cardIndex === -1) {
|
||||
throw new Error("Card not found in the lane");
|
||||
}
|
||||
|
||||
// Remove the card from the lane
|
||||
lane.cards.splice(cardIndex, 1);
|
||||
|
||||
let idx = 0;
|
||||
|
||||
// Update the lane and card indexes for all lanes
|
||||
newLanes.forEach((lane, laneIndex) => {
|
||||
lane.cards.forEach((card, cardIndex) => {
|
||||
card.idx = idx;
|
||||
card.laneIndex = laneIndex;
|
||||
card.cardIndex = cardIndex;
|
||||
card.laneId = lane.id;
|
||||
idx++;
|
||||
});
|
||||
});
|
||||
|
||||
return update(state, {
|
||||
lanes: { $set: newLanes }
|
||||
});
|
||||
return updateLanes(state, lanes);
|
||||
},
|
||||
|
||||
moveCardAcrossLanes: (state, ...params) => {
|
||||
console.log("state");
|
||||
console.dir(state);
|
||||
console.log("params");
|
||||
console.dir(params);
|
||||
// let cardToMove = null;
|
||||
// const interimLanes = state.lanes.map((lane) => {
|
||||
// if (lane.id === fromLaneId) {
|
||||
// cardToMove = lane.cards.find((card) => card.id === cardId);
|
||||
// const newCards = lane.cards.filter((card) => card.id !== cardId);
|
||||
// return updateLaneCards(lane, newCards);
|
||||
// } else {
|
||||
// return lane;
|
||||
// }
|
||||
// });
|
||||
// return LaneHelper.appendCardToLane(
|
||||
// { ...state, lanes: interimLanes },
|
||||
// {
|
||||
// laneId: toLaneId,
|
||||
// card: cardToMove,
|
||||
// index: index
|
||||
// }
|
||||
// );
|
||||
return state;
|
||||
// TODO: This has been updated to new DND Lib, verified.
|
||||
moveCardAcrossLanes: (state, { fromLaneId, toLaneId, cardId, index }) => {
|
||||
// Clone the state to avoid mutation
|
||||
const newLanes = cloneDeep(state.lanes);
|
||||
|
||||
// Find the source and destination lanes using the lane indices
|
||||
const fromLane = newLanes[fromLaneId];
|
||||
const toLane = newLanes[toLaneId];
|
||||
|
||||
// Find the card in the source lane
|
||||
const cardIndex = fromLane.cards.findIndex((card) => card.id === cardId);
|
||||
if (cardIndex === -1) {
|
||||
throw new Error("Card not found in the source lane");
|
||||
}
|
||||
|
||||
// Remove the card from the source lane
|
||||
const [card] = fromLane.cards.splice(cardIndex, 1);
|
||||
|
||||
// Insert the card into the destination lane at the specified index
|
||||
toLane.cards.splice(index, 0, card);
|
||||
|
||||
let idx = 0;
|
||||
|
||||
// Update the lane and card indexes for all lanes
|
||||
newLanes.forEach((lane, laneIndex) => {
|
||||
lane.cards.forEach((card, cardIndex) => {
|
||||
card.idx = idx;
|
||||
card.laneIndex = laneIndex;
|
||||
card.cardIndex = cardIndex;
|
||||
card.laneId = lane.id;
|
||||
idx++;
|
||||
});
|
||||
});
|
||||
|
||||
return update(state, {
|
||||
lanes: { $set: newLanes }
|
||||
});
|
||||
},
|
||||
|
||||
updateCardsForLane: (state, { laneId, cards }) => {
|
||||
|
||||
Reference in New Issue
Block a user