Skip to content

Commit bfe50e0

Browse files
committed
fix ts
1 parent 6fd76db commit bfe50e0

File tree

2 files changed

+58
-731
lines changed

2 files changed

+58
-731
lines changed

packages/app/src/app/pages/Dashboard/Sidebar/index.tsx

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import {
2424
} from '@codesandbox/components';
2525
import css from '@styled-system/css';
2626
import merge from 'deepmerge';
27+
import { WorkspaceSelect } from 'app/components/WorkspaceSelect';
2728
import { ContextMenu } from './ContextMenu';
2829
import { DashboardBaseFolder, PageTypes } from '../types';
2930
import { Position } from '../Components/Selection';
3031
import { SIDEBAR_WIDTH } from './constants';
31-
import { WorkspaceSwitcher } from './WorkspaceSwitcher';
3232
import { DragItemType, useDrop } from '../utils/dnd';
3333

3434
const SidebarContext = React.createContext(null);
@@ -47,13 +47,21 @@ export const Sidebar: React.FC<SidebarProps> = ({
4747
...props
4848
}) => {
4949
const { state, actions } = useOvermind();
50-
const [activeAccount, setActiveAccount] = useState<{
51-
username: string | null;
52-
avatarUrl: string | null;
53-
}>({
54-
username: null,
55-
avatarUrl: null,
56-
});
50+
const [activeAccount, setActiveAccount] = useState<
51+
| {
52+
type: 'user';
53+
id: string;
54+
username: string;
55+
avatarUrl: string;
56+
}
57+
| {
58+
type: 'team';
59+
id: string;
60+
name: string;
61+
avatarUrl: string;
62+
}
63+
| null
64+
>(null);
5765
const { dashboard, user, activeTeam } = state;
5866

5967
React.useEffect(() => {
@@ -65,18 +73,22 @@ export const Sidebar: React.FC<SidebarProps> = ({
6573
const team = dashboard.teams.find(({ id }) => id === state.activeTeam);
6674

6775
if (team)
68-
setActiveAccount({ username: team.name, avatarUrl: team.avatarUrl });
76+
setActiveAccount({
77+
type: 'team',
78+
id: team.id,
79+
name: team.name,
80+
avatarUrl: team.avatarUrl,
81+
});
6982
} else if (user) {
7083
setActiveAccount({
84+
type: 'user',
85+
id: user.id,
7186
username: user.username,
7287
avatarUrl: user.avatarUrl,
7388
});
7489
}
7590
}, [state.activeTeam, state.activeTeamInfo, dashboard.teams, user]);
7691

77-
const inTeamContext =
78-
activeAccount && user && activeAccount.username !== user.username;
79-
8092
const folders = dashboard.allCollections || [];
8193

8294
// context menu for folders
@@ -128,11 +140,40 @@ export const Sidebar: React.FC<SidebarProps> = ({
128140
})}
129141
>
130142
<List>
131-
<ListItem gap={2} css={css({ paddingX: 0, height: 10 })}>
132-
<WorkspaceSwitcher
133-
activeAccount={activeAccount}
134-
inTeamContext={inTeamContext}
135-
/>
143+
<ListItem
144+
css={css({
145+
paddingX: 0,
146+
height: 10,
147+
borderBottom: '1px solid',
148+
borderColor: 'sideBar.border',
149+
})}
150+
>
151+
{activeAccount && (
152+
<WorkspaceSelect
153+
onSelect={workspace => {
154+
actions.setActiveTeam({
155+
id: workspace.type === 'user' ? null : workspace.id,
156+
});
157+
}}
158+
activeAccount={activeAccount}
159+
/>
160+
)}
161+
<Link
162+
css={css({ height: '100%' })}
163+
as={RouterLink}
164+
to={dashboardUrls.settings(state.activeTeam)}
165+
>
166+
<IconButton
167+
name="gear"
168+
size={8}
169+
title="Settings"
170+
css={css({
171+
width: 8,
172+
height: '100%',
173+
borderRadius: 0,
174+
})}
175+
/>
176+
</Link>
136177
</ListItem>
137178
<RowItem
138179
name="Home"

0 commit comments

Comments
 (0)