Scrum4Me/components/backlog/backlog-split-pane.tsx
Madhura68 3e86a8d5c9 feat(ST-1116): mobile auto-switch tabs + back button in BacklogSplitPane
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-30 17:53:38 +02:00

34 lines
1 KiB
TypeScript

'use client'
import { useState } from 'react'
import { useSelectionStore } from '@/stores/selection-store'
import { SplitPane, type SplitPaneProps } from '@/components/split-pane/split-pane'
type Props = Omit<SplitPaneProps, 'activeTab' | 'onActiveTabChange'>
export function BacklogSplitPane(props: Props) {
const { selectedPbiId, selectedStoryId } = useSelectionStore()
const [activeTab, setActiveTab] = useState(0)
// React-recommended "derived state from props" pattern: update state during render
// instead of useEffect to avoid cascading renders.
const [prevPbiId, setPrevPbiId] = useState(selectedPbiId)
const [prevStoryId, setPrevStoryId] = useState(selectedStoryId)
if (selectedStoryId !== prevStoryId) {
setPrevStoryId(selectedStoryId)
if (selectedStoryId) setActiveTab(2)
}
if (selectedPbiId !== prevPbiId) {
setPrevPbiId(selectedPbiId)
if (selectedPbiId && !selectedStoryId) setActiveTab(1)
}
return (
<SplitPane
{...props}
activeTab={activeTab}
onActiveTabChange={setActiveTab}
/>
)
}