From 90c68ef8deadbfe28890f7ab8900ef651444bf68 Mon Sep 17 00:00:00 2001 From: Madhura68 Date: Sun, 10 May 2026 07:18:36 +0200 Subject: [PATCH] refactor: use sprint store active story --- components/sprint/sprint-board-client.tsx | 9 +++++---- components/sprint/task-list.tsx | 10 ++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/components/sprint/sprint-board-client.tsx b/components/sprint/sprint-board-client.tsx index bc40509..2d0e47a 100644 --- a/components/sprint/sprint-board-client.tsx +++ b/components/sprint/sprint-board-client.tsx @@ -62,8 +62,8 @@ export function SprintBoardClient({ const sprintStories = useSprintWorkspaceStore( useShallow((s) => selectStoriesForActiveSprint(s) as SprintStory[]), ) + const selectedStoryId = useSprintWorkspaceStore((s) => s.context.activeStoryId) const sprintStoryIds = new Set(sprintStories.map(s => s.id)) - const [selectedStoryId, setSelectedStoryId] = useState(null) const [activeDragStory, setActiveDragStory] = useState(null) const [, startTransition] = useTransition() @@ -157,7 +157,9 @@ export function SprintBoardClient({ if (story) story.sprint_id = null }) - if (selectedStoryId === storyId) setSelectedStoryId(null) + if (selectedStoryId === storyId) { + useSprintWorkspaceStore.getState().setActiveStory(null) + } startTransition(async () => { const result = await removeStoryFromSprintAction(storyId) @@ -240,7 +242,7 @@ export function SprintBoardClient({ sprintId={sprintId} isDemo={isDemo} onRemove={handleRemove} - onSelect={setSelectedStoryId} + onSelect={(storyId) => useSprintWorkspaceStore.getState().setActiveStory(storyId)} selectedStoryId={selectedStoryId} currentUserId={currentUserId} productId={productId} @@ -250,7 +252,6 @@ export function SprintBoardClient({ selectedStoryId ? ( s.context.activeStoryId) const orderedTasks = useSprintWorkspaceStore( - useShallow((s) => selectTasksForStory(s, storyId)), + useShallow(selectTasksForActiveStory), ) const [activeDragId, setActiveDragId] = useState(null) const [, startTransition] = useTransition() @@ -179,6 +179,7 @@ export function TaskList({ storyId, sprintId: _sprintId, productId: _productId, function handleDragEnd(event: DragEndEvent) { const { active, over } = event + if (!storyId) return if (!over || active.id === over.id) return const store = useSprintWorkspaceStore.getState() const prevOrder = [...(store.relations.taskIdsByStory[storyId] ?? [])] @@ -217,6 +218,7 @@ export function TaskList({ storyId, sprintId: _sprintId, productId: _productId, } function openCreateDialog() { + if (!storyId) return router.push(`${pathname}?newTask=1&storyId=${storyId}`) }