Skip to content

Commit

Permalink
Improve breadcrumb memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
adammertel committed Dec 15, 2024
1 parent ca29d07 commit 43e088c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Dropdown, {
TerritoryActionModal,
} from "components/advanced";
import { useSearchParams } from "hooks";
import React, { useEffect, useState } from "react";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { FaHighlighter, FaList, FaTrash } from "react-icons/fa";
import {
MdOutlineCheckBox,
Expand Down Expand Up @@ -367,6 +367,23 @@ export const StatementListHeader: React.FC<StatementListHeader> = ({
useState<HTMLSpanElement | null>(null);
const [showSubmit, setShowSubmit] = useState(false);

const BreadcrumbItems = useMemo(() => {
return (
<React.Fragment>
{selectedTerritoryPath?.map((territoryId: string, key: number) => {
return (
<React.Fragment key={key}>
<BreadcrumbItem territoryId={territoryId} />
</React.Fragment>
);
})}
<React.Fragment key="this-territory">
<BreadcrumbItem territoryId={territoryId} territoryData={territory} />
</React.Fragment>
</React.Fragment>
);
}, [selectedTerritoryPath.join(",")]);

return (
<>
<Tooltip
Expand All @@ -376,22 +393,7 @@ export const StatementListHeader: React.FC<StatementListHeader> = ({
/>

<StyledHeader>
<StyledHeaderBreadcrumbRow>
{selectedTerritoryPath &&
selectedTerritoryPath.map((territoryId: string, key: number) => {
return (
<React.Fragment key={key}>
<BreadcrumbItem territoryId={territoryId} />
</React.Fragment>
);
})}
<React.Fragment key="this-territory">
<BreadcrumbItem
territoryId={territoryId}
territoryData={territory}
/>
</React.Fragment>
</StyledHeaderBreadcrumbRow>
<StyledHeaderBreadcrumbRow>{BreadcrumbItems}</StyledHeaderBreadcrumbRow>

<StyledHeaderRow>
<span style={{ display: "grid", gridTemplateColumns: "auto auto" }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const StatementListTextAnnotator: React.FC<
);

if (newSelectedOccurence) {
annotator?.selectSearchOccurence(newSelectedOccurence);
annotator?.selectSearchOccurrence(newSelectedOccurence);
}
}, [searchActiveOccurence, searchOccurences]);

Expand Down

0 comments on commit 43e088c

Please sign in to comment.