1- import { ReactNode , useCallback , useContext } from 'react' ;
1+ import {
2+ ReactNode , useCallback , useContext , useRef , useEffect ,
3+ } from 'react' ;
24import { FormattedMessage , useIntl } from '@edx/frontend-platform/i18n' ;
35import {
46 ActionRow ,
@@ -26,6 +28,8 @@ import { useRunOnNextRender } from '../../utils';
2628import BaseCard from '../components/BaseCard' ;
2729import AddComponentWidget from '../components/AddComponentWidget' ;
2830
31+ const DOUBLE_CLICK_DELAY = 500 ; // ms
32+
2933type ContainerMenuProps = {
3034 containerKey : string ;
3135 displayName : string ;
@@ -247,6 +251,8 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
247251 const { showOnlyPublished } = useLibraryContext ( ) ;
248252 const { openContainerInfoSidebar, openItemSidebar, sidebarItemInfo } = useSidebarContext ( ) ;
249253
254+ const clickTimerRef = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
255+
250256 const {
251257 blockType : itemType ,
252258 formatted,
@@ -269,18 +275,33 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
269275
270276 const { navigateTo } = useLibraryRoutes ( ) ;
271277
272- const selectContainer = useCallback ( ( e ?: React . MouseEvent ) => {
273- const doubleClicked = ( e ?. detail || 0 ) > 1 ;
274- if ( componentPickerMode ) {
275- // In component picker mode, we want to open the sidebar
276- // without changing the URL
277- openContainerInfoSidebar ( containerKey ) ;
278- } else if ( ! doubleClicked ) {
279- openItemSidebar ( containerKey , SidebarBodyItemId . ContainerInfo ) ;
280- } else {
281- navigateTo ( { containerId : containerKey } ) ;
278+ const selectContainer = useCallback (
279+ ( ) => {
280+ if ( clickTimerRef . current ) {
281+ clearTimeout ( clickTimerRef . current ) ;
282+ clickTimerRef . current = null ;
283+
284+ navigateTo ( { containerId : containerKey } ) ;
285+ } else {
286+ clickTimerRef . current = setTimeout ( ( ) => {
287+ clickTimerRef . current = null ;
288+
289+ if ( componentPickerMode ) {
290+ openContainerInfoSidebar ( containerKey ) ;
291+ } else {
292+ openItemSidebar ( containerKey , SidebarBodyItemId . ContainerInfo ) ;
293+ }
294+ } , DOUBLE_CLICK_DELAY ) ;
295+ }
296+ } ,
297+ [ containerKey , componentPickerMode , openContainerInfoSidebar , openItemSidebar , navigateTo ] ,
298+ ) ;
299+
300+ useEffect ( ( ) => ( ) => {
301+ if ( clickTimerRef . current ) {
302+ clearTimeout ( clickTimerRef . current ) ;
282303 }
283- } , [ containerKey , openContainerInfoSidebar , openItemSidebar , navigateTo ] ) ;
304+ } , [ ] ) ;
284305
285306 return (
286307 < BaseCard
0 commit comments