Edit add feature refined

This commit is contained in:
adilallo
2026-04-29 18:38:40 -06:00
parent fc845d8308
commit c4c74ecdb4
6 changed files with 195 additions and 82 deletions
@@ -1,6 +1,6 @@
"use client";
import { useEffect, useMemo } from "react";
import { useMemo } from "react";
import { useCreateFlow } from "../context/CreateFlowContext";
import type { CreateFlowMethodCardFacetSection } from "../types";
import {
@@ -18,14 +18,17 @@ type MethodEntry = { id: string; label: string; supportText: string };
/**
* Applies score ranking, compact-slot rules, optional “pinned selection” showcase
* order, and clears the pin draft flag when a section loses all selections.
* order. Rows stay pinned across navigation while `methodSectionsPinCommitted` is true
* and the section still has selections; we do **not** clear the flag when selection
* arrays briefly go empty during draft hydration (`replaceState` / merge flashes) —
* display order already ignores the pin until `pinActive` is true again.
*/
export function useMethodCardDeckOrdering(
section: RecommendationSection,
methods: readonly MethodEntry[],
selectedIds: readonly string[],
) {
const { state, setMethodSectionsPinCommitted } = useCreateFlow();
const { state } = useCreateFlow();
const facetKey = section as CreateFlowMethodCardFacetSection;
const { scoresBySlug, hasAnyFacets } = useFacetRecommendations(section);
@@ -33,17 +36,6 @@ export function useMethodCardDeckOrdering(
state.methodSectionsPinCommitted?.[facetKey] === true;
const pinActive = Boolean(pinStored && selectedIds.length > 0);
useEffect(() => {
if (selectedIds.length > 0) return;
if (!pinStored) return;
setMethodSectionsPinCommitted(facetKey, false);
}, [
facetKey,
pinStored,
selectedIds.length,
setMethodSectionsPinCommitted,
]);
const rankedMethods = useMemo(
() => rankMethodsByScore(methods, scoresBySlug),
[methods, scoresBySlug],