From 746d3d4b108e97b52c1a76085bce8da1066f087b Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 9 Mar 2024 03:15:22 +0700 Subject: [PATCH] save logic --- src/widgets/chain-editor/ui/ChainEditor.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/widgets/chain-editor/ui/ChainEditor.tsx b/src/widgets/chain-editor/ui/ChainEditor.tsx index e6cda1a..0c84d8b 100644 --- a/src/widgets/chain-editor/ui/ChainEditor.tsx +++ b/src/widgets/chain-editor/ui/ChainEditor.tsx @@ -1,4 +1,8 @@ import type { Chain } from "@/entities/chain/schema"; +import { useChainState } from "@/entities/chain/model"; +import { useNavigate } from "@tanstack/react-router"; + +import { upsertChain } from "@/entities/chain/api/upsert"; import { ActionEditor } from "@/widgets/action-editor"; import { RenameChainButton } from "@/features/rename-chain"; @@ -6,12 +10,14 @@ import { DeleteChainButton } from "@/features/delete-chain"; import { Typography } from "@mui/material"; import Breadcrumbs from "@mui/material/Breadcrumbs"; - interface ChainEditorProps { chain: Chain; } export default function ChainEditor({ chain }: ChainEditorProps) { + const navigate = useNavigate({ from: "/$namespace/$chainId" }); + const addCommentAction = useChainState((state) => state.addCommentAction); + if (!chain.actions || chain.actions.length === 0) return (
@@ -40,7 +46,13 @@ export default function ChainEditor({ chain }: ChainEditorProps) {
- + { + addCommentAction(chain._id!, action); + await upsertChain(chain); + navigate({ to: "/$namespace/$chainId" }); + }} + />
);