Skip to content

Commit

Permalink
fix: prevent collection navigation on double click
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Jan 16, 2025
1 parent 3bc0186 commit 645e841
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/library-authoring/collections/CollectionInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Tabs,
} from '@openedx/paragon';
import { useCallback } from 'react';
import { useNavigate } from 'react-router-dom';

import { useComponentPickerContext } from '../common/context/ComponentPickerContext';
import { useLibraryContext } from '../common/context/LibraryContext';
Expand All @@ -24,6 +25,7 @@ import messages from './messages';

const CollectionInfo = () => {
const intl = useIntl();
const navigate = useNavigate();

const { componentPickerMode } = useComponentPickerContext();
const { libraryId, setCollectionId } = useLibraryContext();
Expand All @@ -48,7 +50,7 @@ const CollectionInfo = () => {
if (componentPickerMode) {
setCollectionId(collectionId);
} else {
navigateTo({ collectionId });
navigate(`/library/${libraryId}/collection/${collectionId}`);

Check warning on line 53 in src/library-authoring/collections/CollectionInfo.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/collections/CollectionInfo.tsx#L53

Added line #L53 was not covered by tests
}
}, [componentPickerMode, navigateTo]);

Expand Down
16 changes: 2 additions & 14 deletions src/library-authoring/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,7 @@ export const useLibraryRoutes = (): LibraryRoutesData => {
route = ROUTES.HOME;
} else if (insideCollections) {
// We're inside the Collections tab,
route = (
(collectionId && collectionId === params.collectionId)
// now open the previously-selected collection,
? ROUTES.COLLECTION
// or stay there to list all collections, or a selected collection.
: ROUTES.COLLECTIONS
);
route = ROUTES.COLLECTIONS;
} else if (insideCollection) {
// We're viewing a Collection, so stay there,
// and optionally select a component in that collection.
Expand All @@ -103,13 +97,7 @@ export const useLibraryRoutes = (): LibraryRoutesData => {
route = ROUTES.COMPONENT;
} else {
// We're inside the All Content tab,
route = (
(collectionId && collectionId === params.collectionId)
// now open the previously-selected collection
? ROUTES.COLLECTION
// or stay there to list all content, or optionally select a collection.
: ROUTES.HOME
);
route = ROUTES.HOME;
}

const newPath = generatePath(BASE_ROUTE + route, routeParams);
Expand Down

0 comments on commit 645e841

Please sign in to comment.