I posted about this a couple of weeks ago, but although I got some useful links and help from Yisrael, I didn’t finally get it to work, although I feel I’m close. It seems to be getting into some sort of loop.
Here is the relevant code:
import { local } from ‘wix-storage’ ;
import wixData from ‘wix-data’ ;
var searchType ;
const loadLimit = 15 ;
const startLoadingNext = 10 ;
let skip = 0 ;
let finishLoad = false ;
$w . onReady ( function () {
$w ( "#listRepeater" ). data = []
$w ( "#listRepeater" ). onItemReady (( $item , authorpages , index ) => {
$item ( "#fullName" ). text = authorpages . fullName ;
$item ( "#shortBio" ). text = authorpages . briefBio ;
$item ( "#genre1" ). text = authorpages . genre1 ;
$item ( "#genre2" ). text = authorpages . genre2 ;
$item ( "#photo" ). src = authorpages . photo ;
// for each search type,
// loading 10th item will trigger next load of items
if ( searchType === 1 && index % startLoadingNext )
{ $w ( ‘#triggerBox’ ). onViewportEnter (() => loadMore1 ());
}
})
loadMore1 ();
async function loadMore1 () {
if (! finishLoad && $w ( ‘#progressImage’ ). collapsed ) {
$w ( ‘#progressImage’ ). expand ();
console . log ( "loadMore1 skip = " , skip );
try {
const moreData = await search1 ( loadLimit , skip );
const currData = $w ( ‘#listRepeater’ ). data ;
$w ( ‘#listRepeater’ ). data = currData . concat ( moreData );
skip ++;
$w ( ‘#progressImage’ ). collapse ();
if ( moreData . length < loadLimit ) {
finishLoad = true ;
}
} catch ( err ) {
console . error ( err );
}
}
}
// searches authorpages database with author name
// sorts on most liked
async function search1 ( limit , skip ) {
$w ( ‘#listRepeater’ ). hide ();
$w ( ‘#searchFail’ ). hide ();
$w ( ‘#textClassics’ ). hide ();
console . log ( "search1 skip = " , skip );
try {
const results = await wixData . query ( ‘authorpages’ )
. limit ( limit )
. skip ( limit * skip )
. descending ( “likes” )
. contains ( ‘fullName’ , $w ( “#name” ). value )
. or ( wixData . query ( ‘authorpages’ )
. eq ( ‘email’ , $w ( “#email” ). value ))
. find ();
return results . items || ;
} catch ( err ) {
console . error ( err );
}
}
It comes up with no results. The console log shows it gets to search1 and skip is added to each time it goes round, but this message comes up multiple times per iteration with the IDs of 4 or 5 items repeating more or less at random:
Wix code SDK Warning: The data that was passed to data contained at least two items with the same ID: 4d0d0765-96d8-4dfa-87a4-de567e115a38. Only the first item was accepted.
It’s on this line in loadMore1
const currData = $w ( ‘#listRepeater’ ). data ;
I really hope somebody can help me with this!