Skip to content

Commit 197f98e

Browse files
docs(website): improve view selector
1 parent cc95481 commit 197f98e

File tree

8 files changed

+43
-48
lines changed

8 files changed

+43
-48
lines changed

packages/overmind-website/examples/guide/getstarted/actions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export const loadPosts: Action = async ({ state, jsonPlaceholder }) => {
2121
view,
2222
`
2323
import { state } from './state'
24+
import * as effects from './effects'
2425
import * as actions from './actions'
2526
2627
const config = {
2728
state,
29+
effects,
2830
actions
2931
}
3032
`
@@ -43,6 +45,12 @@ export const overmind = new Overmind({
4345
isLoadingPosts: false,
4446
posts: []
4547
},
48+
effects: {
49+
getPosts() {
50+
return fetch('https://jsonplaceholder.typicode.com/posts')
51+
.then(response => response.json())
52+
}
53+
},
4654
actions: {
4755
loadPosts: async ({ state, jsonPlaceholder }) => {
4856
state.isLoadingPosts = true

packages/overmind-website/examples/guide/getstarted/effects.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ export const jsonPlaceholder = {
2222
view,
2323
`
2424
import state from './state'
25-
import * as actions from './actions'
2625
import * as effects from './effects'
2726
2827
const config = {
2928
state,
30-
actions,
3129
effects
3230
}
3331
`
@@ -46,13 +44,6 @@ export const overmind = new Overmind({
4644
isLoadingPosts: false,
4745
posts: []
4846
},
49-
actions: {
50-
loadPosts: async ({ state, jsonPlaceholder }) => {
51-
state.isLoadingPosts = true
52-
state.posts = await jsonPlaceholder.getPosts()
53-
state.isLoadingPosts = false
54-
}
55-
},
5647
effects: {
5748
getPosts() {
5849
return fetch('https://jsonplaceholder.typicode.com/posts')

packages/overmind-website/guides/beginner/01_getstarted.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,20 @@ h(Example, { name: "guide/getstarted/connectapp" })
3636

3737
That is it, your component will now render whenever the state accessed changes.
3838

39-
## Loading posts
39+
## Effects
4040

41-
We want to load some posts from [jsonplaceholder](https://jsonplaceholder.typicode.com/) when the **Posts** component mounts. To run logic in Overmind you trigger **actions**. Let us define an action that is responsible for getting our application up and running.
41+
We want to load some posts from [jsonplaceholder](https://jsonplaceholder.typicode.com/) when the **Posts** component mounts. This requires a side effect and we can expose any kind of side effects to our Overmind instance. Think of it as injecting libraries and tools. For example, it could be the [axios](https://www.npmjs.com/package/axios) library itself, some class instance we created or just a plain object as we see in the example below. Doing this injection keeps our logic pure and Overmind knows when these injected libraries are accessed, giving you a better developer experience.
4242

4343
```marksy
44-
h(Example, { name: "guide/getstarted/actions" })
44+
h(Example, { name: "guide/getstarted/effects" })
4545
```
4646

47-
Let us see how we define this effect called **jsonPlaceholder**.
47+
## Loading the posts
4848

49-
## Effects
50-
51-
We can expose any kind of side effects to our Overmind instance. Think of it as injecting libraries and tools. For example, it could be the [axios](https://www.npmjs.com/package/axios) library itself, some class instance we created or just a plain object as we see in the example below. Doing this injection keeps our actions pure and Overmind knows when these injected libraries are accessed.
49+
To run logic in Overmind you trigger **actions**. Let us define an action that is responsible for getting our application up and running.
5250

5351
```marksy
54-
h(Example, { name: "guide/getstarted/effects" })
52+
h(Example, { name: "guide/getstarted/actions" })
5553
```
5654

5755
Finally we need to trigger our action and we will do that when the component mounts.

packages/overmind-website/src/components/ViewSelector/index.tsx

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as ReactImage from '../../images/react.png'
44
import * as VueImage from '../../images/vue.png'
55
import * as AngularImage from '../../images/angular.png'
66
import * as TsImage from '../../images/ts.png'
7-
import * as TsImageGrayscale from '../../images/ts-grayscale.png'
7+
import * as JsImage from '../../images/js.png'
88
import Icon from '../Icon'
99
import * as styles from './styles'
1010
import { css } from 'emotion'
@@ -25,49 +25,44 @@ const ViewSelector: SFC = () => {
2525
}
2626

2727
const options = {
28+
vue: (
29+
<div className={styles.viewOption}>
30+
<img src={VueImage} width={25} />
31+
Vue
32+
<img className={styles.image} src={JsImage} width="20" height="20" />
33+
</div>
34+
),
2835
react: (
2936
<div className={styles.viewOption}>
3037
<img src={ReactImage} width={25} />
3138
React
39+
<img className={styles.image} src={JsImage} width="20" height="20" />
3240
</div>
3341
),
34-
vue: (
42+
react_ts: (
3543
<div className={styles.viewOption}>
36-
<img src={VueImage} width={25} />
37-
Vue
44+
<img src={ReactImage} width={25} />
45+
React
46+
<img className={styles.image} src={TsImage} width="20" height="20" />
3847
</div>
3948
),
40-
angular: (
49+
angular_ts: (
4150
<div className={styles.viewOption}>
4251
<img src={AngularImage} width={25} />
4352
Angular
53+
<img className={styles.image} src={TsImage} width="20" height="20" />
4454
</div>
4555
),
4656
}
4757

4858
return (
4959
<div className={styles.wrapper}>
50-
<div
51-
className={styles.tsImageWrapper}
52-
onClick={state.showViewHelp ? null : actions.toggleTypescript}
53-
>
54-
{state.typescript ? (
55-
<img className={styles.image} src={TsImage} width="20" height="20" />
56-
) : (
57-
<img
58-
className={css(styles.image, styles.grayscale)}
59-
src={TsImageGrayscale}
60-
width="20"
61-
height="20"
62-
/>
63-
)}
64-
</div>
6560
<div
6661
ref={selectorRef}
6762
onClick={state.showViewHelp ? null : onSelectorClick}
6863
className={css(styles.selector, isOpen && styles.selectorOpen)}
6964
>
70-
{options[state.theme]}
65+
{options[state.theme + (state.typescript ? '_ts' : '')]}
7166
<span className={styles.chevron}>
7267
<Icon>chevron-down</Icon>
7368
</span>

packages/overmind-website/src/components/ViewSelector/styles.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ export const wrapper = css`
1010
export const viewOption = css`
1111
display: flex;
1212
align-items: center;
13-
`
14-
15-
export const tsImageWrapper = css`
16-
display: flex;
17-
padding: 4px;
18-
align-items: center;
19-
border-top-left-radius: var(--border-radius-1);
20-
border-bottom-left-radius: var(--border-radius-1);
13+
width: 100%;
14+
img:last-child {
15+
margin-left: auto;
16+
}
2117
`
2218

2319
export const image = css`
@@ -59,7 +55,7 @@ export const selectorOpen = css`
5955
`
6056

6157
export const chevron = css`
62-
margin-left: auto;
58+
margin-left: 5px;
6359
font-size: var(--font-size-1);
6460
`
6561

1.92 KB
Loading
-3.03 KB
Binary file not shown.

packages/overmind-website/src/overmind/actions.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,21 @@ export const openApi: Action<RouteContext<VideoParams>> = async ({
5858
}
5959

6060
export const selectTheme: Action<string> = ({
61-
value: theme,
61+
value: selection,
6262
state,
6363
css,
6464
storage,
6565
}) => {
66+
const selectionArray = selection.split('_')
67+
const theme = selectionArray[0]
68+
const typescript = Boolean(selectionArray[1])
69+
6670
state.theme = theme
71+
state.typescript = typescript
72+
6773
css.changePrimary(theme)
6874
storage.set('theme', theme)
75+
storage.set('typescript', typescript)
6976
}
7077

7178
export const toggleTypescript: Action = ({ state, storage }) => {

0 commit comments

Comments
 (0)