feat: open collection or unit page on double click only (#2002)
Opens collection or unit page only on double click.
This commit is contained in:
@@ -48,7 +48,8 @@ const CollectionInfo = () => {
|
||||
if (componentPickerMode) {
|
||||
setCollectionId(collectionId);
|
||||
} else {
|
||||
navigateTo({ collectionId });
|
||||
/* istanbul ignore next */
|
||||
navigateTo({ collectionId, doubleClicked: true });
|
||||
}
|
||||
}, [componentPickerMode, navigateTo]);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ type BaseCardProps = {
|
||||
tags: ContentHitTags;
|
||||
actions: React.ReactNode;
|
||||
hasUnpublishedChanges?: boolean;
|
||||
onSelect: () => void;
|
||||
onSelect: (e?: React.MouseEvent) => void;
|
||||
selected?: boolean;
|
||||
};
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ type CollectionCardProps = {
|
||||
|
||||
const CollectionCard = ({ hit } : CollectionCardProps) => {
|
||||
const { componentPickerMode } = useComponentPickerContext();
|
||||
const { showOnlyPublished } = useLibraryContext();
|
||||
const { showOnlyPublished, setCollectionId } = useLibraryContext();
|
||||
const { openCollectionInfoSidebar, sidebarComponentInfo } = useSidebarContext();
|
||||
|
||||
const {
|
||||
@@ -136,11 +136,15 @@ const CollectionCard = ({ hit } : CollectionCardProps) => {
|
||||
&& sidebarComponentInfo.id === collectionId;
|
||||
|
||||
const { navigateTo } = useLibraryRoutes();
|
||||
const openCollection = useCallback(() => {
|
||||
const openCollection = useCallback((e?: React.MouseEvent) => {
|
||||
openCollectionInfoSidebar(collectionId);
|
||||
const doubleClicked = (e?.detail || 0) > 1;
|
||||
|
||||
if (!componentPickerMode) {
|
||||
navigateTo({ collectionId });
|
||||
navigateTo({ collectionId, doubleClicked });
|
||||
} else if (doubleClicked) {
|
||||
/* istanbul ignore next */
|
||||
setCollectionId(collectionId);
|
||||
}
|
||||
}, [collectionId, navigateTo, openCollectionInfoSidebar]);
|
||||
|
||||
|
||||
@@ -204,12 +204,12 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
|
||||
|
||||
const { navigateTo } = useLibraryRoutes();
|
||||
|
||||
const openContainer = useCallback(() => {
|
||||
const openContainer = useCallback((e?: React.MouseEvent) => {
|
||||
if (itemType === 'unit') {
|
||||
openUnitInfoSidebar(unitId);
|
||||
setUnitId(unitId);
|
||||
if (!componentPickerMode) {
|
||||
navigateTo({ unitId });
|
||||
navigateTo({ unitId, doubleClicked: (e?.detail || 0) > 1 });
|
||||
}
|
||||
}
|
||||
}, [unitId, itemType, openUnitInfoSidebar, navigateTo]);
|
||||
|
||||
@@ -49,6 +49,7 @@ export type NavigateToData = {
|
||||
collectionId?: string,
|
||||
contentType?: ContentType,
|
||||
unitId?: string,
|
||||
doubleClicked?: boolean,
|
||||
};
|
||||
|
||||
export type LibraryRoutesData = {
|
||||
@@ -80,6 +81,7 @@ export const useLibraryRoutes = (): LibraryRoutesData => {
|
||||
collectionId,
|
||||
unitId,
|
||||
contentType,
|
||||
doubleClicked,
|
||||
}: NavigateToData = {}) => {
|
||||
const {
|
||||
collectionId: urlCollectionId,
|
||||
@@ -125,7 +127,7 @@ export const useLibraryRoutes = (): LibraryRoutesData => {
|
||||
} else if (insideCollections) {
|
||||
// We're inside the Collections tab,
|
||||
route = (
|
||||
(collectionId && collectionId === (urlCollectionId || urlSelectedItemId))
|
||||
(collectionId && doubleClicked)
|
||||
// now open the previously-selected collection,
|
||||
? ROUTES.COLLECTION
|
||||
// or stay there to list all collections, or a selected collection.
|
||||
@@ -142,7 +144,7 @@ export const useLibraryRoutes = (): LibraryRoutesData => {
|
||||
} else if (insideUnits) {
|
||||
// We're inside the units tab,
|
||||
route = (
|
||||
(unitId && unitId === (urlUnitId || urlSelectedItemId))
|
||||
(unitId && doubleClicked)
|
||||
// now open the previously-selected unit,
|
||||
? ROUTES.UNIT
|
||||
// or stay there to list all units, or a selected unit.
|
||||
@@ -156,10 +158,10 @@ export const useLibraryRoutes = (): LibraryRoutesData => {
|
||||
// We're inside the All Content tab, so stay there,
|
||||
// and select a component.
|
||||
route = ROUTES.COMPONENT;
|
||||
} else if (collectionId && collectionId === (urlCollectionId || urlSelectedItemId)) {
|
||||
} else if (collectionId && doubleClicked) {
|
||||
// now open the previously-selected collection
|
||||
route = ROUTES.COLLECTION;
|
||||
} else if (unitId && unitId === (urlUnitId || urlSelectedItemId)) {
|
||||
} else if (unitId && doubleClicked) {
|
||||
// now open the previously-selected unit
|
||||
route = ROUTES.UNIT;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user