mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 02:21:51 +08:00
fix: dnd workspace list will cause page to reload (#1848)
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
|||||||
} from './styles';
|
} from './styles';
|
||||||
|
|
||||||
interface WorkspaceModalProps {
|
interface WorkspaceModalProps {
|
||||||
|
disabled?: boolean;
|
||||||
user: AccessTokenMessage | null;
|
user: AccessTokenMessage | null;
|
||||||
workspaces: AllWorkspace[];
|
workspaces: AllWorkspace[];
|
||||||
currentWorkspaceId: AllWorkspace['id'] | null;
|
currentWorkspaceId: AllWorkspace['id'] | null;
|
||||||
@@ -43,6 +44,7 @@ interface WorkspaceModalProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const WorkspaceListModal = ({
|
export const WorkspaceListModal = ({
|
||||||
|
disabled,
|
||||||
open,
|
open,
|
||||||
onClose,
|
onClose,
|
||||||
workspaces,
|
workspaces,
|
||||||
@@ -96,6 +98,7 @@ export const WorkspaceListModal = ({
|
|||||||
|
|
||||||
<StyledModalContent>
|
<StyledModalContent>
|
||||||
<WorkspaceList
|
<WorkspaceList
|
||||||
|
disabled={disabled}
|
||||||
items={workspaces}
|
items={workspaces}
|
||||||
currentWorkspaceId={currentWorkspaceId}
|
currentWorkspaceId={currentWorkspaceId}
|
||||||
onClick={onClickWorkspace}
|
onClick={onClickWorkspace}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
|||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { useCallback } from 'react';
|
import { useCallback, useTransition } from 'react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
currentWorkspaceIdAtom,
|
currentWorkspaceIdAtom,
|
||||||
@@ -45,10 +45,12 @@ export function Modals() {
|
|||||||
const currentWorkspaceId = useAtomValue(currentWorkspaceIdAtom);
|
const currentWorkspaceId = useAtomValue(currentWorkspaceIdAtom);
|
||||||
const [, setCurrentWorkspace] = useCurrentWorkspace();
|
const [, setCurrentWorkspace] = useCurrentWorkspace();
|
||||||
const { createLocalWorkspace } = useWorkspacesHelper();
|
const { createLocalWorkspace } = useWorkspacesHelper();
|
||||||
|
const [transitioning, transition] = useTransition();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WorkspaceListModal
|
<WorkspaceListModal
|
||||||
|
disabled={transitioning}
|
||||||
user={user}
|
user={user}
|
||||||
workspaces={workspaces}
|
workspaces={workspaces}
|
||||||
currentWorkspaceId={currentWorkspaceId}
|
currentWorkspaceId={currentWorkspaceId}
|
||||||
@@ -60,8 +62,10 @@ export function Modals() {
|
|||||||
(activeId, overId) => {
|
(activeId, overId) => {
|
||||||
const oldIndex = workspaces.findIndex(w => w.id === activeId);
|
const oldIndex = workspaces.findIndex(w => w.id === activeId);
|
||||||
const newIndex = workspaces.findIndex(w => w.id === overId);
|
const newIndex = workspaces.findIndex(w => w.id === overId);
|
||||||
setWorkspaces(workspaces =>
|
transition(() =>
|
||||||
arrayMove(workspaces, oldIndex, newIndex)
|
setWorkspaces(workspaces =>
|
||||||
|
arrayMove(workspaces, oldIndex, newIndex)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[setWorkspaces, workspaces]
|
[setWorkspaces, workspaces]
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import type { FC } from 'react';
|
|||||||
import { WorkspaceCard } from '../workspace-card';
|
import { WorkspaceCard } from '../workspace-card';
|
||||||
|
|
||||||
export type WorkspaceListProps = {
|
export type WorkspaceListProps = {
|
||||||
|
disabled?: boolean;
|
||||||
currentWorkspaceId: string | null;
|
currentWorkspaceId: string | null;
|
||||||
items: (AffineWorkspace | LocalWorkspace)[];
|
items: (AffineWorkspace | LocalWorkspace)[];
|
||||||
onClick: (workspace: AffineWorkspace | LocalWorkspace) => void;
|
onClick: (workspace: AffineWorkspace | LocalWorkspace) => void;
|
||||||
@@ -27,11 +28,13 @@ const SortableWorkspaceItem: FC<
|
|||||||
const { setNodeRef, attributes, listeners, transform } = useSortable({
|
const { setNodeRef, attributes, listeners, transform } = useSortable({
|
||||||
id: props.item.id,
|
id: props.item.id,
|
||||||
});
|
});
|
||||||
const style = transform
|
const style: React.CSSProperties = {
|
||||||
? {
|
transform: transform
|
||||||
transform: `translate3d(${transform.x}px, ${transform.y}px, 0)`,
|
? `translate3d(${transform.x}px, ${transform.y}px, 0)`
|
||||||
}
|
: undefined,
|
||||||
: undefined;
|
pointerEvents: props.disabled ? 'none' : undefined,
|
||||||
|
opacity: props.disabled ? 0.6 : undefined,
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
data-testid="draggable-item"
|
data-testid="draggable-item"
|
||||||
|
|||||||
Reference in New Issue
Block a user