Skip to content

Commit

Permalink
Prevent redundant question navigation in BingeMap
Browse files Browse the repository at this point in the history
- Add checks to skip question update when selecting the current question
- Improve node selection logic to avoid unnecessary state changes
- Enhance user experience by preventing duplicate navigation
  • Loading branch information
aralyekta committed Feb 25, 2025
1 parent 2c62877 commit 68ec897
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/gurubase-frontend/src/components/BingeMap/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ export function BingeMap({
setPan(optimalPan);

if (isDesktop) {
if (clickedNode.slug) {
// Skip handleQuestionUpdate if the clicked node is already the current question
if (clickedNode.slug && clickedNode.slug !== currentQuestionSlug) {
dispatch(setIsBingeMapOpen(false));
dispatch(setInputQuery(""));

Expand Down Expand Up @@ -508,24 +509,27 @@ export function BingeMap({
};

const handleNodeSelect = async (selectedNode) => {
// Skip handleQuestionUpdate if the selected node is already the current question
dispatch(setIsBingeMapOpen(false));
setPan({ x: 0, y: 0 });
setActiveNode(null);
setHoveredNode(null);
dispatch(setInputQuery(""));

await handleQuestionUpdate({
guruType,
newSlug: selectedNode.slug,
oldSlug: currentQuestionSlug,
treeData,
dispatch,
setContent,
setQuestion,
setDescription,
bingeId,
questionText
});
if (selectedNode.slug !== currentQuestionSlug) {
await handleQuestionUpdate({
guruType,
newSlug: selectedNode.slug,
oldSlug: currentQuestionSlug,
treeData,
dispatch,
setContent,
setQuestion,
setDescription,
bingeId,
questionText
});
}
};

const handleZoomIn = () => {
Expand Down

0 comments on commit 68ec897

Please sign in to comment.