← All changes
|
assets/src/apps/js/frontend/single-curriculum/components/items-progress.js
+57
-57
4.3.8
→
4.4.9
View file →
| @@ -1,57 +1,57 @@ | ||
| 1 | -// Rest API load content course progress - Nhamdv. | |
| 2 | -import { addQueryArgs } from '@wordpress/url'; | |
| 3 | -import lpModalOverlayCompleteItem from '../../show-lp-overlay-complete-item'; | |
| 4 | - | |
| 5 | -export const itemsProgress = () => { | |
| 6 | - const elements = document.querySelectorAll( '.popup-header__inner' ); | |
| 7 | - | |
| 8 | - if ( ! elements.length ) { | |
| 9 | - return; | |
| 10 | - } | |
| 11 | - | |
| 12 | - if ( document.querySelector( '#learn-press-quiz-app div.quiz-result' ) !== null ) { | |
| 13 | - return; | |
| 14 | - } | |
| 15 | - | |
| 16 | - if ( elements[ 0 ].querySelectorAll( 'form.form-button-finish-course' ).length !== 0 ) { | |
| 17 | - return; | |
| 18 | - } | |
| 19 | - | |
| 20 | - const user_id = lpGlobalSettings.user_id || 0; | |
| 21 | - if ( user_id === 0 ) { | |
| 22 | - return; | |
| 23 | - } | |
| 24 | - | |
| 25 | - if ( 'IntersectionObserver' in window ) { | |
| 26 | - const eleObserver = new IntersectionObserver( ( entries, observer ) => { | |
| 27 | - entries.forEach( ( entry ) => { | |
| 28 | - if ( entry.isIntersecting ) { | |
| 29 | - const ele = entry.target; | |
| 30 | - | |
| 31 | - getResponse( ele ); | |
| 32 | - | |
| 33 | - eleObserver.unobserve( ele ); | |
| 34 | - } | |
| 35 | - } ); | |
| 36 | - } ); | |
| 37 | - | |
| 38 | - [ ...elements ].map( ( ele ) => eleObserver.observe( ele ) ); | |
| 39 | - } | |
| 40 | -}; | |
| 41 | - | |
| 42 | -export const getResponse = async ( ele ) => { | |
| 43 | - const response = await wp.apiFetch( { | |
| 44 | - path: addQueryArgs( 'lp/v1/lazy-load/items-progress', { | |
| 45 | - courseId: lpGlobalSettings.post_id || '', | |
| 46 | - userId: lpGlobalSettings.user_id || '', | |
| 47 | - } ), | |
| 48 | - method: 'GET', | |
| 49 | - } ); | |
| 50 | - | |
| 51 | - const { data } = response; | |
| 52 | - | |
| 53 | - ele.innerHTML += data; | |
| 54 | - ele.classList.add( 'can-finish-course' ); | |
| 55 | - | |
| 56 | - lpModalOverlayCompleteItem.init(); | |
| 57 | -}; | |
| 1 | +// Rest API load content course progress - Nhamdv. | |
| 2 | +import { addQueryArgs } from '@wordpress/url'; | |
| 3 | +import lpModalOverlayCompleteItem from '../../show-lp-overlay-complete-item'; | |
| 4 | + | |
| 5 | +export const itemsProgress = () => { | |
| 6 | + const elements = document.querySelectorAll( '.popup-header__inner' ); | |
| 7 | + | |
| 8 | + if ( ! elements.length ) { | |
| 9 | + return; | |
| 10 | + } | |
| 11 | + | |
| 12 | + if ( document.querySelector( '#learn-press-quiz-app div.quiz-result' ) !== null ) { | |
| 13 | + return; | |
| 14 | + } | |
| 15 | + | |
| 16 | + if ( elements[ 0 ].querySelectorAll( 'form.form-button-finish-course' ).length !== 0 ) { | |
| 17 | + return; | |
| 18 | + } | |
| 19 | + | |
| 20 | + const user_id = lpGlobalSettings.user_id || 0; | |
| 21 | + if ( user_id === 0 ) { | |
| 22 | + return; | |
| 23 | + } | |
| 24 | + | |
| 25 | + if ( 'IntersectionObserver' in window ) { | |
| 26 | + const eleObserver = new IntersectionObserver( ( entries, observer ) => { | |
| 27 | + entries.forEach( ( entry ) => { | |
| 28 | + if ( entry.isIntersecting ) { | |
| 29 | + const ele = entry.target; | |
| 30 | + | |
| 31 | + getResponse( ele ); | |
| 32 | + | |
| 33 | + eleObserver.unobserve( ele ); | |
| 34 | + } | |
| 35 | + } ); | |
| 36 | + } ); | |
| 37 | + | |
| 38 | + [ ...elements ].map( ( ele ) => eleObserver.observe( ele ) ); | |
| 39 | + } | |
| 40 | +}; | |
| 41 | + | |
| 42 | +export const getResponse = async ( ele ) => { | |
| 43 | + const response = await wp.apiFetch( { | |
| 44 | + path: addQueryArgs( 'lp/v1/lazy-load/items-progress', { | |
| 45 | + courseId: lpGlobalSettings.post_id || '', | |
| 46 | + userId: lpGlobalSettings.user_id || '', | |
| 47 | + } ), | |
| 48 | + method: 'GET', | |
| 49 | + } ); | |
| 50 | + | |
| 51 | + const { data } = response; | |
| 52 | + | |
| 53 | + ele.innerHTML += data; | |
| 54 | + ele.classList.add( 'can-finish-course' ); | |
| 55 | + | |
| 56 | + lpModalOverlayCompleteItem.init(); | |
| 57 | +}; | |