Skip to content

Commit

Permalink
Fix: keep scroll on load more in React view
Browse files Browse the repository at this point in the history
  • Loading branch information
thomlamb committed Aug 7, 2024
1 parent d983b9f commit a61e89c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
1.2.65 (unreleased)
-------------------

- Fix: keep scroll on load more in React view
[thomlamb]

- WEB-4132 : In anonymous mode, use remoteUrl instead of internal link url in links sections
[boulch]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useRef } from "react";
import React, { useEffect, useState, useContext, useRef } from "react";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { ScrollContext } from "../../hooks/ScrollContext";
import Filters from "./Filters/Filter";
Expand Down Expand Up @@ -41,6 +41,7 @@ function AnnuaireView(props) {
{ b_start: 0, fullobjects: 1 },
queryString.parse(useFilterQuery().toString())
);
const { scrollPos, updateScrollPos } = useContext(ScrollContext);
const [contactArray, setcontactArray] = useState([]);
const [contactNumber, setcontactNumber] = useState([]);
const [clickId, setClickId] = useState(null);
Expand Down Expand Up @@ -95,6 +96,7 @@ function AnnuaireView(props) {

// set batch
const loadMore = () => {
updateScrollPos(window.scrollY);
setBatchStart((batchStart) => batchStart + parseInt(props.batchSize));
setLoadMoreLaunch(true);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Link } from "react-router-dom";
import removeAccents from "remove-accents";
import { ScrollContext } from "../../../hooks/ScrollContext";
const ContactList = ({ contactArray, onChange, onHover, parentCallback }) => {

const { scrollPos, updateScrollPos } = useContext(ScrollContext);

function handleClick(event) {
Expand All @@ -17,11 +16,8 @@ const ContactList = ({ contactArray, onChange, onHover, parentCallback }) => {
}

useEffect(() => {
window.scrollTo(
{ top: scrollPos,
left: 0,
behavior: 'instant'});
}, [contactArray]);
window.scrollTo({ top: scrollPos, left: 0, behavior: "instant" });
}, [contactArray]);
return (
<React.Fragment>
<ul className="r-result-list annuaire-result-list">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useRef } from "react";
import React, { useEffect, useState, useContext, useRef } from "react";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { ScrollContext } from "../../hooks/ScrollContext";
import Filters from "./Filters/Filter";
Expand Down Expand Up @@ -51,6 +51,7 @@ function EventsView(props) {
},
queryString.parse(useFilterQuery().toString())
);
const { scrollPos, updateScrollPos } = useContext(ScrollContext);
const [itemsArray, setItemsArray] = useState([]);
const [itemsNumber, setItemsNumber] = useState([]);
const [clickId, setClickId] = useState(null);
Expand Down Expand Up @@ -106,6 +107,7 @@ function EventsView(props) {

// set batch
const loadMore = () => {
updateScrollPos(window.scrollY);
setBatchStart((batchStart) => batchStart + parseInt(props.batchSize));
setLoadMoreLaunch(true);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, createContext } from "react";
import React, { useEffect, useState, useContext, createContext } from "react";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { ScrollContext } from "../../hooks/ScrollContext";
import Filters from "./Filters/Filter";
Expand Down Expand Up @@ -43,6 +43,7 @@ const NewsView = (props) => {
{ b_start: 0, fullobjects: 1 },
queryString.parse(useFilterQuery().toString())
);
const { scrollPos, updateScrollPos } = useContext(ScrollContext);
const [itemsArray, setItemsArray] = useState([]);
const [itemsNumber, setItemsNumber] = useState([]);
const [clickId, setClickId] = useState(null);
Expand Down Expand Up @@ -89,6 +90,7 @@ const NewsView = (props) => {

// set batch
const loadMore = () => {
updateScrollPos(window.scrollY);
setBatchStart((batchStart) => batchStart + parseInt(props.batchSize));
setLoadMoreLaunch(true);
};
Expand Down

0 comments on commit a61e89c

Please sign in to comment.