Skip to content

Commit

Permalink
don't flash error page during post load
Browse files Browse the repository at this point in the history
  • Loading branch information
sampl committed Aug 24, 2018
1 parent 8e29b63 commit ed3071a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/views/posts/Post.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ const Post = ({match}) => (
filter={['slug', '==', match.params.slug]}
>
{ ({error, isLoading, data}) => {
if (error || data.length === 0) {
if (error) {
return <Error error={error} />
}

if (isLoading) {
return <p>loading...</p>
}

if (!isLoading && data.length === 0) {
return <Error />
}

const post = data[0]

return <div>
Expand Down
10 changes: 7 additions & 3 deletions src/views/posts/PostEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ const PostEdit = ({match, history}) => (
filter={['slug', '==', match.params.slug]}
>
{ ({error, isLoading, data}) => {
if (error || data.length === 0) {
if (error) {
return <Error error={error} />
}

if (isLoading) {
return <p>loading...</p>
}

if (!isLoading && data.length === 0) {
return <Error />
}

const post = data[0]

Expand All @@ -31,13 +35,13 @@ const PostEdit = ({match, history}) => (
return updatePost(post.id, values)
.then(() => history.push(`/${post.slug}`))
}} />
or
<br />
<button onClick={() => {
if (window.confirm(`Are you sure you want to delete this post?`)) {
deletePost(post)
.then( () => history.push(`/`))
}
}}>delete post</button>
}}>Delete post</button>
</div>
}}
</FirestoreCollection>
Expand Down
2 changes: 1 addition & 1 deletion src/views/posts/Posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Posts = () => (
return <p>loading...</p>
}

if (data.length === 0) {
if (!isLoading && data.length === 0) {
return <p>No posts yet!</p>
}

Expand Down

0 comments on commit ed3071a

Please sign in to comment.