Skip to content

Commit d4566b3

Browse files
refactor(overmind-devtools): improve the UI
1 parent b2d6a9c commit d4566b3

File tree

14 files changed

+137
-61
lines changed

14 files changed

+137
-61
lines changed

packages/node_modules/overmind-devtools/src/app/actions.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,13 @@ export const toggleGroupedComponent: Action<string> = ({
152152
}
153153
}
154154

155-
export const selectApp: Action<string> = ({ value: appName, state }) =>
156-
(state.currentAppName = appName)
155+
export const selectApp: Action<string> = ({ value: appName, state }) => {
156+
state.currentAppName = appName
157+
state.showApps = false
158+
}
157159

158160
export const toggleExpandAllActions: Action = ({ state }) =>
159161
(state.expandAllActionDetails = !state.expandAllActionDetails)
162+
163+
export const toggleShowApps: Action = ({ state }) =>
164+
(state.showApps = !state.showApps)

packages/node_modules/overmind-devtools/src/app/operators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export const addMutations = mutate<MutationsMessage>(
282282
const operator =
283283
state.apps[message.appName].actions[id].operators[mutations.operatorId]
284284

285-
operator.mutations = mutations.mutations
285+
operator.mutations = operator.mutations.concat(mutations.mutations)
286286
}
287287
)
288288

packages/node_modules/overmind-devtools/src/app/state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type State = {
1717
currentAppName: string
1818
newPortValue: string
1919
currentTab: Tab
20+
showApps: boolean
2021
expandedStatePaths: string[]
2122
expandAllActionDetails: boolean
2223
expandedComponents: string[]
@@ -34,6 +35,7 @@ type State = {
3435
const state: State = {
3536
isConnecting: true,
3637
error: null,
38+
showApps: false,
3739
currentAppName: null,
3840
port: '3031',
3941
apps: {},

packages/node_modules/overmind-devtools/src/app/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,13 @@ export const ensureFlushExists = (flushes, flushId) => {
6969
flushes[flushId] = flush
7070
}
7171
}
72+
73+
export const getAppShortName = (name: string) => {
74+
const firstLetters = name.split(' ').map((word) => word[0].toUpperCase())
75+
76+
if (firstLetters.length >= 2) {
77+
return firstLetters.slice(0, 2)
78+
}
79+
80+
return name.substr(0, 2)
81+
}

packages/node_modules/overmind-devtools/src/components/ActionsList/elements.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const ActionColor = styled<
2626
>('span')`
2727
position: absolute;
2828
top: 0;
29-
left: 0;
29+
right: 0;
3030
width: 10px;
3131
height: 100%;
3232
background-color: ${({ color }) => color};
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import styled from '../../styled-components'
2+
3+
export const Wrapper = styled.div`
4+
position: relative;
5+
display: flex;
6+
background-color: ${({ theme }) => theme.color.white};
7+
height: 50px;
8+
justify-content: center;
9+
align-items: center;
10+
`
11+
12+
export const App = styled<
13+
{
14+
isSelected: boolean
15+
},
16+
'button'
17+
>('button')`
18+
outline: none;
19+
border: 0;
20+
width: 100%;
21+
cursor: pointer;
22+
background-color: ${({ theme, isSelected }) =>
23+
isSelected
24+
? theme.color.lighten(theme.color.white, -0.03)
25+
: theme.color.lighten(theme.color.white, -0.01)};
26+
display: flex;
27+
align-items: center;
28+
color: ${({ theme }) => theme.color.black};
29+
padding: ${({ theme }) => `${theme.padding.small} ${theme.padding.normal}`};
30+
white-space: nowrap;
31+
`
32+
33+
export const CurrentApp = styled.div<{
34+
color: string
35+
}>`
36+
border: 2px solid ${({ color }) => color};
37+
border-radius: 50%;
38+
background-color: #fff;
39+
width: 30px;
40+
height: 30px;
41+
display: flex;
42+
justify-content: center;
43+
align-items: center;
44+
cursor: pointer;
45+
font-size: ${({ theme }) => theme.fontSize.small};
46+
font-weight: bold;
47+
`
48+
49+
export const Overlay = styled.div`
50+
position: fixed;
51+
top: 0;
52+
left: 0;
53+
width: 100vw;
54+
height: 100vh;
55+
`
56+
57+
export const AppsList = styled.div`
58+
position: absolute;
59+
left: calc(100% + 1px);
60+
top: 0;
61+
background-color: #fff;
62+
border-right: 1px solid ${({ theme }) => theme.color.gray};
63+
border-bottom: 1px solid ${({ theme }) => theme.color.gray};
64+
`
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react'
2+
import { connect, Connect } from '../../app'
3+
import { getAppShortName, nameToColor } from '../../app/utils'
4+
import { Wrapper, App, CurrentApp, Overlay, AppsList } from './elements'
5+
6+
const Apps: React.SFC<Connect> = ({ app }) => (
7+
<Wrapper>
8+
<CurrentApp
9+
color={nameToColor(app.state.currentAppName)}
10+
onClick={app.actions.toggleShowApps}
11+
>
12+
{getAppShortName(app.state.currentAppName)}
13+
</CurrentApp>
14+
{app.state.showApps ? (
15+
<>
16+
<Overlay onClick={app.actions.toggleShowApps} />
17+
<AppsList>
18+
{Object.keys(app.state.apps).map((appName) => (
19+
<App
20+
key={appName}
21+
onClick={() => app.actions.selectApp(appName)}
22+
isSelected={app.state.currentAppName === appName}
23+
>
24+
{appName}
25+
</App>
26+
))}
27+
</AppsList>
28+
</>
29+
) : null}
30+
</Wrapper>
31+
)
32+
33+
export default connect(Apps)

packages/node_modules/overmind-devtools/src/components/AppsBar/elements.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/node_modules/overmind-devtools/src/components/AppsBar/index.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/node_modules/overmind-devtools/src/components/Devtools/elements.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export const Wrapper = styled.div`
66
justify-content: center;
77
height: 100%;
88
width: 100%;
9-
background-color: ${(props) => props.theme.color.dark};
10-
color: ${(props) => props.theme.color.white};
9+
background-color: ${(props) => props.theme.color.white};
10+
color: ${(props) => props.theme.color.black};
1111
flex-direction: column;
1212
`
1313

0 commit comments

Comments
 (0)