feat: pass library-page action props through StepLibraryBrowser + refreshKey

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-02-24 20:41:55 -05:00
parent 0fbe50c38b
commit f1c5898b9f

View File

@@ -8,12 +8,17 @@ import { StepDetailModal } from './StepDetailModal'
import type { Step, StepListItem, StepCategory, PopularTag, StepListParams } from '@/types/step' import type { Step, StepListItem, StepCategory, PopularTag, StepListParams } from '@/types/step'
interface StepLibraryBrowserProps { interface StepLibraryBrowserProps {
onInsert: (step: Step) => void onInsert?: (step: Step) => void
onCreateNew?: () => void onCreateNew?: () => void
showCreateButton?: boolean showCreateButton?: boolean
onEdit?: (step: StepListItem) => void
onDelete?: (step: StepListItem) => void
onSave?: (step: StepListItem) => void
currentUserId?: string
refreshKey?: number
} }
export function StepLibraryBrowser({ onInsert, onCreateNew, showCreateButton = false }: StepLibraryBrowserProps) { export function StepLibraryBrowser({ onInsert, onCreateNew, showCreateButton = false, onEdit, onDelete, onSave, currentUserId, refreshKey }: StepLibraryBrowserProps) {
// State // State
const [steps, setSteps] = useState<StepListItem[]>([]) const [steps, setSteps] = useState<StepListItem[]>([])
const [categories, setCategories] = useState<StepCategory[]>([]) const [categories, setCategories] = useState<StepCategory[]>([])
@@ -87,7 +92,7 @@ export function StepLibraryBrowser({ onInsert, onCreateNew, showCreateButton = f
} }
loadSteps() loadSteps()
}, [searchQuery, selectedCategoryId, selectedStepType, minRating, sortBy, selectedTag]) }, [searchQuery, selectedCategoryId, selectedStepType, minRating, sortBy, selectedTag, refreshKey])
// Group steps by visibility // Group steps by visibility
const groupedSteps = useMemo(() => { const groupedSteps = useMemo(() => {
@@ -108,12 +113,15 @@ export function StepLibraryBrowser({ onInsert, onCreateNew, showCreateButton = f
const handleInsertFromPreview = (step: Step) => { const handleInsertFromPreview = (step: Step) => {
setPreviewStepId(null) setPreviewStepId(null)
onInsert(step) if (onInsert) {
onInsert(step)
}
} }
const handleInsertFromCard = (stepItem: StepListItem) => { const handleInsertFromCard = (stepItem: StepListItem) => {
// Need to fetch full step details for insert if (onInsert) {
stepsApi.get(stepItem.id).then(onInsert) stepsApi.get(stepItem.id).then(onInsert)
}
} }
const handleTagClick = (tag: string) => { const handleTagClick = (tag: string) => {
@@ -275,7 +283,11 @@ export function StepLibraryBrowser({ onInsert, onCreateNew, showCreateButton = f
key={step.id} key={step.id}
step={step} step={step}
onPreview={handlePreview} onPreview={handlePreview}
onInsert={handleInsertFromCard} onInsert={onInsert ? handleInsertFromCard : undefined}
onEdit={onEdit}
onDelete={onDelete}
onSave={onSave}
currentUserId={currentUserId}
/> />
))} ))}
</div> </div>
@@ -304,7 +316,11 @@ export function StepLibraryBrowser({ onInsert, onCreateNew, showCreateButton = f
key={step.id} key={step.id}
step={step} step={step}
onPreview={handlePreview} onPreview={handlePreview}
onInsert={handleInsertFromCard} onInsert={onInsert ? handleInsertFromCard : undefined}
onEdit={onEdit}
onDelete={onDelete}
onSave={onSave}
currentUserId={currentUserId}
/> />
))} ))}
</div> </div>
@@ -333,7 +349,11 @@ export function StepLibraryBrowser({ onInsert, onCreateNew, showCreateButton = f
key={step.id} key={step.id}
step={step} step={step}
onPreview={handlePreview} onPreview={handlePreview}
onInsert={handleInsertFromCard} onInsert={onInsert ? handleInsertFromCard : undefined}
onEdit={onEdit}
onDelete={onDelete}
onSave={onSave}
currentUserId={currentUserId}
/> />
))} ))}
</div> </div>