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

Commit 7c8fb58

Browse files
committed
cleanup githubStore && add 'Repo not found' && R refactor
1 parent 1b65f20 commit 7c8fb58

File tree

4 files changed

+65
-16
lines changed

4 files changed

+65
-16
lines changed

containers/UniversePanel/Modal.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ export const EditorBar = styled(BaseBar)`
3535
position: relative;
3636
left: -50%;
3737
`
38+
export const AlertBar = styled(BaseBar)`
39+
position: relative;
40+
padding: 18px;
41+
left: -50%;
42+
color: #365760;
43+
&:before {
44+
content: '⚠ ';
45+
margin-right: 10px;
46+
color: tomato;
47+
}
48+
`
49+
3850
export const InfoBar = styled(BaseBar)`
3951
padding: 10px;
4052
min-height: 100px;

containers/UniversePanel/index.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
EditorBar,
2121
Wraper,
2222
InputBar,
23+
AlertBar,
2324
AddOn,
2425
AvatarImg,
2526
AvatarWrapper,
@@ -33,19 +34,20 @@ import {
3334

3435
const debug = makeDebugger('C:UniversePanel')
3536

36-
function inputChange(e) {
37-
logic.search(e.target.value)
38-
}
37+
// R.isEmpty(repos.toJSON()) && !isSearching && !R.isEmpty(inputValue)
38+
39+
// const repoNotFound = R.and()
3940

40-
const SearchEditor = () => (
41+
const SearchEditor = ({ value }) => (
4142
<EditorBar>
4243
<AddOn>&#9906;</AddOn>
4344
<InputBar
4445
spellCheck={false}
4546
autoCapitalize={false}
4647
autoCorrect="off"
4748
autoComplete="off"
48-
onChange={inputChange}
49+
value={value}
50+
onChange={logic.search}
4951
/>
5052
</EditorBar>
5153
)
@@ -62,14 +64,21 @@ class UniversePanelContainer extends React.Component {
6264
}
6365

6466
render() {
65-
const repos = this.props.store.githubRepos
66-
debug('repos: ', repos.toJSON())
67+
const store = this.props.store
68+
const { reposData, inputValue } = store
69+
70+
// debug('repos: ', repos)
71+
// debug('searching: ', searching)
72+
// debug('logic.repoNotFound2(store): ', logic.repoNotFound2(store))
6773

6874
return (
6975
<PanelContainer>
70-
<SearchEditor />
76+
<SearchEditor value={inputValue} />
77+
78+
{logic.repoNotFound(store) && <AlertBar>Repo not found</AlertBar>}
79+
7180
<Wraper>
72-
{repos.map(repo => (
81+
{reposData.map(repo => (
7382
<InfoBar key={repo.id}>
7483
<AvatarWrapper onClick={logic.watshData}>
7584
<AvatarImg src={repo.owner.avatar_url} alt="repo avatar" />

containers/UniversePanel/logic.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,51 @@ const repoData = R.map(
1212
R.pick(['id', 'name', 'description', 'language', 'owner', 'stargazers_count'])
1313
)
1414

15-
export function watshData() {
16-
debug('watshData')
15+
// const RLog = x => debug('R log: ', x)
16+
17+
const reposIsEmpty = R.compose(R.isEmpty, R.prop('reposData'))
18+
const inputValueIsNotEmpty = R.compose(R.not, R.isEmpty, R.prop('inputValue'))
19+
const isNotSearching = R.compose(R.not, R.prop('searching'))
20+
21+
export const repoNotFound = R.allPass([
22+
reposIsEmpty,
23+
inputValueIsNotEmpty,
24+
isNotSearching,
25+
])
26+
27+
/*
28+
export function repoNotFound() {
29+
return (
30+
R.isEmpty(store.reposData) &&
31+
!store.searching &&
32+
!R.isEmpty(store.inputValue)
33+
)
1734
}
35+
*/
1836

19-
export function search(val) {
37+
export function search(e) {
2038
// console.log('search: ', val)
21-
Pigeon.search(val)
39+
const value = e.target.value
40+
store.markState('inputValue', value)
41+
store.markState('searching', true)
42+
Pigeon.search(value)
2243
}
2344

2445
export function init(selectedStore) {
25-
debug('store', store)
2646
store = selectedStore
47+
debug('store', store)
2748
Pigeon = new SearchService()
2849

2950
Pigeon.get().subscribe(res => {
3051
debug('Pigeon get: ', res)
3152
// debug('washed: ', repoData(res.items))
53+
store.markState('searching', false)
3254
store.replaceRepos(repoData(res.items))
3355
})
3456

3557
Pigeon.emptyInput().subscribe(() => {
3658
debug('Pigeon get emptyInput!')
59+
store.markState('searching', false)
3760
store.clearRepos()
3861
})
3962
}

stores/GithubEampleStore/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ const Repo = t.model('Repo', {
2626
const GithubEampleStore = t
2727
.model('GithubEampleStore', {
2828
repos: t.optional(t.array(Repo), []),
29+
inputValue: t.optional(t.string, ''),
30+
searching: t.optional(t.boolean, false),
2931
})
3032
.views(self => ({
3133
get app() {
3234
return getParent(self)
3335
},
34-
get githubRepos() {
35-
return self.repos
36+
get reposData() {
37+
return self.repos.toJSON()
3638
},
3739
}))
3840
.actions(self => ({
@@ -43,6 +45,9 @@ const GithubEampleStore = t
4345
clearRepos() {
4446
self.repos = []
4547
},
48+
markState(key, val) {
49+
self[key] = val
50+
},
4651
}))
4752

4853
export default GithubEampleStore

0 commit comments

Comments
 (0)