forked from Sacret/githubify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPage.js
More file actions
192 lines (180 loc) · 6.37 KB
/
MainPage.js
File metadata and controls
192 lines (180 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
'use strict';
import React from 'react';
import Reflux from 'reflux';
import Rebase from 're-base';
import moment from 'moment';
//
import { Grid, Row, Col } from 'react-bootstrap';
//
import ClearFiltersBlock from '../components/blocks/ClearFiltersBlock';
import EmptyUserBlock from '../components/blocks/EmptyUserBlock';
import FilterBlock from '../components/blocks/FilterBlock';
import LanguagesBlock from '../components/blocks/LanguagesBlock';
import LoadingBlock from '../components/blocks/LoadingBlock';
import LoginForm from '../components/blocks/LoginForm';
import ReposBlock from '../components/blocks/ReposBlock';
import SearchBlock from '../components/blocks/SearchBlock';
import TagsBlock from '../components/blocks/TagsBlock';
import UserBlock from '../components/blocks/UserBlock';
import UserMenu from '../components/menus/UserMenu';
import TagLimitModal from '../components/modals/TagLimitModal';
//
import FilterActions from '../actions/FilterActions';
import ReposActions from '../actions/ReposActions';
import UserActions from '../actions/UserActions';
//
import UserStore from '../stores/UserStore';
//
import Config from '../config/Config';
const base = Rebase.createClass(Config.FirebaseUrl);
/**
* Main page contains tags, filters and repos
*/
const MainPage = React.createClass({
mixins: [Reflux.connect(UserStore, 'userStore')],
componentDidMount() {
UserActions.isLoggedIn();
UserActions.getUser(this.props.params.uname);
//
const filter = this.props.location.query.filter || 'all';
ReposActions.getRepos(this.props.params.uname, 1, filter);
FilterActions.getFilters();
FilterActions.getDefaultFilters(this.props.location.query);
},
componentDidUpdate(prevProps, prevState) {
const userStore = prevState.userStore;
if (userStore && userStore.openUser && !this.state.tags) {
const userID = userStore.openUser.id;
this.ref = base.syncState('users/github:' + userID + '/tags', {
context: this,
state: 'tags',
asArray: true
});
}
},
componentWillUnmount() {
base.removeBinding(this.ref);
},
setFirebaseTagRepos(tagKey, newReposList) {
const userStore = this.state.userStore;
const userID = userStore.openUser.id;
base.post('users/github:' + userID + '/tags/' + tagKey, {
data: { repos: newReposList }
});
},
setFirebaseTags(tagKey) {
const userStore = this.state.userStore;
const userID = userStore.openUser.id;
base.post('users/github:' + userID + '/tags/' + tagKey, {
data: null
});
},
editTag(oldTagKey, newTagKey, tag, callback) {
const userStore = this.state.userStore;
const userID = userStore.openUser.id;
base.post('users/github:' + userID + '/tags/' + newTagKey, {
data: { repos: tag.repos },
then() {
base.post('users/github:' + userID + '/tags/' + oldTagKey, {
data: null,
then() {
callback();
}
});
}
});
},
render() {
const userStore = this.state.userStore;
//
return (
<Grid fluid={true}>
<Row>
<Col xs={12} md={12} className="content-block">
{
userStore && userStore.openUser ?
userStore.openUser.isActive ?
[
<Row className="user-info" key="block1">
<div className="container">
<Row>
<Col xs={6}>
<h2>GITHUBIFY.<span className="header-title">me</span></h2>
</Col>
<Col xs={6}>
<div className="pull-right logged-in-user">
<UserMenu
isLoggedIn={userStore.isLoggedIn}
info={userStore.info}
/>
</div>
</Col>
</Row>
<UserBlock
openUser={userStore.openUser}
/>
</div>
</Row>,
<Row className="tags-info" key="block2">
<div className="container">
<TagsBlock
uid={userStore.uid}
openUser={userStore.openUser}
isLoggedIn={userStore.isLoggedIn}
query={this.props.location.query}
tags={this.state.tags}
setFirebaseTags={this.setFirebaseTags}
editTag={this.editTag}
/>
</div>
</Row>,
<Row className="languages-info" key="block3">
<div className="container">
<LanguagesBlock />
</div>
</Row>,
<Row className="filters-info" key="block4">
<div className="container">
<FilterBlock
uname={this.props.params.uname}
/>
</div>
</Row>,
<Row className="search-info" key="block5">
<div className="container">
<SearchBlock />
</div>
</Row>,
<Row className="clear-info" key="block6">
<div className="container">
<ClearFiltersBlock
uname={this.props.params.uname}
/>
</div>
</Row>,
<Row className="repos-info" key="block7">
<div className="container">
<ReposBlock
uid={userStore.uid}
openUser={userStore.openUser}
isLoggedIn={userStore.isLoggedIn}
tags={this.state.tags}
setFirebaseTagRepos={this.setFirebaseTagRepos}
/>
</div>
</Row>
] :
<EmptyUserBlock
info={userStore.info}
uname={this.props.params.uname}
/> :
<LoadingBlock />
}
<TagLimitModal />
</Col>
</Row>
</Grid>
);
}
});
export default MainPage;