Skip to content

Commit

Permalink
update the workspaces, selected workspaces and view mode properly whe…
Browse files Browse the repository at this point in the history
…n creating the workspace
  • Loading branch information
Salam-Dalloul committed Aug 8, 2024
1 parent 57260fd commit 2ceb605
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { useGlobalContext } from "../contexts/GlobalContext.tsx";
import { parseURLParams } from "../helpers/parseURLHelper.ts";
import { TEMPLATE_ACTIVE_DATASETS, TEMPLATE_ACTIVE_NEURONS } from "../settings/templateWorkspaceSettings.ts";
function AppLauncher() {
const { workspaces, createWorkspace, setCurrentWorkspace } = useGlobalContext();
const { workspaces, createWorkspace, setCurrentWorkspace, setSelectedWorkspacesIds } = useGlobalContext();

const handleTemplateClick = async () => {
const workspaceId = `workspace-${Date.now()}`;
const workspaceName = `Template Workspace ${Object.keys(workspaces).length + 1}`;

createWorkspace(workspaceId, workspaceName, new Set(TEMPLATE_ACTIVE_DATASETS), new Set(TEMPLATE_ACTIVE_NEURONS));
setCurrentWorkspace(workspaceId);
setSelectedWorkspacesIds(new Set<string>([workspaceId]));
};

const handleBlankClick = () => {
Expand All @@ -20,6 +20,7 @@ function AppLauncher() {

createWorkspace(workspaceId, workspaceName, new Set(TEMPLATE_ACTIVE_DATASETS));
setCurrentWorkspace(workspaceId);
setSelectedWorkspacesIds(new Set<string>([workspaceId]));
};

const handlePasteUrlClick = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,22 @@ const Header = ({
const onClick = (_: React.MouseEvent, index: number) => {
updateActiveState(index);
};

const onClose = () => {
setShowModal(false);
const newIndex = Array.from(selectedWorkspacesIds).length >= 2 ? 1 : 0;
setActive(newIndex);
setViewMode(ViewMode.Compare);
if (Object.keys(workspaces).length > 1) {
setActive(newIndex);
setViewMode(ViewMode.Compare);
} else {
setActive(0);
setViewMode(ViewMode.Default);
}
};

useEffect(() => {
const newIndex = Array.from(selectedWorkspacesIds).length >= 2 ? 1 : 0;
setActive(newIndex);
}, [selectedWorkspacesIds, viewMode]);
}, [selectedWorkspacesIds]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const LoadingComponent = () => (

function WorkspaceComponent({ sidebarOpen }) {
const dispatch = useDispatch();
const { workspaces, setCurrentWorkspace, removeWorkspace, selectedWorkspacesIds, setSelectedWorkspacesIds, setAllWorkspaces, setViewMode } =
const { workspaces, setCurrentWorkspace, removeWorkspace, selectedWorkspacesIds, setSelectedWorkspacesIds, setAllWorkspaces, setViewMode, viewMode } =
useGlobalContext();

const workspaceId = useSelector((state: RootState) => state.workspaceId);
Expand Down Expand Up @@ -66,13 +66,10 @@ function WorkspaceComponent({ sidebarOpen }) {
};

const onClickWorkspace = (workspace) => {
const updatedIds = Array.from(selectedWorkspacesIds);
let updatedIds = Array.from(selectedWorkspacesIds);
const index = updatedIds.indexOf(workspaceId);
if (index !== -1) {
updatedIds[index] = workspace.id;
} else {
updatedIds.push(workspace.id);
}

updatedIds = updateIds(updatedIds, index, workspace.id, viewMode);

const newSelectedWorkspacesIds = new Set(updatedIds);
setCurrentWorkspace(workspace.id);
Expand All @@ -94,6 +91,19 @@ function WorkspaceComponent({ sidebarOpen }) {

setAllWorkspaces(sortedWorkspacesRecord);
};

const updateIds = (ids, index, id, viewMode) => {
if (index !== -1) {
ids[index] = id;
} else {
if (viewMode === ViewMode.Compare) {
ids.push(id);
} else {
ids = [id];
}
}
return ids;
};
const handleMouseEnter = (workspaceId) => {
setHoveredWorkspaceId(workspaceId);
};
Expand Down

0 comments on commit 2ceb605

Please sign in to comment.