update action logic
This commit is contained in:
parent
a51c43c500
commit
1e2c7c2965
|
|
@ -12,6 +12,7 @@ interface ChainState {
|
|||
updateChain: (chain: Chain) => void;
|
||||
deleteChain: (id: string) => void;
|
||||
addCommentAction: (chainId: string, action: Action) => void;
|
||||
updateAction: (chainId: string, actionIndex: number, action: Action) => void;
|
||||
}
|
||||
|
||||
export const useChainState = create<ChainState>((set, get) => ({
|
||||
|
|
@ -88,4 +89,22 @@ export const useChainState = create<ChainState>((set, get) => ({
|
|||
chains[chainIndex].actions = actions;
|
||||
return state;
|
||||
}),
|
||||
|
||||
updateAction: (chainId, actionIndex, action) =>
|
||||
set((state) => {
|
||||
const chains = state.chains;
|
||||
if (!chains) return state;
|
||||
|
||||
const chain = state.getChain(chainId);
|
||||
|
||||
if (
|
||||
!chain ||
|
||||
typeof chain.actions === "undefined" ||
|
||||
!chain.actions[actionIndex]
|
||||
)
|
||||
return state;
|
||||
|
||||
chain.actions[actionIndex] = action;
|
||||
return state;
|
||||
}),
|
||||
}));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user