fix(core): page jumps unexpectedly when clicking the collection operation (#8182)
close AF-1371 https://github.com/user-attachments/assets/9cc25790-8755-458c-94ac-a8d1b584c428
This commit is contained in:
@@ -35,6 +35,7 @@ import {
|
|||||||
useServices,
|
useServices,
|
||||||
WorkspaceService,
|
WorkspaceService,
|
||||||
} from '@toeverything/infra';
|
} from '@toeverything/infra';
|
||||||
|
import type { MouseEvent } from 'react';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
|
||||||
import type { CollectionService } from '../../modules/collection';
|
import type { CollectionService } from '../../modules/collection';
|
||||||
@@ -324,7 +325,14 @@ export const CollectionOperationCell = ({
|
|||||||
title: t['com.affine.editCollection.renameCollection'](),
|
title: t['com.affine.editCollection.renameCollection'](),
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleEditName = useCallback(() => {
|
const handlePropagation = useCallback((event: MouseEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleEditName = useCallback(
|
||||||
|
(event: MouseEvent) => {
|
||||||
|
handlePropagation(event);
|
||||||
// use openRenameModal if it is in the sidebar collection list
|
// use openRenameModal if it is in the sidebar collection list
|
||||||
openEditCollectionNameModal(collection.name)
|
openEditCollectionNameModal(collection.name)
|
||||||
.then(name => {
|
.then(name => {
|
||||||
@@ -336,9 +344,19 @@ export const CollectionOperationCell = ({
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
}, [collection.id, collection.name, openEditCollectionNameModal, service]);
|
},
|
||||||
|
[
|
||||||
|
collection.id,
|
||||||
|
collection.name,
|
||||||
|
handlePropagation,
|
||||||
|
openEditCollectionNameModal,
|
||||||
|
service,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
const handleEdit = useCallback(() => {
|
const handleEdit = useCallback(
|
||||||
|
(event: MouseEvent) => {
|
||||||
|
handlePropagation(event);
|
||||||
openEditCollectionModal(collection)
|
openEditCollectionModal(collection)
|
||||||
.then(collection => {
|
.then(collection => {
|
||||||
return service.updateCollection(collection.id, () => collection);
|
return service.updateCollection(collection.id, () => collection);
|
||||||
@@ -346,7 +364,9 @@ export const CollectionOperationCell = ({
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
}, [openEditCollectionModal, collection, service]);
|
},
|
||||||
|
[handlePropagation, openEditCollectionModal, collection, service]
|
||||||
|
);
|
||||||
|
|
||||||
const handleDelete = useCallback(() => {
|
const handleDelete = useCallback(() => {
|
||||||
return service.deleteCollection(info, collection.id);
|
return service.deleteCollection(info, collection.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user