Skip to content

Commit

Permalink
Replicate ferdium#497
Browse files Browse the repository at this point in the history
  • Loading branch information
m-roberts committed Dec 24, 2022
1 parent 21582fd commit 4e856a3
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 19 deletions.
87 changes: 68 additions & 19 deletions src/features/workspaces/components/WorkspaceDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { observer } from 'mobx-react';
import withStyles, { WithStylesProps } from 'react-jss';
import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl';
import ReactTooltip from 'react-tooltip';
import { mdiPlusBox, mdiCog } from '@mdi/js';
import { mdiPlusBox, mdiCog, mdiMenuUp, mdiMenuDown } from '@mdi/js';
import { noop } from 'lodash';
import { H1 } from '../../../components/ui/headline';
import Icon from '../../../components/ui/icon';
Expand Down Expand Up @@ -63,7 +63,7 @@ const styles = theme => ({
},
workspaces: {
height: 'auto',
overflowY: 'auto',
overflowY: 'visible',
},
addNewWorkspaceLabel: {
height: 'auto',
Expand Down Expand Up @@ -103,6 +103,27 @@ class WorkspaceDrawer extends Component<IProps> {
}
}

handleClick(e, workspaces, index) {
switch (e) {
case 'goUp':
if (index !== 0) {
const toIndex = index - 1;
const element = workspaces.splice(index, 1)[0];
workspaces.splice(toIndex, 0, element);
}
break;
case 'goDown':
if (index !== workspaces.length - 1) {
const toIndex = index + 1;
const element = workspaces.splice(index, 1)[0];
workspaces.splice(toIndex, 0, element);
}
break;
default:
break;
}
}

render(): ReactElement {
const { classes, getServicesForWorkspace } = this.props;
const { intl } = this.props;
Expand Down Expand Up @@ -144,23 +165,51 @@ class WorkspaceDrawer extends Component<IProps> {
shortcutIndex={0}
/>
{workspaces.map((workspace, index) => (
<WorkspaceDrawerItem
key={workspace.id}
name={workspace.name}
isActive={actualWorkspace === workspace}
onClick={() => {
if (actualWorkspace === workspace) {
return;
}
workspaceActions.activate({ workspace });
workspaceActions.toggleWorkspaceDrawer();
}}
onContextMenuEditClick={() =>
workspaceActions.edit({ workspace })
}
services={getServicesForWorkspace(workspace)}
shortcutIndex={index + 1}
/>
<div className="wrapper-workspaces-drawer-item">
<div className="wrapper-workspaces-drawer-item__workspaces">
<WorkspaceDrawerItem
key={workspace.id}
name={workspace.name}
isActive={actualWorkspace === workspace}
onClick={() => {
if (actualWorkspace === workspace) {
return;
}
workspaceActions.activate({ workspace });
workspaceActions.toggleWorkspaceDrawer();
}}
onContextMenuEditClick={() =>
workspaceActions.edit({ workspace })
}
services={getServicesForWorkspace(workspace)}
shortcutIndex={index + 1}
/>
</div>
<div className="wrapper-workspaces-drawer-item__buttons">
{index !== 0 && (
<button
type="button"
onClick={() => {
this.handleClick('goUp', workspaces, index);
}}
className="button-up"
>
<Icon icon={mdiMenuUp} size={1.5} />
</button>
)}
{index !== workspaces.length - 1 && (
<button
type="button"
onClick={() => {
this.handleClick('goDown', workspaces, index);
}}
className="button-down"
>
<Icon icon={mdiMenuDown} size={1.5} />
</button>
)}
</div>
</div>
))}
<div
className={classes.addNewWorkspaceLabel}
Expand Down
25 changes: 25 additions & 0 deletions src/styles/vertical.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,31 @@ $tabitem-bias: 30px;
}
}

.wrapper-workspaces-drawer-item {
height: fit-content;
display: flex;
align-items: center;
width: 107%;

&__workspaces {
display: flex;
flex-basis: 100%;

& > div {
width: 100%;
overflow: auto;
}
}
&__buttons {
display: flex;
flex-direction: column;
position: relative;
top: 0;
right: 9%;
bottom: 0;
}
}

.theme__dark {
.sidebar .sidebar__button--workspaces.is-active {
background-color: #2d2f31;
Expand Down

0 comments on commit 4e856a3

Please sign in to comment.