@@ -2,6 +2,7 @@ import React, { Component } from 'react';
22import { connect } from 'react-redux' ;
33import PropTypes from 'prop-types' ;
44import { withTranslation } from 'react-i18next' ;
5+ import axios from 'axios' ;
56import ReactGA from 'react-ga4' ;
67import { range } from 'lodash' ;
78
@@ -21,9 +22,11 @@ import {
2122 deleteLectureFromCart ,
2223 setIsLectureListOpenOnMobile ,
2324} from '../../../../redux/actions/timetable/list' ;
24- import { openSearch } from '../../../../redux/actions/timetable/search' ;
25+ import { openSearch , setLastSearchOption } from '../../../../redux/actions/timetable/search' ;
2526import { addLectureToTimetable } from '../../../../redux/actions/timetable/timetable' ;
2627
28+ import { setListLectures } from '../../../../redux/actions/timetable/list' ;
29+
2730import { LectureFocusFrom } from '@/shapes/enum' ;
2831import { LectureListCode } from '@/shapes/enum' ;
2932
@@ -59,12 +62,20 @@ import {
5962import LectureGroupBlockRow from '../../../blocks/LectureGroupBlockRow' ;
6063import { TIMETABLE_START_HOUR } from '../../../../common/constants' ;
6164
65+ const REFRESH_LIMIT = 50 ;
66+
6267class LectureListSection extends Component {
6368 constructor ( props ) {
6469 super ( props ) ;
6570 this . arrowRef = React . createRef ( ) ;
6671 }
6772
73+ onScrollChange = ( e ) => {
74+ const { scrollTop, scrollHeight, clientHeight } = e ;
75+
76+ if ( scrollTop + clientHeight >= scrollHeight ) this . _addLectureGroups ( ) ;
77+ } ;
78+
6879 componentDidMount ( ) {
6980 window . addEventListener ( 'resize' , this . selectWithArrow ) ;
7081 }
@@ -293,6 +304,64 @@ class LectureListSection extends Component {
293304 return lists [ selectedListCode ] . lectureGroups ;
294305 } ;
295306
307+ _addLectureGroups = async ( ) => {
308+ const {
309+ lastSearchOption,
310+ setLastSearchOption,
311+ year,
312+ semester,
313+ setListLecturesDispatch,
314+ lists,
315+ } = this . props ;
316+
317+ const lectures = this . _getLectureGroups ( LectureListCode . SEARCH , lists ) ;
318+
319+ let offset = 0 ;
320+
321+ for ( let i = 0 ; i < lectures . length - 1 ; i ++ ) {
322+ offset += lectures [ i ] . length ;
323+ }
324+
325+ const option = {
326+ ...lastSearchOption ,
327+ offset,
328+ limit : offset + REFRESH_LIMIT ,
329+ } ;
330+
331+ await axios
332+ . get ( '/api/lectures' , {
333+ params : {
334+ year : year ,
335+ semester : semester ,
336+ ...option ,
337+ order : [ 'old_code' , 'class_no' ] ,
338+ } ,
339+ metadata : {
340+ gaCategory : 'Timetable' ,
341+ gaVariable : 'POST / List' ,
342+ } ,
343+ } )
344+ . then ( ( response ) => {
345+ const newProps = this . props ;
346+ if ( newProps . year !== year || newProps . semester !== semester ) {
347+ return ;
348+ }
349+ if ( response . data . length > 0 ) {
350+ const newLectures = lectures ;
351+ let spreadedLectures = [ ] ;
352+
353+ for ( let i = 0 ; i < newLectures . length - 1 ; i ++ ) {
354+ spreadedLectures = spreadedLectures . concat ( newLectures [ i ] ) ;
355+ }
356+
357+ spreadedLectures = spreadedLectures . concat ( response . data ) ;
358+
359+ setListLecturesDispatch ( LectureListCode . SEARCH , spreadedLectures ) ;
360+ }
361+ } )
362+ . catch ( ( error ) => { } ) ;
363+ } ;
364+
296365 render ( ) {
297366 const { t } = this . props ;
298367 const { user, lectureFocus, selectedTimetable, selectedListCode, lastSearchOption, lists } =
@@ -376,7 +445,12 @@ class LectureListSection extends Component {
376445 ) ;
377446 }
378447 return (
379- < Scroller onScroll = { this . selectWithArrow } key = { selectedListCode } >
448+ < Scroller
449+ onScroll = { ( e ) => {
450+ this . selectWithArrow ( ) ;
451+ this . onScrollChange ( e ) ;
452+ } }
453+ key = { selectedListCode } >
380454 < div className = { classNames ( 'block-list' ) } >
381455 { lectureGroups . map ( ( lg ) => (
382456 < LectureGroupBlock
@@ -467,6 +541,12 @@ const mapDispatchToProps = (dispatch) => ({
467541 setIsLectureListOpenOnMobileDispatch : ( isLectureListOpenOnMobile ) => {
468542 dispatch ( setIsLectureListOpenOnMobile ( isLectureListOpenOnMobile ) ) ;
469543 } ,
544+ setLastSearchOptionDispatch : ( lastSearchOption ) => {
545+ dispatch ( setLastSearchOption ( lastSearchOption ) ) ;
546+ } ,
547+ setListLecturesDispatch : ( code , lectures ) => {
548+ dispatch ( setListLectures ( code , lectures ) ) ;
549+ } ,
470550} ) ;
471551
472552LectureListSection . propTypes = {
@@ -485,8 +565,10 @@ LectureListSection.propTypes = {
485565 clearLectureFocusDispatch : PropTypes . func . isRequired ,
486566 addLectureToTimetableDispatch : PropTypes . func . isRequired ,
487567 addLectureToCartDispatch : PropTypes . func . isRequired ,
568+ setListLecturesDispatch : PropTypes . func . isRequired ,
488569 deleteLectureFromCartDispatch : PropTypes . func . isRequired ,
489570 setIsLectureListOpenOnMobileDispatch : PropTypes . func . isRequired ,
571+ setLastSearchOptionDispatch : PropTypes . func . isRequired ,
490572} ;
491573
492574export default withTranslation ( ) ( connect ( mapStateToProps , mapDispatchToProps ) ( LectureListSection ) ) ;
0 commit comments