Skip to content

Commit

Permalink
Merge branch 'qat' into fix/DEV12045
Browse files Browse the repository at this point in the history
  • Loading branch information
House authored and House committed Feb 11, 2025
2 parents 66d989b + e320c8d commit 9cbf257
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 99 deletions.
62 changes: 37 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@
"ws": "8.18.0",
"**/path-to-regexp": "0.1.12",
"path-to-regexp": "0.1.12",
"cookie":"0.7.2",
"**/cookie":"0.7.2",
"store2":"2.14.4",
"**/store2":"2.14.4",
"nanoid":"3.3.8",
"**/nanoid":"3.3.8"
"cookie": "0.7.2",
"**/cookie": "0.7.2",
"store2": "2.14.4",
"**/store2": "2.14.4",
"nanoid": "3.3.8",
"**/nanoid": "3.3.8"
},
"dependencies": {
"@babel/eslint-parser": "^7.17.0",
Expand Down Expand Up @@ -233,6 +233,7 @@
"react-custom-scrollbars": "^4.1.2",
"react-dom": "^18.3.1",
"react-flip-toolkit": "^7.0.17",
"react-frame-component": "^5.2.7",
"react-helmet": "^6.1.0",
"react-hot-loader": "^4.8.2",
"react-markdown": "^2.5.0",
Expand Down
5 changes: 3 additions & 2 deletions src/_scss/pages/search/_collapsibleSidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
@import './filters/otherFilters/defCheckboxV2';
box-shadow: unset;
border-radius: unset;
position: absolute;
margin-top: 0;
position: relative;
top: 0;

.sidebar-bottom-submit {
position: static;
width: 100%;
}

&.sticky {
margin-top: -32px !important;
position: fixed;
top: rem(92);

.sidebar-bottom-submit {
position: absolute;
Expand Down
80 changes: 17 additions & 63 deletions src/js/components/search/collapsibleSidebar/SidebarWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Created by Andrea Blackwell 11/05/2024
**/

import React, { useEffect, useState, useCallback } from 'react';
import React, { useEffect, useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { throttle } from "lodash";
import PropTypes from "prop-types";
Expand All @@ -29,10 +29,8 @@ const SidebarWrapper = React.memo(({
const [sidebarContentHeight, setSidebarContentHeight] = useState();
const [mainContentHeight, setMainContentHeight] = useState();
const [isOpened, setIsOpened] = useState(sidebarOpen);
const [isHeaderVisible, setIsHeaderVisible] = useState();
const [sidebarIsSticky, setSidebarIsSticky] = useState();
const [isFooterVisible, setIsFooterVisible] = useState();
const [observerSupported, setObserverSupported] = useState(false);

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

const observerOptions = {
threshold: 0.1
};
const toggleOpened = (e) => {
e.preventDefault();
setIsOpened((prevState) => !prevState);
Expand Down Expand Up @@ -88,17 +83,17 @@ const SidebarWrapper = React.memo(({
setSidebarContentHeight(sidebarContentArea);
};

const updatePosition = () => {
const updatePosition = (isHeaderSticky) => {
const tmpFooterInView = checkInView(footerEl) + footerMargin;

if (!sidebarIsSticky && isHeaderVisible) {
if (!isHeaderSticky) {
resizeHeightByHeader();
}
else if (sidebarIsSticky) {
else if (isHeaderSticky) {
document.querySelector(".search-collapsible-sidebar-container").style.height = '100vh - 60';
}

if (isFooterVisible || tmpFooterInView > 0) {
if (tmpFooterInView > 0) {
resizeHeightByFooter();
}
};
Expand All @@ -107,11 +102,14 @@ const SidebarWrapper = React.memo(({
const tmpFooterInView = checkInView(footerEl) + footerMargin;
setIsFooterVisible(tmpFooterInView > 0);
const isStickyEl = document.querySelector(".usda-page-header--sticky");
const tmpIsSticky = isStickyEl !== null;
setSidebarIsSticky(tmpIsSticky);
const isHeaderSticky = isStickyEl !== null;

if (!isHeaderSticky || sidebarIsSticky !== isHeaderSticky || window.scrollY < 170 || tmpFooterInView > 0) {
updatePosition(isHeaderSticky);
}

if (!tmpIsSticky || tmpFooterInView > 45) {
updatePosition();
if (sidebarIsSticky !== isHeaderSticky) {
setSidebarIsSticky(isHeaderSticky);
}
}, 20);

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

updatePosition();

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isFooterVisible, isHeaderVisible, sidebarIsSticky, mainContentHeight]);

const handleObserver = useCallback((entries) => {
entries.forEach((entry) => {
if (entry.target?.localName?.includes("footer")) {
setIsFooterVisible(true);
}

if (entry.target?.className?.includes("usda-page-header") && !entry.target?.className?.includes("usda-page-header--sticky")) {
setIsHeaderVisible(true);
setSidebarIsSticky(false);
}

if (entry.target?.className?.includes("usda-page-header--sticky")) {
setSidebarIsSticky(true);
setIsHeaderVisible(false);
}
});
});
}, [mainContentHeight]);

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

useEffect(() => {
setObserverSupported('IntersectionObserver' in window);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

// eslint-disable-next-line consistent-return
useEffect(() => {
if (observerSupported) {
const targets = [document.querySelector(".usda-page-header")];
targets.push(document.querySelector(".usda-page-header"));

// eslint-disable-next-line no-undef
const observer = new IntersectionObserver(handleObserver, observerOptions);
targets.forEach((i) => {
if (i.className) {
observer.observe(i);
}
});

return () => observer.disconnect();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [observerSupported]);

const calculateHeight = () => {
const selectHeight = () => {
const isStickyEl = document.querySelector(".usda-page-header--sticky");
const tmpIsSticky = isStickyEl !== null;
const isHeaderSticky = isStickyEl !== null;

if (tmpIsSticky && !isFooterVisible) {
if (isHeaderSticky && !isFooterVisible) {
return 'calc(100vh - 60px)';
}

Expand All @@ -280,7 +234,7 @@ const SidebarWrapper = React.memo(({
className={`search-collapsible-sidebar-container search-sidebar ${sidebarIsSticky ? "sticky" : ""}`}
style={isMobile ? {} : { display: "none" }}>
<div
style={{ height: calculateHeight(), overscrollBehavior: "none" }}
style={{ height: selectHeight(), overscrollBehavior: "none" }}
className={`search-sidebar collapsible-sidebar ${initialPageLoad ? "is-initial-loaded" : ""} ${isOpened ? 'opened' : ''}`}>
<div
className="collapsible-sidebar--toggle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const AccordionCheckbox = ({
expandCheckboxCategoryAccordions(filterCategoryMapping, selectedFilters)
);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ListCheckbox = ({
const [searchString, setSearchString] = useState('');
const [filterCategory, setFilterCategory] = useState(filterCategoryMapping);
const [noResults, setNoResults] = useState(false);
const selectedItemHeight = document.querySelector('.selected-category-item').offsetHeight;
const selectedItemHeight = document.querySelector('.selected-category-item')?.offsetHeight;
// subtracting to account for input box/margin/title header
const [innerDivHeight, setInnerDivHeight] = useState(selectedItemHeight - 53 - 52);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const RecipientSearchContainer = ({ updateSelectedRecipients, selectedRecipients
const [newSearch, setNewSearch] = useState(true);
const [isLoading, setIsLoading] = useState(false);
const [maxRecipients, setMaxRecipients] = useState(true);
const selectedItemHeight = document.querySelector('.selected-category-item').offsetHeight;
const selectedItemHeight = document.querySelector('.selected-category-item')?.offsetHeight;
// subtracting to account for input box/margin/title header/clear all recipients
const [innerDivHeight, setInnerDivHeight] = useState(selectedItemHeight - 53 - 32 - 34 - 20);

Expand Down

0 comments on commit 9cbf257

Please sign in to comment.