@@ -35,6 +35,7 @@ import {
3535 useServices ,
3636 WorkspaceService ,
3737} from '@toeverything/infra' ;
38+ import type { MouseEvent } from 'react' ;
3839import { useCallback , useState } from 'react' ;
3940
4041import type { CollectionService } from '../../modules/collection' ;
@@ -324,29 +325,48 @@ export const CollectionOperationCell = ({
324325 title : t [ 'com.affine.editCollection.renameCollection' ] ( ) ,
325326 } ) ;
326327
327- const handleEditName = useCallback ( ( ) => {
328- // use openRenameModal if it is in the sidebar collection list
329- openEditCollectionNameModal ( collection . name )
330- . then ( name => {
331- return service . updateCollection ( collection . id , collection => ( {
332- ...collection ,
333- name,
334- } ) ) ;
335- } )
336- . catch ( err => {
337- console . error ( err ) ;
338- } ) ;
339- } , [ collection . id , collection . name , openEditCollectionNameModal , service ] ) ;
340-
341- const handleEdit = useCallback ( ( ) => {
342- openEditCollectionModal ( collection )
343- . then ( collection => {
344- return service . updateCollection ( collection . id , ( ) => collection ) ;
345- } )
346- . catch ( err => {
347- console . error ( err ) ;
348- } ) ;
349- } , [ openEditCollectionModal , collection , service ] ) ;
328+ const handlePropagation = useCallback ( ( event : MouseEvent ) => {
329+ event . preventDefault ( ) ;
330+ event . stopPropagation ( ) ;
331+ } , [ ] ) ;
332+
333+ const handleEditName = useCallback (
334+ ( event : MouseEvent ) => {
335+ handlePropagation ( event ) ;
336+ // use openRenameModal if it is in the sidebar collection list
337+ openEditCollectionNameModal ( collection . name )
338+ . then ( name => {
339+ return service . updateCollection ( collection . id , collection => ( {
340+ ...collection ,
341+ name,
342+ } ) ) ;
343+ } )
344+ . catch ( err => {
345+ console . error ( err ) ;
346+ } ) ;
347+ } ,
348+ [
349+ collection . id ,
350+ collection . name ,
351+ handlePropagation ,
352+ openEditCollectionNameModal ,
353+ service ,
354+ ]
355+ ) ;
356+
357+ const handleEdit = useCallback (
358+ ( event : MouseEvent ) => {
359+ handlePropagation ( event ) ;
360+ openEditCollectionModal ( collection )
361+ . then ( collection => {
362+ return service . updateCollection ( collection . id , ( ) => collection ) ;
363+ } )
364+ . catch ( err => {
365+ console . error ( err ) ;
366+ } ) ;
367+ } ,
368+ [ handlePropagation , openEditCollectionModal , collection , service ]
369+ ) ;
350370
351371 const handleDelete = useCallback ( ( ) => {
352372 return service . deleteCollection ( info , collection . id ) ;
0 commit comments