Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent context color flickering while navigating #1365

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/frontend/src/api/useParties.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery, useQueryClient } from '@tanstack/react-query';
import type { PartiesQuery, PartyFieldsFragment } from 'bff-types-generated';
import { useEffect } from 'react';
import { useEffect, useMemo } from 'react';
import { useLocation, useSearchParams } from 'react-router-dom';
import { normalizeFlattenParties } from '../components/PartyDropdown/normalizeFlattenParties.ts';
import { QUERY_KEYS } from '../constants/queryKeys.ts';
Expand All @@ -18,6 +18,7 @@ interface UsePartiesOutput {
setSelectedPartyIds: (parties: string[], allOrganizationsSelected: boolean) => void;
currentEndUser: PartyFieldsFragment | undefined;
allOrganizationsSelected: boolean;
selectedProfile: 'company' | 'person';
}

interface PartiesResult {
Expand Down Expand Up @@ -131,13 +132,24 @@ export const useParties = (): UsePartiesOutput => {
}
};

const isCompanyFromParams = useMemo(() => {
const party = searchParams.get('party');
const allParties = searchParams.get('allParties');
return Boolean(party || allParties);
}, [searchParams]);

// biome-ignore lint/correctness/useExhaustiveDependencies: Full control of what triggers this code is needed
useEffect(() => {
if (isSuccess && data?.parties?.length > 0) {
handlePartySelection();
}
}, [isSuccess, data?.parties, location.search]);

const isCompanyProfile =
isCompanyFromParams || allOrganizationsSelected || selectedParties?.[0]?.partyType === 'Organization';

const selectedProfile = (isCompanyProfile ? 'company' : 'person') as 'company' | 'person';

return {
isLoading,
isSuccess,
Expand All @@ -149,5 +161,6 @@ export const useParties = (): UsePartiesOutput => {
currentEndUser: data?.parties.find((party) => party.isCurrentEndUser),
deletedParties: data?.deletedParties ?? [],
allOrganizationsSelected,
selectedProfile,
};
};
9 changes: 3 additions & 6 deletions packages/frontend/src/components/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const PageLayoutContent: React.FC<PageLayoutContentProps> = memo(

const Background: React.FC<{ children: React.ReactNode; isCompany: boolean }> = ({ children, isCompany }) => {
const { inSelectionMode } = useSelectedDialogs();

return (
<div
data-testid="pageLayout-background"
Expand All @@ -90,14 +89,12 @@ export const ProtectedPageLayout = () => {
export const PageLayout: React.FC = () => {
const queryClient = useQueryClient();
const { t } = useTranslation();
const { selectedParties, allOrganizationsSelected } = useParties();
const { selectedParties, allOrganizationsSelected, selectedProfile } = useParties();
const [searchParams] = useSearchParams();

useProfile();

const name = allOrganizationsSelected ? t('parties.labels.all_organizations') : selectedParties?.[0]?.name || '';
const isCompany = allOrganizationsSelected || selectedParties?.[0]?.partyType === 'Organization';
const profile = isCompany ? 'company' : 'person';

useUpdateOnLocationChange(() => {
const searchString = getSearchStringFromQueryParams(searchParams);
Expand All @@ -106,10 +103,10 @@ export const PageLayout: React.FC = () => {

return (
<SelectedDialogsContainer>
<Background isCompany={isCompany}>
<Background isCompany={selectedProfile === 'company'}>
<BottomDrawerContainer>
<BetaBanner />
<PageLayoutContent name={name} profile={profile} />
<PageLayoutContent name={name} profile={selectedProfile} />
<Snackbar />
</BottomDrawerContainer>
</Background>
Expand Down
Loading