Skip to content

Commit e29bc87

Browse files
author
chenyunan
committed
modify select the final result's signal, delay render, some style
1 parent 6b35e3c commit e29bc87

File tree

6 files changed

+58
-32
lines changed

6 files changed

+58
-32
lines changed

app/commons/Search/action.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ function searchPattern() {
3333
}
3434

3535
function commonSearch() {
36-
if(!state.searched.end) {
36+
if(!state.searched.end && !state.ws.first) {
3737
api.searchInterrupt(state.searched.taskId);
3838
}
3939
if(state.searched.taskId != null) {
4040
state.searched.former.taskId = state.searched.taskId
4141
state.searched.former.results = state.searched.results.splice(0, state.searched.results.length);
4242
state.searched.taskId = ''
4343
}
44+
state.searched.taskId = ''
45+
state.searched.pattern = state.searching.isPattern
46+
state.searched.message = ''
47+
state.searched.end = false
4448
state.searched.randomKey = randomForOne()
4549
}
4650

app/commons/Search/state.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { observable } from 'mobx'
22

33
export const ws = observable({
44
name: '',
5-
status: false
5+
status: false,
6+
first: true
67
})
78

89
export const searching = observable({
@@ -20,7 +21,7 @@ export const searched = observable({
2021
pattern: false,
2122
message: '',
2223
results: [],
23-
end: true,
24+
end: false,
2425
former: {
2526
taskId: '',
2627
results: []

app/commons/Search/subscribeToSearch.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SearchSocketClient } from 'backendAPI/websocketClients'
33
import { autorun } from 'mobx'
44
import state from './state'
55
import * as api from 'backendAPI/searchAPI'
6+
import debounce from 'lodash/debounce'
67

78

89
export default function subscribeToSearch() {
@@ -75,26 +76,31 @@ export default function subscribeToSearch() {
7576
}
7677
if(result.randomKey === state.searched.randomKey) {
7778
state.searched.message = results.message;
78-
state.searched.end = true;
7979
}
8080
});
8181

8282
// end result
8383
client.subscribe('/user/topic/search/end', response => {
84-
let result = JSON.parse(response.body);
85-
if(result == null) {
86-
return ;
87-
}
88-
if(result.randomKey === state.searched.randomKey) {
89-
state.searched.end = true;
90-
}
84+
end(response)
9185
});
9286

9387
// modify workspace status to up and init workspace files in mem
9488
api.searchWorkspaceUp();
89+
9590
})
9691
}
9792

93+
// end
94+
const end = debounce((response) => {
95+
let result = JSON.parse(response.body);
96+
if(result == null) {
97+
return ;
98+
}
99+
if(result.randomKey === state.searched.randomKey) {
100+
state.searched.end = true;
101+
}
102+
}, 500)
103+
98104
function setData(result) {
99105
if(result.randomKey === state.searched.randomKey) {
100106
if(result.joinResultMessage) {
@@ -125,7 +131,7 @@ function editWsStatus(result, wsStatus) {
125131
break;
126132
}
127133
} else if(result.code == 1) {
128-
log(result.message);
134+
console.log(result.message);
129135
}
130136
}
131137

@@ -135,11 +141,14 @@ function formatSearch(response, isPattern) {
135141
return ;
136142
}
137143
if(result.randomKey && result.randomKey === state.searched.randomKey) {
138-
state.searched.taskId = result.taskId;
139-
state.searched.isPattern = isPattern;
140-
state.searched.message = '';
141-
state.searched.end = false;
142-
} else if(result.message) {
143-
log(result.message);
144+
if(result.message) {
145+
state.searched.message = result.message
146+
state.searched.end = true
147+
} else {
148+
state.searched.taskId = result.taskId;
149+
state.searched.isPattern = isPattern;
150+
state.searched.message = '';
151+
state.searched.end = false;
152+
}
144153
}
145154
}

app/components/Panel/PanelContent.jsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import FileTree from '../FileTree'
99
import SideBar from './SideBar/SideBar'
1010
import { SidePanelContainer, SidePanelView } from './SideBar/SidePanel'
1111
import FileList from '../Tab/fileList'
12-
import SearchPanel from '../Search/search'
13-
import SearchPanel2 from '../Search/search.new'
12+
import SearchPanel from '../Search/search.new'
1413
import config from '../../config'
1514
import PluginDev from 'components/PluginDev'
1615
import FileTreeToolBar from 'components/FileTreeToolBar'
@@ -58,11 +57,8 @@ const PanelContent = observer(({ panel }) => {
5857
<SidePanelView key='working' label={{ text: i18n`panel.left.working`, icon: 'fa fa-folder-open-o', weight: 1 }}>
5958
<FileList />
6059
</SidePanelView>
61-
{/* <SidePanelView key='find' label={{ text: i18n`panel.left.find`, icon: 'fa fa-search' }}>
60+
<SidePanelView key='find' label={{ text: i18n`panel.left.find`, icon: 'fa fa-search' }}>
6261
<SearchPanel />
63-
</SidePanelView> */}
64-
<SidePanelView key='find2' label={{ text: i18n`panel.left.find`, icon: 'fa fa-search' }}>
65-
<SearchPanel2 />
6662
</SidePanelView>
6763
</SidePanelContainer>
6864
)

app/components/Search/search.new.jsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class SearchResultItem extends Component {
6767
}
6868

6969
@observer
70-
class SearchPanel2 extends Component {
70+
class SearchPanel extends Component {
7171
componentDidMount () {
7272
subscribeToSearch()
7373
}
@@ -85,6 +85,9 @@ class SearchPanel2 extends Component {
8585
}
8686

8787
searchTxt = () => {
88+
if(state.ws.first) {
89+
state.ws.first = false
90+
}
8891
if(state.searching.isPattern) {
8992
delegate.searchPattern(state.searching);
9093
} else {
@@ -94,10 +97,11 @@ class SearchPanel2 extends Component {
9497

9598
renderResult () {
9699
let content = '';
97-
if (!state.searched.end) {
100+
if (state.ws.first) {
101+
content = ''
102+
} else if (!state.searched.end) {
98103
content = 'Searching...'
99-
} else if(state.searched.message != '') {
100-
// todo 这里的错误信息是否显示
104+
} else if(state.searched.message !== '') {
101105
content = state.searched.message;
102106
} else if (state.searched.results.length != 0) {
103107
const pattern = state.searching.pattern;
@@ -143,8 +147,10 @@ class SearchPanel2 extends Component {
143147
onKeyDown={this.onKeyDown}
144148
placeholder={i18n.get('panel.left.find')}
145149
/>
146-
147-
<input title={i18n.get('panel.checkbox.case')}
150+
</div>
151+
<div className='search-checkbox'>
152+
<input
153+
title={i18n.get('panel.checkbox.case')}
148154
label={i18n.get('panel.checkbox.case')}
149155
className='search-control-case-sensitive'
150156
onChange={this.caseSensitive}
@@ -181,4 +187,4 @@ class SearchPanel2 extends Component {
181187

182188
}
183189

184-
export default SearchPanel2;
190+
export default SearchPanel;

app/styles/core-ui/Search.styl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77
margin-bottom: 14px;
88
}
99
.search-panel-input {
10-
margin-bottom: 14px;
10+
margin-bottom: 14px;
11+
background-color: #1e1e1e
12+
border: 1px solid #333
13+
display: flex
14+
.search-controls {
15+
border: none
16+
}
17+
.search-checkbox {
18+
margin-right: inherit;
19+
position inherit;
20+
}
1121
}
1222
.search-item {
1323
cursor: pointer;

0 commit comments

Comments
 (0)