MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / columnViewReducer

Function columnViewReducer

app/useColumnView/index.ts:345–453  ·  view source on GitHub ↗
(
  state: ColumnViewState,
  action: ColumnViewAction
)

Source from the content-addressed store, hash-verified

343 9. Move forward to the next state
344*/
345function columnViewReducer(
346 state: ColumnViewState,
347 action: ColumnViewAction
348): ColumnViewState {
349 switch (action.type) {
350 case "SET_SELECTED_NODE_ID":
351 return {
352 ...state,
353 selectedNodeId: action.id,
354 highlightedNodeId: action.id,
355 selectedNodeSource: action.source,
356 };
357 case "MOVE_DOWN": {
358 if (state.highlightedNodeId === state.rootNodeId) {
359 return moveToChildren(state);
360 }
361
362 const id = getHighlightedSibling(state, state.nodeTable, 1);
363
364 if (!id) {
365 return state;
366 }
367
368 return {
369 ...state,
370 selectedNodeId: id,
371 highlightedNodeId: id,
372 };
373 }
374 case "MOVE_UP": {
375 const id = getHighlightedSibling(state, state.nodeTable, -1);
376
377 if (!id) {
378 return state;
379 }
380
381 return {
382 ...state,
383 selectedNodeId: id,
384 highlightedNodeId: id,
385 };
386 }
387 case "MOVE_TO_CHILDREN": {
388 return moveToChildren(state);
389 }
390 case "MOVE_TO_PARENT": {
391 const { highlightedNodeId } = state;
392
393 if (!highlightedNodeId) {
394 return state;
395 }
396
397 const highlightedNode = state.nodeTable[highlightedNodeId];
398
399 if (!highlightedNode || !highlightedNode.parentId) {
400 return state;
401 }
402

Callers 1

useColumnViewFunction · 0.85

Calls 2

moveToChildrenFunction · 0.85
getHighlightedSiblingFunction · 0.85

Tested by

no test coverage detected