cogsbox-state 0.5.370 → 0.5.372

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-state",
3
- "version": "0.5.370",
3
+ "version": "0.5.372",
4
4
  "description": "React state management library with form controls and server sync",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/CogsState.tsx CHANGED
@@ -1817,6 +1817,7 @@ function createProxyHandler<T>(
1817
1817
  | "LOCKED_AT_BOTTOM"
1818
1818
  | "IDLE_NOT_AT_BOTTOM";
1819
1819
 
1820
+ const shouldNotScroll = useRef(false);
1820
1821
  const containerRef = useRef<HTMLDivElement | null>(null);
1821
1822
  const [range, setRange] = useState({
1822
1823
  startIndex: 0,
@@ -1948,10 +1949,13 @@ function createProxyHandler<T>(
1948
1949
 
1949
1950
  if (lastItemHeight > 0) {
1950
1951
  clearInterval(intervalId);
1951
- console.log(
1952
- "ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
1953
- );
1954
- setStatus("SCROLLING_TO_BOTTOM");
1952
+ if (!shouldNotScroll.current) {
1953
+ console.log(
1954
+ "ACTION (GETTING_HEIGHTS): Measurement success -> SCROLLING_TO_BOTTOM"
1955
+ );
1956
+
1957
+ setStatus("SCROLLING_TO_BOTTOM");
1958
+ }
1955
1959
  }
1956
1960
  }, 100);
1957
1961
  } else if (status === "SCROLLING_TO_BOTTOM") {
@@ -1972,6 +1976,7 @@ function createProxyHandler<T>(
1972
1976
  console.log(
1973
1977
  "ACTION (SCROLLING_TO_BOTTOM): Scroll finished -> LOCKED_AT_BOTTOM"
1974
1978
  );
1979
+ shouldNotScroll.current = false;
1975
1980
  setStatus("LOCKED_AT_BOTTOM");
1976
1981
  },
1977
1982
  scrollBehavior === "smooth" ? 500 : 50
@@ -1995,19 +2000,23 @@ function createProxyHandler<T>(
1995
2000
 
1996
2001
  const handleUserScroll = () => {
1997
2002
  // This is the core logic you wanted.
1998
- if (status !== "IDLE_NOT_AT_BOTTOM") {
1999
- const isAtBottom =
2000
- container.scrollHeight -
2001
- container.scrollTop -
2002
- container.clientHeight <
2003
- 1;
2004
- if (!isAtBottom) {
2005
- console.log(
2006
- "USER ACTION: Scrolled up -> IDLE_NOT_AT_BOTTOM"
2007
- );
2008
- setStatus("IDLE_NOT_AT_BOTTOM");
2009
- }
2003
+
2004
+ const isAtBottom =
2005
+ container.scrollHeight -
2006
+ container.scrollTop -
2007
+ container.clientHeight <
2008
+ 1;
2009
+
2010
+ if (!isAtBottom) {
2011
+ console.log(
2012
+ "USER ACTION: Scrolled up -> IDLE_NOT_AT_BOTTOM"
2013
+ );
2014
+
2015
+ setStatus("IDLE_NOT_AT_BOTTOM");
2016
+ } else {
2017
+ shouldNotScroll.current = false;
2010
2018
  }
2019
+
2011
2020
  // We always update the range, regardless of state.
2012
2021
  // This is the full, non-placeholder function.
2013
2022
  const { scrollTop, clientHeight } = container;