Skip to content
GitLab
Menu
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Phạm Chí Công
book_store
Commits
dc5eaebf
Commit
dc5eaebf
authored
4 years ago
by
Phạm Chí Công
Browse files
Options
Download
Plain Diff
Merge branch 'develop' into 'master'
Add config decorator See merge request
!1
parents
99c53fe5
da1d0003
master
1 merge request
!1
Add config decorator
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
App.js
+2
-2
App.js
api/BookApi.js
+1
-1
api/BookApi.js
jsconfig.json
+5
-0
jsconfig.json
mobx/LibraryStore.js
+9
-9
mobx/LibraryStore.js
screens/DetailScreen.js
+7
-7
screens/DetailScreen.js
screens/HomeScreen.js
+1
-1
screens/HomeScreen.js
screens/LibaryScreen.js
+6
-6
screens/LibaryScreen.js
with
31 additions
and
26 deletions
+31
-26
App.js
+
2
-
2
View file @
dc5eaebf
...
...
@@ -3,7 +3,7 @@ import {NavigationContainer} from '@react-navigation/native';
import
{
createStackNavigator
}
from
'
@react-navigation/stack
'
;
import
HomeScreen
from
'
./screens/HomeScreen
'
;
import
DetailsScreen
from
'
./screens/DetailScreen
'
;
import
LibaryScreen
from
'
./screens/LibaryScreen
'
;
import
Lib
r
aryScreen
from
'
./screens/LibaryScreen
'
;
const
Stack
=
createStackNavigator
();
...
...
@@ -17,7 +17,7 @@ function App() {
}}
>
<
Stack
.
Screen
name
=
"
Home
"
component
=
{
HomeScreen
}
/
>
<
Stack
.
Screen
name
=
"
Detail
"
component
=
{
DetailsScreen
}
/
>
<
Stack
.
Screen
name
=
"
Libary
"
component
=
{
LibaryScreen
}
/
>
<
Stack
.
Screen
name
=
"
Lib
r
ary
"
component
=
{
Lib
r
aryScreen
}
/
>
<
/Stack.Navigator
>
<
/NavigationContainer
>
);
...
...
This diff is collapsed.
Click to expand it.
api/BookApi.js
+
1
-
1
View file @
dc5eaebf
...
...
@@ -16,7 +16,7 @@ const addBook = () => {
const
removeBook
=
(
id
)
=>
{
return
request
({
url
:
`
https://5ec39d77628c160016e706f3.mockapi.io/book/
`
,
url
:
'
https://5ec39d77628c160016e706f3.mockapi.io/book/
'
,
method
:
'
POST
'
,
}).
then
((
data
)
=>
data
);
};
...
...
This diff is collapsed.
Click to expand it.
jsconfig.json
0 → 100644
+
5
-
0
View file @
dc5eaebf
{
"compilerOptions"
:
{
"experimentalDecorators"
:
true
}
}
This diff is collapsed.
Click to expand it.
mobx/LibaryStore.js
→
mobx/Lib
r
aryStore.js
+
9
-
9
View file @
dc5eaebf
...
...
@@ -10,21 +10,21 @@ const Book = types.model({
author
:
types
.
string
,
});
const
LibaryStore
=
types
.
model
(
'
libaryStore
'
,
{
const
Lib
r
aryStore
=
types
.
model
(
'
lib
r
aryStore
'
,
{
listBooks
:
types
.
array
(
Book
),
loading
:
false
,
})
.
views
((
self
)
=>
{
return
{
checkBookExistOnLibary
(
id
)
{
const
check
=
self
.
listBooks
.
find
((
book
)
=>
book
.
id
==
id
);
checkBookExistOnLib
r
ary
(
id
)
{
const
check
=
self
.
listBooks
.
find
((
book
)
=>
book
.
id
==
=
id
);
return
check
&&
check
.
id
===
id
?
true
:
false
;
},
};
})
.
actions
((
self
)
=>
{
const
addBookToLibary
=
flow
(
function
*
(
book
)
{
const
addBookToLib
r
ary
=
flow
(
function
*
(
book
)
{
self
.
loading
=
true
;
try
{
const
response
=
yield
bookApi
.
addBook
();
...
...
@@ -42,7 +42,7 @@ const LibaryStore = types
return
self
.
listBooks
;
});
const
removeBookInLibary
=
flow
(
function
*
(
id
)
{
const
removeBookInLib
r
ary
=
flow
(
function
*
(
id
)
{
self
.
loading
=
true
;
try
{
const
response
=
yield
bookApi
.
removeBook
(
id
);
...
...
@@ -61,9 +61,9 @@ const LibaryStore = types
return
self
.
listBooks
;
});
return
{
addBookToLibary
,
removeBookInLibary
,
addBookToLib
r
ary
,
removeBookInLib
r
ary
,
};
});
export
default
LibaryStore
.
create
({});
export
default
Lib
r
aryStore
.
create
({});
This diff is collapsed.
Click to expand it.
screens/DetailScreen.js
+
7
-
7
View file @
dc5eaebf
import
React
,
{
Component
}
from
'
react
'
;
import
{
View
,
Text
,
Image
,
ScrollView
,
StyleSheet
}
from
'
react-native
'
;
import
{
Button
,
Icon
}
from
'
react-native-elements
'
;
import
LibaryStore
from
'
../mobx/LibaryStore
'
;
import
Lib
r
aryStore
from
'
../mobx/Lib
r
aryStore
'
;
import
{
observer
}
from
'
mobx-react
'
;
import
Loading
from
'
../components/LoadingComponent
'
;
@
observer
class
DetailScreen
extends
Component
{
handleAddBookToLibary
(
book
)
{
LibaryStore
.
addBookToLibary
(
book
);
handleAddBookToLib
r
ary
(
book
)
{
Lib
r
aryStore
.
addBookToLib
r
ary
(
book
);
}
render
()
{
const
{
navigation
,
route
}
=
this
.
props
;
...
...
@@ -16,7 +16,7 @@ class DetailScreen extends Component {
return
(
<
View
style
=
{
styles
.
container
}
>
<
Loading
loading
=
{
LibaryStore
.
loading
}
/
>
<
Loading
loading
=
{
Lib
r
aryStore
.
loading
}
/
>
<
View
style
=
{
styles
.
screen1
}
>
<
View
style
=
{
styles
.
parentBntBack
}
>
<
Button
...
...
@@ -58,11 +58,11 @@ class DetailScreen extends Component {
<
Button
titleStyle
=
{[
styles
.
titleStyleButton
,
styles
.
titleBtnAdd
]}
buttonStyle
=
{[
styles
.
btnAdd
]}
title
=
"
Add to Libary
"
title
=
"
Add to Lib
r
ary
"
onPress
=
{()
=>
{
this
.
handleAddBookToLibary
(
book
);
this
.
handleAddBookToLib
r
ary
(
book
);
}}
disabled
=
{
LibaryStore
.
checkBookExistOnLibary
(
book
.
id
)}
disabled
=
{
Lib
r
aryStore
.
checkBookExistOnLib
r
ary
(
book
.
id
)}
/
>
<
/View
>
<
/View
>
...
...
This diff is collapsed.
Click to expand it.
screens/HomeScreen.js
+
1
-
1
View file @
dc5eaebf
...
...
@@ -88,7 +88,7 @@ class HomeScreen extends Component {
<
Button
buttonStyle
=
{[
styles
.
buttonAction
]}
onPress
=
{()
=>
{
navigation
.
navigate
(
'
Libary
'
);
navigation
.
navigate
(
'
Lib
r
ary
'
);
}}
icon
=
{
<
Icon
color
=
"
#FC8B55
"
size
=
{
40
}
name
=
"
book
"
type
=
"
font-awesome
"
/>
...
...
This diff is collapsed.
Click to expand it.
screens/LibaryScreen.js
+
6
-
6
View file @
dc5eaebf
...
...
@@ -8,26 +8,26 @@ import {
StyleSheet
,
}
from
'
react-native
'
;
import
{
Button
,
Icon
}
from
'
react-native-elements
'
;
import
LibaryStore
from
'
../mobx/LibaryStore
'
;
import
Lib
r
aryStore
from
'
../mobx/Lib
r
aryStore
'
;
import
{
observer
}
from
'
mobx-react
'
;
import
Loading
from
'
../components/LoadingComponent
'
;
const
screenWidth
=
Dimensions
.
get
(
'
window
'
).
width
;
@
observer
class
LibaryScreen
extends
Component
{
class
Lib
r
aryScreen
extends
Component
{
handleRemoveBook
(
id
)
{
LibaryStore
.
removeBookInLibary
(
id
);
Lib
r
aryStore
.
removeBookInLib
r
ary
(
id
);
}
render
()
{
const
{
navigation
}
=
this
.
props
;
const
{
listBooks
}
=
LibaryStore
;
const
{
listBooks
}
=
Lib
r
aryStore
;
console
.
log
(
JSON
.
stringify
(
listBooks
));
return
(
<
View
style
=
{
styles
.
all
}
>
<
Loading
loading
=
{
LibaryStore
.
loading
}
/
>
<
Loading
loading
=
{
Lib
r
aryStore
.
loading
}
/
>
<
View
style
=
{
styles
.
categoryBook
}
>
<
Text
style
=
{[
styles
.
textCategory
]}
>
Trending
<
/Text
>
<
Text
style
=
{[
styles
.
textCategory
,
styles
.
textCategoryActive
]}
>
...
...
@@ -218,4 +218,4 @@ const styles = StyleSheet.create({
},
});
export
default
LibaryScreen
;
export
default
Lib
r
aryScreen
;
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets