Skip to content

Commit 3159712

Browse files
author
Moeen Basra
committed
adding react-loader
1 parent 84dd806 commit 3159712

File tree

10 files changed

+139
-61
lines changed

10 files changed

+139
-61
lines changed

app/Http/Controllers/Api/Auth/LoginController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function login(Request $request)
3535
return json_decode((string)$response->getBody(), true);
3636
} catch (\Exception $e) {
3737
return response()->json([
38-
"error" => "invalid_credentials",
39-
"message" => "The user credentials were incorrect."
38+
'error' => 'invalid_credentials',
39+
'message' => "{$e->getCode()}: {$e->getMessage()}"
4040
], 401);
4141
}
4242
}

composer.lock

Lines changed: 40 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"react-document-title": "^2.0.3",
4949
"react-dom": "^16.2.0",
5050
"react-draft-wysiwyg": "^1.12.3",
51+
"react-loadable": "^5.3.1",
5152
"react-redux": "^5.0.6",
5253
"react-router-dom": "^4.2.2",
5354
"reactstrap": "5.0.0-alpha.4",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
// set display name for component
5+
const displayName = 'CommonLoader'
6+
7+
// validate component properties
8+
const propTypes = {
9+
isLoading: PropTypes.bool,
10+
error: PropTypes.object,
11+
}
12+
13+
const LoadingComponent = ({isLoading, error}) => {
14+
// Handle the loading state
15+
if (isLoading) {
16+
return <div>Loading...</div>
17+
}
18+
// Handle the error state
19+
else if (error) {
20+
return <div>Sorry, there was a problem loading the page.</div>
21+
}
22+
else {
23+
return null
24+
}
25+
}
26+
27+
LoadingComponent.displayName = displayName
28+
LoadingComponent.propTypes = propTypes
29+
30+
export default LoadingComponent
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1-
import Articles from "./pages/list"
2-
import EditArticle from "./pages/edit"
3-
import AddArticle from "./pages/add"
1+
// import lib
2+
import Loadable from 'react-loadable'
3+
4+
// import components
5+
import LoadingComponent from '../../common/loader'
46

57
export default [
68
{
79
path: '/articles',
810
exact: true,
911
auth: true,
10-
component: Articles,
12+
component: Loadable({
13+
loader: () => import('./pages/list'),
14+
loading: LoadingComponent,
15+
}),
1116
},
1217
{
1318
path: '/articles/create',
1419
exact: true,
1520
auth: true,
16-
component: AddArticle,
21+
component: Loadable({
22+
loader: () => import('./pages/add'),
23+
loading: LoadingComponent,
24+
}),
1725
},
1826
{
1927
path: '/articles/:id/edit',
2028
exact: true,
2129
auth: true,
22-
component: EditArticle,
30+
component: Loadable({
31+
loader: () => import('./pages/edit'),
32+
loading: LoadingComponent,
33+
}),
2334
},
2435
]
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
import Register from "./pages/register"
2-
import Login from "./pages/login"
1+
// import lib
2+
import Loadable from 'react-loadable'
3+
4+
// import components
5+
import LoadingComponent from '../../common/loader'
6+
37

48
export default [
59
{
610
path: '/login',
711
exact: true,
8-
component: Login,
12+
component: Loadable({
13+
loader: () => import('./pages/login'),
14+
loading: LoadingComponent,
15+
}),
916
},
1017
{
1118
path: '/register',
1219
exact: true,
13-
component: Register,
20+
component: Loadable({
21+
loader: () => import('./pages/register'),
22+
loading: LoadingComponent,
23+
}),
1424
},
1525
]
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import Edit from "./pages/edit"
1+
// import lib
2+
import Loadable from 'react-loadable'
3+
4+
// import components
5+
import LoadingComponent from '../../common/loader'
26

37
export default [
48
{
59
path: '/users/:id/edit',
610
exact: true,
711
auth: true,
8-
component: Edit,
12+
component: Loadable({
13+
loader: () => import('./pages/edit'),
14+
loading: LoadingComponent,
15+
}),
916
},
1017
]

resources/assets/js/modules/web/pages/blog/details/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import Page from './Page'
77
const mapStateToProps = (state, router) => {
88
const { params } = router.match
99

10+
console.log(params)
11+
1012
const article = state.articles.data.find(article => article.slug === params.slug)
1113
return {
1214
article: article ? new Article(article) : new Article({})

0 commit comments

Comments
 (0)