6
6
<img :src =" movie.img" />
7
7
</div >
8
8
</div >
9
- <a @click =" nextHandler()" class =" next" >Next</a >
9
+ <div class =" loader" v-if =" isLoading" ></div >
10
+ <div class =" last" v-if =" isLast" >No more movies 😒</div >
10
11
</div >
11
12
</template >
12
13
@@ -33,34 +34,39 @@ const catalog = [
33
34
}
34
35
]
35
36
36
- let ias = null ;
37
-
38
37
export default Vue .extend ({
39
38
data() {
40
39
return {
40
+ ias: null ,
41
+ isLast: false ,
42
+ isLoading: false ,
41
43
movies: []
42
44
};
43
45
},
44
46
mounted() {
45
- // Simulate initial load
46
- Promise .all ([
47
- this .loadNewMovie (),
48
- this .loadNewMovie (),
49
- this .loadNewMovie (),
50
- this .loadNewMovie ()
51
- ]).then (() => {
52
- ias = new InfiniteAjaxScroll (' .movies' , {
53
- item: ' .movie' ,
54
- pagination: false ,
55
- });
47
+ const ias = new InfiniteAjaxScroll (' .movies' , {
48
+ item: ' .movie' ,
49
+ next: this .nextPage ,
50
+ spinner: {
51
+ show : () => this .isLoading = true ,
52
+ hide : () => this .isLoading = false ,
53
+ },
54
+ });
56
55
57
- ias .on (' hit' , () => {
58
- console .log (" hit!!!" )
59
- this .loadNewMovie ()
60
- })
61
- })
56
+ ias .on (' last' , () => {
57
+ this .isLast = true ;
58
+ });
62
59
},
63
60
methods: {
61
+ nextPage(pageIndex ) {
62
+ const hasNextUrl = pageIndex < 4 ;
63
+
64
+ return Promise .all ([
65
+ this .loadNewMovie (),
66
+ this .loadNewMovie (),
67
+ this .loadNewMovie ()
68
+ ]).then (() => hasNextUrl );
69
+ },
64
70
loadNewMovie() {
65
71
return new Promise ((resolve ) => {
66
72
// Simulate loading of new movie
@@ -70,24 +76,44 @@ export default Vue.extend({
70
76
71
77
this .movies .push (movie )
72
78
resolve ()
73
- }, 2000 )
79
+ }, 200 )
74
80
})
75
- },
76
- nextHandler() {
77
- this .loadNewMovie ()
78
81
}
79
82
}
80
83
});
81
84
</script >
82
85
83
86
<style lang="scss" scoped>
87
+ .movies {
88
+ margin : 0 auto ;
89
+ padding : 20px ;
90
+ max-width : 300px ;
91
+ }
84
92
.movie {
85
- margin : 20px 0 ;
86
- padding : 20px 20px ;
87
- width : 300px ;
88
- background-color : #ff0000 ;
93
+ margin-top : 20px ;
94
+ padding : 20px ;
95
+ background-image : linear-gradient (to right , #EE0979 0% , #F73D39 20% );
89
96
img {
90
97
width : 100% ;
91
98
}
92
99
}
100
+
101
+ .last {
102
+ font-family : sans-serif ;
103
+ text-align : center ;
104
+ color : #999 ;
105
+ line-height : 40px ;
106
+ }
107
+
108
+ .loader {
109
+ height : 40px ;
110
+ background : transparent url (' loader.svg' ) no-repeat center center ;
111
+ background-size : 40px 19px ;
112
+ animation : flipAnimation 1s infinite ;
113
+ }
114
+
115
+ @keyframes flipAnimation {
116
+ 0%,100% { transform : rotateY (-180deg ); }
117
+ 50% { transform : rotateY (0deg ); }
118
+ }
93
119
</style >
0 commit comments