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

Commit a3039f0

Browse files
committed
Merge branch 'hight-words' into dev
2 parents 0b10d41 + e60c8e4 commit a3039f0

File tree

18 files changed

+206
-60
lines changed

18 files changed

+206
-60
lines changed

containers/Doraemon/ResultsList.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import R from 'ramda'
3+
import Highlighter from 'react-highlight-words'
34

45
import { ICON_CMD } from 'config'
56

@@ -29,7 +30,7 @@ const HintIcon = ({ index, active, cur, length }) => {
2930
return null
3031
}
3132

32-
const ResultsList = ({ searchThread, suggestions, activeRaw }) => (
33+
const ResultsList = ({ searchValue, searchThread, suggestions, activeRaw }) => (
3334
<Wrapper>
3435
<SuggestionWrapper empty={suggestions.length === 0}>
3536
{suggestions.map((suggestion, i) => (
@@ -47,7 +48,14 @@ const ResultsList = ({ searchThread, suggestions, activeRaw }) => (
4748
searchThread={searchThread}
4849
/>
4950
<ContentWraper>
50-
<Title>{suggestion.title}</Title>
51+
<Title>
52+
<Highlighter
53+
highlightClassName="doramon-search-highlighter"
54+
searchWords={[searchValue]}
55+
autoEscape
56+
textToHighlight={suggestion.title}
57+
/>
58+
</Title>
5159
<Desc>{suggestion.desc}</Desc>
5260
</ContentWraper>
5361
<HintIcon

containers/Doraemon/ThreadSelectBar.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import React from 'react'
22

33
// import { ICON_CMD } from 'config'
44
import { THREAD } from 'utils'
5-
import { Wrapper, Selector } from './styles/thread_select_bar'
5+
import {
6+
Wrapper,
7+
Selector,
8+
VideoSelector,
9+
RepoSelector,
10+
} from './styles/thread_select_bar'
611
import { searchThreadOnChange } from './logic'
712

813
const ThreadSelectBar = ({ active }) => (
@@ -19,18 +24,18 @@ const ThreadSelectBar = ({ active }) => (
1924
>
2025
帖子
2126
</Selector>
22-
<Selector
27+
<VideoSelector
2328
onClick={searchThreadOnChange.bind(this, THREAD.VIDEO)}
2429
active={active === THREAD.VIDEO}
2530
>
2631
视频
27-
</Selector>
28-
<Selector
32+
</VideoSelector>
33+
<RepoSelector
2934
onClick={searchThreadOnChange.bind(this, THREAD.REPO)}
3035
active={active === THREAD.REPO}
3136
>
3237
项目
33-
</Selector>
38+
</RepoSelector>
3439
<Selector
3540
onClick={searchThreadOnChange.bind(this, THREAD.JOB)}
3641
active={active === THREAD.JOB}

containers/Doraemon/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class DoraemonContainer extends React.Component {
3535
const { doraemon } = this.props
3636
const {
3737
inputValue,
38+
inputValueRaw,
3839
suggestions,
3940
activeRaw,
4041
prefix,
@@ -64,6 +65,7 @@ class DoraemonContainer extends React.Component {
6465
<AlertBar value={inputValue} searchThread={searchThread} />
6566
)}
6667
<ResultsList
68+
searchValue={inputValueRaw}
6769
suggestions={suggestions}
6870
activeRaw={activeRaw}
6971
searchThread={searchThread}

containers/Doraemon/store.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ const DoraemonStore = t
7979
get curRoute() {
8080
return self.root.curRoute
8181
},
82+
get inputValueRaw() {
83+
if (R.startsWith('/', self.inputValue)) {
84+
return R.last(self.inputValue.split('/'))
85+
}
86+
if (R.startsWith('@', self.inputValue)) return self.inputValue.slice(1)
87+
88+
return self.inputValue
89+
},
8290
get curCmdChain() {
8391
if (!self.cmdChain && self.activeRaw) {
8492
return [self.activeRaw]

containers/Doraemon/styles/results_list.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ export const Title = styled.div`
112112
> a {
113113
color: ${theme('shell.link')};
114114
}
115+
116+
${cs.truncate('400px')};
117+
${cs.media.mobile`
118+
${cs.truncate('200px')};
119+
`};
115120
`
116121
export const Desc = styled.div`
117122
color: ${theme('shell.desc')};

containers/Doraemon/styles/thread_select_bar.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ export const Selector = styled.div`
2727
}
2828
`
2929

30+
export const VideoSelector = styled(Selector)`
31+
${cs.media.mobile`display: none;`};
32+
`
33+
export const RepoSelector = styled(Selector)`
34+
${cs.media.mobile`display: none;`};
35+
`
36+
3037
export const Info = styled.div`
3138
${cs.flexGrow()};
3239
`

containers/ThemeWrapper/GlobalStyle.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const GlobalStyle = createGlobalStyle`
1818
body {
1919
${cs.media.mobile`
2020
position: relative;
21-
`};
21+
`};
2222
}
2323
*::-moz-selection {
2424
background-color: ${theme('selectionBg')} !important;
@@ -132,6 +132,12 @@ const GlobalStyle = createGlobalStyle`
132132
text-decoration: underline;
133133
}
134134
}
135+
136+
.doramon-search-highlighter {
137+
background-color: ${theme('searchHighlight.doramonBg')};
138+
padding: 0 1px;
139+
color: ${theme('searchHighlight.doramonFg')};
140+
}
135141
`
136142

137143
export default GlobalStyle

package-docker.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"react-calendar-heatmap": "^1.6.3",
6060
"react-content-loader": "3.1.2",
6161
"react-dom": "16.6.0",
62+
"react-highlight-words": "^0.16.0",
6263
"react-intl": "2.4.0",
6364
"react-json-view": "1.19.1",
6465
"react-keydown": "1.9.7",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"react-calendar-heatmap": "^1.6.3",
100100
"react-content-loader": "3.1.2",
101101
"react-dom": "16.6.0",
102+
"react-highlight-words": "^0.16.0",
102103
"react-intl": "2.4.0",
103104
"react-json-view": "1.19.1",
104105
"react-keydown": "1.9.7",

utils/themes/skins/cyan.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ const cyan = {
313313
border: '#e8e8e8',
314314
hoverBg: '#fffef1',
315315
},
316+
searchHighlight: {
317+
doramonFg: '#F6DE38',
318+
doramonBg: 'transparent',
319+
},
316320
}
317321

318322
export default cyan

0 commit comments

Comments
 (0)