Skip to content

Commit 7da3616

Browse files
committed
🔨 Switch Badges to use useOvermind
1 parent 4534009 commit 7da3616

File tree

2 files changed

+20
-22
lines changed
  • packages/app/src/app

2 files changed

+20
-22
lines changed

‎packages/app/src/app/overmind/namespaces/preferences/actions.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { Badge } from '@codesandbox/common/lib/types';
2+
import { json } from 'overmind';
3+
14
import { Action, AsyncAction } from 'app/overmind';
25
import { setVimExtensionEnabled } from 'app/vscode/initializers';
3-
import { json } from 'overmind';
46

57
export const viewModeChanged: Action<{
68
showEditor: boolean;
@@ -59,13 +61,11 @@ export const settingChanged: Action<{
5961
});
6062
};
6163

62-
export const setBadgeVisibility: AsyncAction<{
63-
id: string;
64-
visible: boolean;
65-
}> = async ({ state, effects }, { id, visible }) => {
66-
const { badges } = state.user;
67-
68-
badges.forEach((badge, index) => {
64+
export const setBadgeVisibility: AsyncAction<Pick<
65+
Badge,
66+
'id' | 'visible'
67+
>> = async ({ effects, state }, { id, visible }) => {
68+
state.user.badges.forEach((badge, index) => {
6969
if (badge.id === id) {
7070
state.user.badges[index].visible = visible;
7171
}

‎packages/app/src/app/pages/common/Modals/PreferencesModal/Badges/index.tsx‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,35 @@ import { Title } from '../elements';
88

99
export const Badges: FunctionComponent = () => {
1010
const {
11-
state: {
12-
user: { badges },
13-
},
1411
actions: {
1512
preferences: { setBadgeVisibility },
1613
},
14+
state: {
15+
user: { badges },
16+
},
1717
} = useOvermind();
18-
const badgesCount = badges.length;
1918

2019
return (
2120
<div>
2221
<Title>Badges</Title>
22+
2323
<strong>
24-
You currently have {badgesCount} badge
25-
{badgesCount === 1 ? '' : 's'}. You can click on the badges to toggle
24+
You currently have {badges.length} badge
25+
{badges.length === 1 ? '' : 's'}. You can click on the badges to toggle
2626
visibility.
2727
</strong>
28+
2829
<Margin top={2}>
2930
{badges.map(badge => (
3031
<Badge
32+
badge={badge}
33+
onClick={({ id, visible }) =>
34+
setBadgeVisibility({ id, visible: !visible })
35+
}
3136
key={badge.id}
37+
size={128}
3238
tooltip={false}
33-
onClick={b =>
34-
setBadgeVisibility({
35-
...b,
36-
visible: !b.visible,
37-
})
38-
}
39-
badge={badge}
4039
visible={badge.visible}
41-
size={128}
4240
/>
4341
))}
4442
</Margin>

0 commit comments

Comments
 (0)