refactor: use sprint store active story
This commit is contained in:
parent
38d99834ef
commit
90c68ef8de
2 changed files with 11 additions and 8 deletions
|
|
@ -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<string | null>(null)
|
||||
const [activeDragStory, setActiveDragStory] = useState<SprintStory | null>(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 ? (
|
||||
<TaskList
|
||||
key="tasks"
|
||||
storyId={selectedStoryId}
|
||||
sprintId={sprintId}
|
||||
productId={productId}
|
||||
isDemo={isDemo}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import { CodeBadge } from '@/components/shared/code-badge'
|
|||
import { PanelNavBar } from '@/components/shared/panel-nav-bar'
|
||||
import { PRIORITY_BORDER } from '@/components/backlog/backlog-card'
|
||||
import { useSprintWorkspaceStore } from '@/stores/sprint-workspace/store'
|
||||
import { selectTasksForStory } from '@/stores/sprint-workspace/selectors'
|
||||
import { selectTasksForActiveStory } from '@/stores/sprint-workspace/selectors'
|
||||
import type {
|
||||
SprintWorkspaceTask,
|
||||
SprintWorkspaceTaskDetail,
|
||||
|
|
@ -70,7 +70,6 @@ export interface Task {
|
|||
type WorkspaceTask = SprintWorkspaceTask | SprintWorkspaceTaskDetail
|
||||
|
||||
interface TaskListProps {
|
||||
storyId: string
|
||||
sprintId: string
|
||||
productId: string
|
||||
isDemo: boolean
|
||||
|
|
@ -158,9 +157,10 @@ function SortableTaskRow({
|
|||
)
|
||||
}
|
||||
|
||||
export function TaskList({ storyId, sprintId: _sprintId, productId: _productId, isDemo }: TaskListProps) {
|
||||
export function TaskList({ sprintId: _sprintId, productId: _productId, isDemo }: TaskListProps) {
|
||||
const storyId = useSprintWorkspaceStore((s) => s.context.activeStoryId)
|
||||
const orderedTasks = useSprintWorkspaceStore(
|
||||
useShallow((s) => selectTasksForStory(s, storyId)),
|
||||
useShallow(selectTasksForActiveStory),
|
||||
)
|
||||
const [activeDragId, setActiveDragId] = useState<string | null>(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}`)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue