Skip to content

Commit 864001b

Browse files
committed
cleanup redirecting
1 parent bd2816b commit 864001b

2 files changed

Lines changed: 18 additions & 36 deletions

File tree

browser/main/Components/PlanetArticleDetail.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ var PlanetArticleDetail = React.createClass({
2020
},
2121
render: function () {
2222
var article = this.props.article
23-
23+
if (article == null) {
24+
return (
25+
<div className='PlanetArticleDetail'>
26+
Nothing selected
27+
</div>
28+
)
29+
}
2430
var tags = article.Tags.length > 0 ? article.Tags.map(function (tag) {
2531
return (
2632
<a key={tag.id} href>#{tag.name}</a>

browser/main/Containers/PlanetContainer.jsx

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ module.exports = React.createClass({
5555
getInitialState: function () {
5656
return {
5757
currentPlanet: null,
58-
filteredArticles: [],
5958
search: '',
6059
isFetched: false
6160
}
@@ -136,16 +135,16 @@ module.exports = React.createClass({
136135
}
137136
},
138137
selectNextArticle: function () {
139-
if (this.state.currentPlanet == null || this.state.filteredArticles.length === 0) return
138+
if (this.state.currentPlanet == null) return
140139

141140
var index = this.getFilteredIndexOfCurrentArticle()
142141

143-
if (index < this.state.filteredArticles.length - 1) {
142+
if (index < this.refs.list.props.articles.length - 1) {
144143
this.selectArticleByIndex(index + 1)
145144
}
146145
},
147146
selectPriorArticle: function () {
148-
if (this.state.currentPlanet == null || this.state.filteredArticles.length === 0) {
147+
if (this.state.currentPlanet == null) {
149148
return
150149
}
151150
var index = this.getFilteredIndexOfCurrentArticle()
@@ -162,30 +161,10 @@ module.exports = React.createClass({
162161
if (res.status === 'planetFetched') {
163162
var planet = res.data
164163
this.setState({isFetched: true, currentPlanet: planet, filteredArticles: planet.Articles}, function () {
165-
if (this.state.filteredArticles.length > 0) {
166-
if (this.props.params.localId == null) {
167-
var article = this.state.filteredArticles[0]
168-
if (article == null) return
169-
this.transitionTo(article.type === 'snippet' ? 'snippets' : 'blueprints', {
170-
userName: this.props.params.userName,
171-
planetName: this.props.params.planetName,
172-
localId: planet.Articles[0].localId
173-
})
174-
return
175-
}
176-
if (this.isActive('snippets')) {
177-
this.transitionTo('snippets', {
178-
userName: this.props.params.userName,
179-
planetName: this.props.params.planetName,
180-
localId: this.props.params.localId == null ? planet.Articles[0].localId : this.props.params.localId
181-
})
182-
} else if (this.isActive('blueprints')) {
183-
this.transitionTo('blueprints', {
184-
userName: this.props.params.userName,
185-
planetName: this.props.params.planetName,
186-
localId: this.props.params.localId == null ? planet.Articles[0].localId : this.props.params.localId
187-
})
188-
}
164+
if (this.refs.detail.props.article == null) {
165+
var params = this.props.params
166+
delete params.localId
167+
this.transitionTo('planetHome', params)
189168
}
190169
})
191170
return
@@ -236,6 +215,7 @@ module.exports = React.createClass({
236215
this.setState({isLaunchModalOpen: false})
237216
},
238217
openEditModal: function () {
218+
if (this.refs.detail.props.article == null) {return}
239219
this.setState({isEditModalOpen: true})
240220
},
241221
closeEditModal: function () {
@@ -245,6 +225,7 @@ module.exports = React.createClass({
245225
this.setState({isEditModalOpen: false})
246226
},
247227
openDeleteModal: function () {
228+
if (this.refs.detail.props.article == null) {return}
248229
this.setState({isDeleteModalOpen: true})
249230
},
250231
closeDeleteModal: function () {
@@ -355,12 +336,6 @@ module.exports = React.createClass({
355336

356337
var filteredArticles = this.state.isFetched ? searchArticle(this.state.search, this.state.currentPlanet.Articles) : []
357338

358-
var content = article != null ? (
359-
<PlanetArticleDetail article={article} onOpenEditModal={this.openEditModal} onOpenDeleteModal={this.openDeleteModal}/>
360-
) : (
361-
<div className='PlanetArticleDetail'>Nothing selected</div>
362-
)
363-
364339
var editModal = article != null ? (article.type === 'snippet' ? (
365340
<SnippetEditModal snippet={article} submit={this.submitEditModal} close={this.closeEditModal}/>
366341
) : (
@@ -392,7 +367,8 @@ module.exports = React.createClass({
392367
<PlanetNavigator onOpenLaunchModal={this.openLaunchModal} currentPlanet={this.state.currentPlanet} currentUser={user}/>
393368

394369
<PlanetArticleList ref='list' articles={filteredArticles}/>
395-
{content}
370+
371+
<PlanetArticleDetail ref='detail' article={article} onOpenEditModal={this.openEditModal} onOpenDeleteModal={this.openDeleteModal}/>
396372
</div>
397373
)
398374
}

0 commit comments

Comments
 (0)