@metron-labs/quote-react 0.1.20 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useState } from "react";
3
+ import { useEffect, useRef, useState } from "react";
4
4
  import { assetUrl } from "../lib/assets";
5
5
  import { getQuoteConfig } from "../lib/config";
6
6
  import { ESTIMATOR_TOOLS } from "../components/estimators/registry";
@@ -21,6 +21,15 @@ function EstimatingToolsInner({ fullPage = false, hideHeader = false, internal =
21
21
  const activeEstimator = ESTIMATOR_TOOLS.find((tool) => tool.id === activeEstimatorId);
22
22
  const { cart, updateCartQty, updateCartSellUnits, updateCartConversions, removeFromCart, clearCart } = useCart();
23
23
  const { adding, basketError, addToBasket } = useFixedBasket(activeEstimator?.title ?? "calculator");
24
+ // Every screen change, forward or back, lands at the top.
25
+ const view = showBasket ? "basket" : adding ? "adding" : review ? "review" : activeEstimatorId ?? "list";
26
+ const scrolledView = useRef(view);
27
+ useEffect(() => {
28
+ if (scrolledView.current === view)
29
+ return;
30
+ scrolledView.current = view;
31
+ window.scrollTo(0, 0);
32
+ }, [view]);
24
33
  const reviewOrBasket = (requirements) => {
25
34
  if (!activeEstimator)
26
35
  return;
@@ -99,7 +99,6 @@ function QuickQuoteInner({ fullPage = false, hideHeader = false, internal = fals
99
99
  const goToBasket = useCallback(() => {
100
100
  writeQuoteHistory("basket");
101
101
  setStage("basket");
102
- window.scrollTo(0, 0);
103
102
  }, [writeQuoteHistory]);
104
103
  const backToResults = useCallback(() => {
105
104
  const quoteStage = window.history.state?.boqQuoteStage;
@@ -108,6 +107,15 @@ function QuickQuoteInner({ fullPage = false, hideHeader = false, internal = fals
108
107
  else
109
108
  setStage(scheduleResult ? "results" : "entry");
110
109
  }, [scheduleResult]);
110
+ // Every screen change, forward or back, lands at the top. Runs after the new screen has
111
+ // rendered, so it also wins over the browser restoring the old scroll on history.back().
112
+ const scrolledStage = useRef(stage);
113
+ useEffect(() => {
114
+ if (scrolledStage.current === stage)
115
+ return;
116
+ scrolledStage.current = stage;
117
+ window.scrollTo(0, 0);
118
+ }, [stage]);
111
119
  // Reset back to the method-selection screen. The uploaded catalogue stays in
112
120
  // place — it's a session-level prerequisite, not part of an individual quote.
113
121
  const resetToEntry = () => {