Skip to content

Commit 9cbf257

Browse files
HouseHouse
authored andcommitted
Merge branch 'qat' into fix/DEV12045
2 parents 66d989b + e320c8d commit 9cbf257

File tree

7 files changed

+67
-99
lines changed

7 files changed

+67
-99
lines changed

package-lock.json

Lines changed: 37 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@
174174
"ws": "8.18.0",
175175
"**/path-to-regexp": "0.1.12",
176176
"path-to-regexp": "0.1.12",
177-
"cookie":"0.7.2",
178-
"**/cookie":"0.7.2",
179-
"store2":"2.14.4",
180-
"**/store2":"2.14.4",
181-
"nanoid":"3.3.8",
182-
"**/nanoid":"3.3.8"
177+
"cookie": "0.7.2",
178+
"**/cookie": "0.7.2",
179+
"store2": "2.14.4",
180+
"**/store2": "2.14.4",
181+
"nanoid": "3.3.8",
182+
"**/nanoid": "3.3.8"
183183
},
184184
"dependencies": {
185185
"@babel/eslint-parser": "^7.17.0",
@@ -233,6 +233,7 @@
233233
"react-custom-scrollbars": "^4.1.2",
234234
"react-dom": "^18.3.1",
235235
"react-flip-toolkit": "^7.0.17",
236+
"react-frame-component": "^5.2.7",
236237
"react-helmet": "^6.1.0",
237238
"react-hot-loader": "^4.8.2",
238239
"react-markdown": "^2.5.0",

src/_scss/pages/search/_collapsibleSidebar.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
@import './filters/otherFilters/defCheckboxV2';
1818
box-shadow: unset;
1919
border-radius: unset;
20+
position: absolute;
2021
margin-top: 0;
21-
position: relative;
22+
top: 0;
2223

2324
.sidebar-bottom-submit {
2425
position: static;
2526
width: 100%;
2627
}
2728

2829
&.sticky {
29-
margin-top: -32px !important;
3030
position: fixed;
31+
top: rem(92);
3132

3233
.sidebar-bottom-submit {
3334
position: absolute;

src/js/components/search/collapsibleSidebar/SidebarWrapper.jsx

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Created by Andrea Blackwell 11/05/2024
44
**/
55

6-
import React, { useEffect, useState, useCallback } from 'react';
6+
import React, { useEffect, useState } from 'react';
77
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
88
import { throttle } from "lodash";
99
import PropTypes from "prop-types";
@@ -29,10 +29,8 @@ const SidebarWrapper = React.memo(({
2929
const [sidebarContentHeight, setSidebarContentHeight] = useState();
3030
const [mainContentHeight, setMainContentHeight] = useState();
3131
const [isOpened, setIsOpened] = useState(sidebarOpen);
32-
const [isHeaderVisible, setIsHeaderVisible] = useState();
3332
const [sidebarIsSticky, setSidebarIsSticky] = useState();
3433
const [isFooterVisible, setIsFooterVisible] = useState();
35-
const [observerSupported, setObserverSupported] = useState(false);
3634

3735
const mainContentEl = document.querySelector("#main-content");
3836
const footerEl = document.querySelector("footer");
@@ -41,9 +39,6 @@ const SidebarWrapper = React.memo(({
4139
const topStickyBarHeight = 60;
4240
const minContentHeight = 124;
4341

44-
const observerOptions = {
45-
threshold: 0.1
46-
};
4742
const toggleOpened = (e) => {
4843
e.preventDefault();
4944
setIsOpened((prevState) => !prevState);
@@ -88,17 +83,17 @@ const SidebarWrapper = React.memo(({
8883
setSidebarContentHeight(sidebarContentArea);
8984
};
9085

91-
const updatePosition = () => {
86+
const updatePosition = (isHeaderSticky) => {
9287
const tmpFooterInView = checkInView(footerEl) + footerMargin;
9388

94-
if (!sidebarIsSticky && isHeaderVisible) {
89+
if (!isHeaderSticky) {
9590
resizeHeightByHeader();
9691
}
97-
else if (sidebarIsSticky) {
92+
else if (isHeaderSticky) {
9893
document.querySelector(".search-collapsible-sidebar-container").style.height = '100vh - 60';
9994
}
10095

101-
if (isFooterVisible || tmpFooterInView > 0) {
96+
if (tmpFooterInView > 0) {
10297
resizeHeightByFooter();
10398
}
10499
};
@@ -107,11 +102,14 @@ const SidebarWrapper = React.memo(({
107102
const tmpFooterInView = checkInView(footerEl) + footerMargin;
108103
setIsFooterVisible(tmpFooterInView > 0);
109104
const isStickyEl = document.querySelector(".usda-page-header--sticky");
110-
const tmpIsSticky = isStickyEl !== null;
111-
setSidebarIsSticky(tmpIsSticky);
105+
const isHeaderSticky = isStickyEl !== null;
106+
107+
if (!isHeaderSticky || sidebarIsSticky !== isHeaderSticky || window.scrollY < 170 || tmpFooterInView > 0) {
108+
updatePosition(isHeaderSticky);
109+
}
112110

113-
if (!tmpIsSticky || tmpFooterInView > 45) {
114-
updatePosition();
111+
if (sidebarIsSticky !== isHeaderSticky) {
112+
setSidebarIsSticky(isHeaderSticky);
115113
}
116114
}, 20);
117115

@@ -192,28 +190,8 @@ const SidebarWrapper = React.memo(({
192190
document.querySelector("#main-content .v2").style.minHeight = `${window.innerHeight}px`;
193191
}
194192

195-
updatePosition();
196-
197193
// eslint-disable-next-line react-hooks/exhaustive-deps
198-
}, [isFooterVisible, isHeaderVisible, sidebarIsSticky, mainContentHeight]);
199-
200-
const handleObserver = useCallback((entries) => {
201-
entries.forEach((entry) => {
202-
if (entry.target?.localName?.includes("footer")) {
203-
setIsFooterVisible(true);
204-
}
205-
206-
if (entry.target?.className?.includes("usda-page-header") && !entry.target?.className?.includes("usda-page-header--sticky")) {
207-
setIsHeaderVisible(true);
208-
setSidebarIsSticky(false);
209-
}
210-
211-
if (entry.target?.className?.includes("usda-page-header--sticky")) {
212-
setSidebarIsSticky(true);
213-
setIsHeaderVisible(false);
214-
}
215-
});
216-
});
194+
}, [mainContentHeight]);
217195

218196
useEffect(() => {
219197
// eslint-disable-next-line no-undef
@@ -240,35 +218,11 @@ const SidebarWrapper = React.memo(({
240218
// eslint-disable-next-line react-hooks/exhaustive-deps
241219
});
242220

243-
useEffect(() => {
244-
setObserverSupported('IntersectionObserver' in window);
245-
// eslint-disable-next-line react-hooks/exhaustive-deps
246-
}, []);
247-
248-
// eslint-disable-next-line consistent-return
249-
useEffect(() => {
250-
if (observerSupported) {
251-
const targets = [document.querySelector(".usda-page-header")];
252-
targets.push(document.querySelector(".usda-page-header"));
253-
254-
// eslint-disable-next-line no-undef
255-
const observer = new IntersectionObserver(handleObserver, observerOptions);
256-
targets.forEach((i) => {
257-
if (i.className) {
258-
observer.observe(i);
259-
}
260-
});
261-
262-
return () => observer.disconnect();
263-
}
264-
// eslint-disable-next-line react-hooks/exhaustive-deps
265-
}, [observerSupported]);
266-
267-
const calculateHeight = () => {
221+
const selectHeight = () => {
268222
const isStickyEl = document.querySelector(".usda-page-header--sticky");
269-
const tmpIsSticky = isStickyEl !== null;
223+
const isHeaderSticky = isStickyEl !== null;
270224

271-
if (tmpIsSticky && !isFooterVisible) {
225+
if (isHeaderSticky && !isFooterVisible) {
272226
return 'calc(100vh - 60px)';
273227
}
274228

@@ -280,7 +234,7 @@ const SidebarWrapper = React.memo(({
280234
className={`search-collapsible-sidebar-container search-sidebar ${sidebarIsSticky ? "sticky" : ""}`}
281235
style={isMobile ? {} : { display: "none" }}>
282236
<div
283-
style={{ height: calculateHeight(), overscrollBehavior: "none" }}
237+
style={{ height: selectHeight(), overscrollBehavior: "none" }}
284238
className={`search-sidebar collapsible-sidebar ${initialPageLoad ? "is-initial-loaded" : ""} ${isOpened ? 'opened' : ''}`}>
285239
<div
286240
className="collapsible-sidebar--toggle"

src/js/components/sharedComponents/checkbox/AccordionCheckbox.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const AccordionCheckbox = ({
4141
expandCheckboxCategoryAccordions(filterCategoryMapping, selectedFilters)
4242
);
4343

44-
const selectedItemHeight = document.querySelector('.selected-category-item').offsetHeight;
44+
const selectedItemHeight = document.querySelector('.selected-category-item')?.offsetHeight;
4545
// subtracting to account for input box/margin/title header
4646
const [innerDivHeight, setInnerDivHeight] = useState(selectedItemHeight - 66);
4747

src/js/components/sharedComponents/checkbox/ListCheckbox.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const ListCheckbox = ({
2323
const [searchString, setSearchString] = useState('');
2424
const [filterCategory, setFilterCategory] = useState(filterCategoryMapping);
2525
const [noResults, setNoResults] = useState(false);
26-
const selectedItemHeight = document.querySelector('.selected-category-item').offsetHeight;
26+
const selectedItemHeight = document.querySelector('.selected-category-item')?.offsetHeight;
2727
// subtracting to account for input box/margin/title header
2828
const [innerDivHeight, setInnerDivHeight] = useState(selectedItemHeight - 53 - 52);
2929

src/js/containers/search/filters/recipient/RecipientSearchContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const RecipientSearchContainer = ({ updateSelectedRecipients, selectedRecipients
2727
const [newSearch, setNewSearch] = useState(true);
2828
const [isLoading, setIsLoading] = useState(false);
2929
const [maxRecipients, setMaxRecipients] = useState(true);
30-
const selectedItemHeight = document.querySelector('.selected-category-item').offsetHeight;
30+
const selectedItemHeight = document.querySelector('.selected-category-item')?.offsetHeight;
3131
// subtracting to account for input box/margin/title header/clear all recipients
3232
const [innerDivHeight, setInnerDivHeight] = useState(selectedItemHeight - 53 - 32 - 34 - 20);
3333

0 commit comments

Comments
 (0)