Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Project 4 - React Native
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Trym Grande
Project 4 - React Native
Commits
b441f392
Commit
b441f392
authored
3 years ago
by
thombje
Browse files
Options
Downloads
Patches
Plain Diff
added hasMore global state
parent
e00eea92
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
client/src/components/Header.tsx
+4
-1
4 additions, 1 deletion
client/src/components/Header.tsx
client/src/components/Movies.tsx
+9
-4
9 additions, 4 deletions
client/src/components/Movies.tsx
client/src/components/MoviesStore.tsx
+10
-1
10 additions, 1 deletion
client/src/components/MoviesStore.tsx
with
23 additions
and
6 deletions
client/src/components/Header.tsx
+
4
−
1
View file @
b441f392
...
...
@@ -46,7 +46,10 @@ class Header extends React.Component<MoviesProps, MyState> {
getMovieByColumnType
(
columnType
:
services
.
ColumnType
,
value
:
string
,
neededData
:
string
)
{
services
.
queryFetch
(
services
.
generateQuery
(
columnType
,
value
,
neededData
)
,
'
POST
'
)
.
then
(
res
=>
res
.
json
())
.
then
(
res
=>
this
.
props
.
moviesStore
.
setMovies
(
res
.
data
.
getMovieByColumnType
))
.
then
(
res
=>
{
this
.
props
.
moviesStore
.
setHasMore
(
false
);
this
.
props
.
moviesStore
.
setMovies
(
res
.
data
.
getMovieByColumnType
);
})
}
}
...
...
This diff is collapsed.
Click to expand it.
client/src/components/Movies.tsx
+
9
−
4
View file @
b441f392
...
...
@@ -4,6 +4,7 @@ import InfiniteScroll from "react-infinite-scroller";
import
{
MoviesStore
,
MoviesStoreImplementation
}
from
"
./MoviesStore
"
;
import
{
inject
,
observer
}
from
'
mobx-react
'
;
import
*
as
services
from
'
./services
'
;
import
{
observe
}
from
'
mobx
'
;
interface
MoviesProps
{
moviesStore
:
MoviesStoreImplementation
...
...
@@ -14,7 +15,9 @@ function Movies(props: MoviesProps){
// const [movies, setMovies] = useState([]);
useEffect
(()
=>
{
if
(
MoviesStore
.
hasMore
){
getAllMovies
({
lim
:
13
});
}
},
[]);
...
...
@@ -33,7 +36,10 @@ function Movies(props: MoviesProps){
services
.
queryFetch
(
generateAllMoviesQuery
(
params
.
lim
),
'
POST
'
)
.
then
(
res
=>
res
.
json
())
// .then(res => setMovies(res.data.getAllMovies))
.
then
(
res
=>
props
.
moviesStore
.
setMovies
(
res
.
data
.
getAllMovies
))
.
then
(
res
=>
{
props
.
moviesStore
.
setMovies
(
res
.
data
.
getAllMovies
);
props
.
moviesStore
.
setHasMore
(
true
);
})
}
...
...
@@ -53,7 +59,7 @@ function Movies(props: MoviesProps){
<
InfiniteScroll
pageStart
=
{
0
}
loadMore
=
{
()
=>
getAllMovies
({
lim
:
MoviesStore
.
movies
.
length
+
13
})
}
hasMore
=
{
true
||
fals
e
}
hasMore
=
{
MoviesStore
.
hasMor
e
}
useWindow
=
{
true
}
loader
=
{
<
div
key
=
"loading"
className
=
"loader"
>
...
...
@@ -67,5 +73,4 @@ function Movies(props: MoviesProps){
}
export
default
inject
(
'
moviesStore
'
)(
observer
(
Movies
))
This diff is collapsed.
Click to expand it.
client/src/components/MoviesStore.tsx
+
10
−
1
View file @
b441f392
...
...
@@ -4,20 +4,29 @@ interface Movie {
}
export
class
MoviesStoreImplementation
{
movies
:
Movie
[]
=
[];
hasMore
:
boolean
=
true
;
constructor
()
{
makeObservable
(
this
,
{
movies
:
observable
,
setMovies
:
action
setMovies
:
action
,
hasMore
:
observable
,
setHasMore
:
action
});
}
setMovies
(
movies
:
any
)
{
this
.
movies
=
movies
;
}
setHasMore
(
hasMore
:
boolean
)
{
this
.
hasMore
=
hasMore
;
}
}
export
const
MoviesStore
=
new
MoviesStoreImplementation
();
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment