Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 0ec04af

Browse files
committed
[new svg loader] load svg from dir && refactor file/code structures
1 parent 6ddb5e0 commit 0ec04af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+229
-364
lines changed

containers/Body/index.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import keydown from 'react-keydown'
1111
// import Link from 'next/link'
1212
import { Button } from '../../components'
1313

14-
import { storeSelector } from '../../utils/functions'
15-
16-
import * as SuggestionIcons from '../Doraemon/styles/suggestionIcons'
14+
import { storeSelector, getSVGIconPath } from '../../utils/functions'
1715
import * as logic from './logic'
1816

1917
import {
@@ -28,11 +26,9 @@ import {
2826
NotificationIcon,
2927
User,
3028
UserIcon,
31-
AddonSVGIconWrapper,
29+
BannerLogo,
3230
} from './styles'
3331

34-
const Icons = { ...SuggestionIcons }
35-
3632
const AppHeader = () => {
3733
return (
3834
<Header>
@@ -56,16 +52,12 @@ const AppHeader = () => {
5652
const AppBanner = ({ curUrlPath }) => {
5753
const defaultIcon = 'js'
5854
const iconKey = curUrlPath === '/' ? defaultIcon : curUrlPath
59-
6055
// debug('AppBanner curUrlPath: ', curUrlPath)
6156
// debug('iconKey: ', iconKey)
6257

63-
const Icon = Icons[iconKey]
6458
return (
6559
<Banner>
66-
<AddonSVGIconWrapper>
67-
<Icon />
68-
</AddonSVGIconWrapper>
60+
<BannerLogo path={getSVGIconPath(iconKey)} />
6961
</Banner>
7062
)
7163
}

containers/Body/styles/index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import styled from 'styled-components'
2+
import ReactSVG from 'react-svg'
23

34
import { theme } from '../../../utils/themes'
45

@@ -71,7 +72,6 @@ export const Banner = styled.div`
7172
height: 15vh;
7273
border-bottom: 1px solid tomato;
7374
`
74-
7575
export const Button = styled.button`
7676
font-size: 1em;
7777
margin: 1em;
@@ -87,11 +87,8 @@ export const Button = styled.button`
8787
outline: 0;
8888
}
8989
`
90-
91-
export const AddonSVGIconWrapper = styled.div`
92-
> svg {
93-
width: 80px;
94-
height: 80px;
95-
margin-top: 20px;
96-
}
90+
export const BannerLogo = styled(ReactSVG)`
91+
margin-top: 2em;
92+
width: 100px;
93+
height: 100px;
9794
`

containers/Doraemon/InputEditor.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,33 @@
77
import React from 'react'
88
import keydown from 'react-keydown'
99

10-
// import { makeDebugger } from '../../utils/functions'
10+
import { getSVGIconPath } from '../../utils/functions'
1111
import * as logic from './logic'
1212

1313
import {
1414
EditorBar,
1515
InputBar,
1616
AddOn,
1717
LoadingIcon,
18-
AddonSVGIconWrapper,
18+
PrefixSVGIcon,
19+
PrefixSearchIcon,
20+
PrefixMagicIcon,
1921
} from './styles'
2022

21-
import * as SuggestionIcons from './styles/suggestionIcons'
22-
23-
const allIcons = { ...SuggestionIcons }
24-
const defaultIcon = SuggestionIcons.search
25-
26-
// import { theme, magic, search } from './styles/suggestionIcons'
2723
// const debug = makeDebugger('C:Doraemon:InputEditor')
2824

2925
const PrefixIcon = ({ prefix }) => {
30-
let Icon
31-
if (prefix === '/') {
32-
Icon = SuggestionIcons.magic
33-
} else {
34-
Icon = allIcons[prefix] ? allIcons[prefix] : defaultIcon
26+
switch (prefix) {
27+
case '': {
28+
return <PrefixSearchIcon path={getSVGIconPath('search')} />
29+
}
30+
case '/': {
31+
return <PrefixMagicIcon path={getSVGIconPath('magic')} />
32+
}
33+
default: {
34+
return <PrefixSVGIcon path={getSVGIconPath(prefix)} />
35+
}
3536
}
36-
37-
return (
38-
<AddonSVGIconWrapper>
39-
<Icon />
40-
</AddonSVGIconWrapper>
41-
)
4237
}
4338

4439
export default class InputEditor extends React.Component {

containers/Doraemon/NodeIcon.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,31 @@
66
import React from 'react'
77
import R from 'ramda'
88

9-
import { SVGIconWrapper } from './styles'
10-
import * as SuggestionIcons from './styles/suggestionIcons'
11-
// import { makeDebugger } from '../../utils/functions'
12-
9+
import { getSVGIconPath } from '../../utils/functions'
10+
import { NodeSVGIcon, ThemeDot } from './styles'
1311
import { themeColorMap } from '../../utils/themes/'
1412

15-
const Icons = { ...SuggestionIcons }
16-
const DefaultIcon = SuggestionIcons.javascript
17-
1813
// const debug = makeDebugger('C:Doraemon:NodeIcon')
1914

2015
const getIconKey = R.compose(R.last, R.split('--'), R.toLower)
2116

2217
// sucks need refactor
2318
const NodeIcon = ({ raw }) => {
2419
const lowerRaw = R.toLower(raw)
25-
2620
const iconKey = getIconKey(lowerRaw)
21+
let specialStyle = {}
22+
2723
if (R.startsWith('themes--', lowerRaw)) {
28-
return <Icons.themeDot bg={themeColorMap[iconKey]} />
29-
} else if (iconKey === 'hforward') {
30-
return <Icons.forward />
24+
return <ThemeDot bg={themeColorMap[iconKey]} />
3125
} else if (iconKey === 'hbackward') {
32-
return <Icons.backward />
33-
} else if (iconKey === 'question') {
34-
return <Icons.question />
26+
return <NodeSVGIcon reverse path={getSVGIconPath('forward')} />
27+
} else if (iconKey === 'write') {
28+
specialStyle = { width: '70%', marginLeft: 5 }
29+
} else if (iconKey === 'login') {
30+
specialStyle = { width: '70%', marginLeft: 5 }
3531
}
36-
const Icon = Icons[iconKey] ? Icons[iconKey] : DefaultIcon
37-
return (
38-
<SVGIconWrapper>
39-
<Icon />
40-
</SVGIconWrapper>
41-
)
32+
33+
return <NodeSVGIcon path={getSVGIconPath(iconKey)} style={specialStyle} />
4234
}
4335

4436
export default NodeIcon

containers/Doraemon/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import { inject, observer } from 'mobx-react'
1010
// import Link from 'next/link'
1111
// import styled from 'styled-components'
1212

13-
import { makeDebugger, storeSelector } from '../../utils/functions'
13+
import {
14+
makeDebugger,
15+
storeSelector,
16+
getSVGIconPath,
17+
} from '../../utils/functions'
1418

1519
import InputEditor from './InputEditor'
1620
import NodeIcon from './NodeIcon'
1721
import * as logic from './logic'
1822

19-
import * as SuggestionIcons from './styles/suggestionIcons'
20-
2123
import {
2224
PageOverlay,
2325
PanelContainer,
@@ -37,9 +39,7 @@ const debug = makeDebugger('C:Doraemon')
3739

3840
const HintIcon = ({ index, active, cur }) => {
3941
return active === cur ? (
40-
<HintEnter>
41-
<SuggestionIcons.enter />
42-
</HintEnter>
42+
<HintEnter path={getSVGIconPath('enter')} />
4343
) : (
4444
<Hint>^ {index}</Hint>
4545
)

containers/Doraemon/logic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const initCmdResolver = () => {
9292
debug('communityLinker: ', cmdpath)
9393

9494
// Router.push(url, as)
95+
// TODO: use route store method
9596
Router.push(
9697
{
9798
pathname: '/',
@@ -113,8 +114,7 @@ const initCmdResolver = () => {
113114

114115
const doCmd = () => {
115116
const cmd = clearfyCmd(doraemon.activeRaw)
116-
// debug('clearfyCmd: ', cmd)
117-
// Do not use forEach, cause forEach will not break
117+
/* Do not use forEach, cause forEach will not break */
118118
for (let i = 0; i < cmdResolver.length; i += 1) {
119119
if (cmdResolver[i].match(cmd)) {
120120
return cmdResolver[i].action(cmd)

containers/Doraemon/styles/index.js

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import styled, { keyframes } from 'styled-components'
2-
import { theme } from '../../../utils/themes'
2+
import ReactSVG from 'react-svg'
33

4+
import { theme } from '../../../utils/themes'
45
import { Img } from '../../../components'
5-
66
import loadingIcon from '../../../static/searchLoading.svg'
77

8-
// import javascriptIcon from '../../../static/nodeIcons/javascript.svg'
9-
10-
// import * as SuggestionIcons from './suggestionIcons'
11-
export * from './suggestionIcons'
12-
138
const rotate360 = keyframes`
149
from {
1510
transform: rotate(0deg);
@@ -155,11 +150,16 @@ export const Hint = styled.div`
155150
margin-top: 10px;
156151
margin-right: 15px;
157152
width: 30px;
153+
font-size: 1.1rem;
158154
`
159-
export const HintEnter = styled.div`
155+
export const HintEnter = styled(ReactSVG)`
160156
color: ${theme('u_panel.text')};
161157
margin-top: 10px;
162-
margin-right: 10px;
158+
margin-right: 1.5em;
159+
width: 30px;
160+
height: 30px;
161+
transform: rotateX(180deg);
162+
fill: ${theme('u_panel.text')};
163163
`
164164

165165
export const SubInfoWraper = styled.div`
@@ -178,22 +178,38 @@ export const RepoStar = styled.div`
178178
margin-right: 10px;
179179
`
180180

181-
export const ImgIconWrapper = styled(Img)`
181+
export const NodeSVGIcon = styled(ReactSVG)`
182182
width: 40px;
183183
height: 40px;
184+
margin-top: 3px;
185+
transform: ${props => (props.reverse ? 'rotate(180deg)' : '')};
184186
`
185187

186-
export const SVGIconWrapper = styled.div`
187-
> svg {
188-
width: 40px;
189-
height: 40px;
190-
margin-top: 3px;
191-
}
188+
export const ThemeDot = styled.div`
189+
width: 35px;
190+
height: 35px;
191+
margin-top: 5px;
192+
background: ${props => props.bg};
193+
border-radius: 50%;
192194
`
193-
export const AddonSVGIconWrapper = styled.div`
194-
> svg {
195-
width: 30px;
196-
height: 30px;
197-
margin-top: 20px;
198-
}
195+
196+
// TODO: rename -> PrefixIcon
197+
export const PrefixSVGIcon = styled(ReactSVG)`
198+
width: 30px;
199+
height: 30px;
200+
margin-top: 20px;
201+
`
202+
203+
export const PrefixSearchIcon = styled(ReactSVG)`
204+
width: 30px;
205+
height: 30px;
206+
margin-top: 20px;
207+
fill: ${theme('u_panel.search_icon')};
208+
`
209+
210+
export const PrefixMagicIcon = styled(ReactSVG)`
211+
width: 30px;
212+
height: 25px;
213+
margin-top: 20px;
214+
transform: rotate(-30deg);
199215
`

0 commit comments

Comments
 (0)