Skip to content

Commit

Permalink
extract into function
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-crespo-fdc committed Oct 24, 2024
1 parent 587b519 commit e79d80e
Showing 1 changed file with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>
Copyright freiheit.com*/
import {
addAction,
AppDetailsResponse,
AppDetailsState,
EnvironmentGroupExtended,
getAppDetails,
Expand All @@ -34,7 +35,7 @@ import { AppLockSummary } from '../chip/EnvironmentGroupChip';
import { WarningBoxes } from './Warnings';
import { DotsMenu, DotsMenuButton } from './DotsMenu';
import { EnvSelectionDialog } from '../SelectionDialog/SelectionDialogs';
import { useAzureAuthSub } from '../../utils/AzureAuthProvider';
import { AuthHeader, useAzureAuthSub } from '../../utils/AzureAuthProvider';
import { SmallSpinner } from '../Spinner/Spinner';

// number of releases on home. based on design
Expand Down Expand Up @@ -116,23 +117,9 @@ export const ServiceLane: React.FC<{
const componentRef: React.MutableRefObject<any> = React.useRef();

React.useEffect(() => {
if (componentRef.current !== null) {
const rect = componentRef.current.getBoundingClientRect();
if (rect.top >= 0 && rect.bottom <= window.innerHeight) {
if (appDetails.appDetailState === AppDetailsState.NOTREQUESTED) {
getAppDetails(application.name, authHeader);
}
}
}
getAppDetailsIfInView(componentRef, appDetails, authHeader, application.name);
const handleScroll = (): void => {
if (componentRef.current !== null) {
const rect = componentRef.current.getBoundingClientRect();
if (rect.top >= 0 && rect.bottom <= window.innerHeight) {
if (appDetails.appDetailState === AppDetailsState.NOTREQUESTED) {
getAppDetails(application.name, authHeader);
}
}
}
getAppDetailsIfInView(componentRef, appDetails, authHeader, application.name);
};
if (document.getElementsByClassName('mdc-drawer-app-content').length !== 0) {
document.getElementsByClassName('mdc-drawer-app-content')[0].addEventListener('scroll', handleScroll);
Expand Down Expand Up @@ -172,6 +159,22 @@ export const ServiceLane: React.FC<{
);
};

function getAppDetailsIfInView(
componentRef: React.MutableRefObject<any>,
appDetails: AppDetailsResponse,
authHeader: AuthHeader,
appName: string
): void {
if (componentRef.current !== null) {
const rect = componentRef.current.getBoundingClientRect();
if (rect.top >= 0 && rect.bottom <= window.innerHeight) {
if (appDetails.appDetailState === AppDetailsState.NOTREQUESTED) {
getAppDetails(appName, authHeader);
}
}
}
}

export const ReadyServiceLane: React.FC<{
application: OverviewApplication;
hideMinors: boolean;
Expand Down

0 comments on commit e79d80e

Please sign in to comment.