@oezdemirumut I have looked at the code on the web page in question. You have several things going on that I would recommend you fix. I have annotated the code snippet below. This may not be all of your problems but they will likely contribute to the issues you are facing.
I would recommend that you re-familiarize yourself with the wix-Data, Dataset and repeater scope models and what JavaScript event handlers do and consider refactoring your code to make bug detection easier!
Cheers
Steve
//-----------------------------#1 YOU HAVE TOO MANY $w.onReady() CALLS --------------//
// This may work but will not necessarily result in the behavior you are expecting //
// You should put all of your start up code in ONE SINGLE $w.onReady() function . //
$w.onReady(() => {
if($w("#repeater1").rendered === false){
winLocation.to(winLocation.url)
}
})
// ^
// ----------- MERGE THIS | AND THAT | INTO A SINGLE onReady() WITH THE OTHER ONES //
// v
$w.onReady(()=> {
// all details to the campaign is "allCampaignDetails"
wixData.query("campaignCollection")
.contains("_owner", user.id)
.find()
//
.then((result) => {
//---------------- #2 YOU SHOULD CONSIDER USING DIFFERENT NAMES FOR result -----------//
// This is for clarity as much as anything else. You may have scope issues. The comment//
// 'all details to the application and applied influencers is "result"' //
// Implies you want to use result for a particular purpose BUT you have two places //
// 'result' is set one is the .then() above & the other is in the getItems().then() //
// below. Make sure you are using this variable correctly! I would use unique names //
allCampaignDetails = result.items
//console.log(allCampaignDetails)
result.items.forEach(element => {
campaignIDtechnical.push(element.campaignIDtechnical)
})
}).then( () =>{
//
//-------- #3 YOU ARE NOT WAITING FOR $w('#dataset1').onReady() BEFORE YOU getItems ---//
// When this is called the dataset may not be loaded. So the initial call to getTotalCount() may //
// return 0. So nothing will be returned. You should wrap the getItems code below in an onReady //
//
// all details to the application and applied influencers is "result"
$w("#dataset1").getItems(0, $w("#dataset1").getTotalCount())
.then((result) => { // <<<<<< THIS IS THE SECOND PLACE WHERE YOU SET RESULT
allApplicationDetails = result.items
//---------------- #4 YOU ARE MAKING AN ASSUMPTION ABOUT the 'result' variable here ---//
// Just because you asked for .getTotalCount() items from $w('#dataset1') doesn't //
// mean you were returned that number. This for loop should be i < result.length!! //
// . As mentioned above if the dataset finishes loading after you called getItems then it is . //
// possible that result.length = 0 BUT $w("#dataset1").getTotalCount() is > zero and this will . //
// fail.
for (let i= 0 ; i < $w("#dataset1").getTotalCount() ; i++) {
let temp_img;
let campaign_ID;
let status;
let influencer_name;
let influced_name;
let motivation;
let language;
let followers;
let age;
let gender;
let personal_image;
let address;
let addressline2;
let zipCode;
let city;
let country;
let state
if (campaignIDtechnical.indexOf(result.items[i].idCampaignTechnical) > -1 && result.items[i].status === "not answered") {
//console.log("yes sir, i contain, ", result.items[i].idCampaignTechnical)
allCampaignDetails.forEach(element => {
if(element.campaignIDtechnical === result.items[i].idCampaignTechnical) {
temp_img = element.campaignImages1
campaign_ID = element.campaignID
}
})
repeater_data.push(
{"_id":(row_i+1).toString(10),
"img":temp_img,
"campaignID":campaign_ID,
"status":result.items[i].status,
"influencerName":result.items[i].influencerName,
"influcedName":result.items[i].influcedName,
"motivationText":result.items[i].motivationText,
"influencerLanguage":result.items[i].influencerLanguage,
"amountFollowers":result.items[i].amountFollowers,
"age":parseInt(result.items[i].age,10),
"gender":result.items[i].gender,
"personalId":result.items[i].personalId,
"statistics":"https://www.influced.com/influencer-statistics?influencerName="+result.items[i].influencerName,
"address": result.items[i].address,
"addressline2": result.items[i].addressLine2,
"zipCode": result.items[i].zipCode,
"city": result.items[i].city,
"country": result.items[i].country,
"row_idx": i
})
row_i++
}
}
}).then(()=> {
$w("#repeater1").data = repeater_data.slice(fromPagination, toPagination);
if(repeater_data.length > toPagination) {
$w("#showMore").expand()
}
$w("#totalApplications").value = parseInt(repeater_data.length, 10)
$w("#repeater1").onItemReady( ($item, itemData, index) => {
$item("#rowIDX").value = itemData.row_idx;
$item("#img").src = itemData.img;
$item("#campaignID").text = itemData.campaignID;
$item("#status").text = itemData.status;
$item("#row").text = (itemData._id).toString(10);
$item("#influencerName").text = itemData.influencerName;
$item("#influcedName").text = itemData.influcedName;
$item("#motivationText").value = itemData.motivationText;
$item("#influencerLanguage").text = itemData.influencerLanguage;
$item("#amountFollowers").value = parseInt(itemData.amountFollowers,10)
$item("#age").text = (itemData.age).toString(10);
$item("#gender").text = itemData.gender;
$item("#statistics").target = "_blank"
$item("#statistics").link = itemData.statistics;
if (itemData.personalId === null || itemData.personalId === undefined){
$item("#idCard").collapse()
$item("#personalId").collapse()
}else {
$item("#personalId").src = itemData.personalId;
}
$item("#address").text = itemData.address;
if (itemData.addressLine2 === null || itemData.addressLine2 === undefined) {
$item("#addressline2").collapse()
}else{
$item("#addressline2").text = itemData.addressLine2
}
$item("#zipCode").text = itemData.zipCode;
$item("#city").text = itemData.city;
$item("#country").text = itemData.country;
if (itemData.state === null || itemData.state === undefined) {
$item("#state").collapse()
}else
{$item("#state").text = itemData.state}
if (itemData.influencerImage === null || itemData.influencerImage === undefined) {
$item("#influencerImage").collapse()
}else{
$item("#influencerImage").src = itemData.influencerImage
}
/*
$item("#img").onClick( (event) => {
let $item = $w.at(event.context);
$item("#campaignID").text = "Selected";
}); */
//----------- #5 THIS IS NOT THE RECOMMENDED WAY TO WRITE A REPEATER EVENT HANDLER ---//
// To make your code easier to read and debug you should define your event handlers //
// Outside of the repeater and use the $w form. Again you are using $item which has //
// scope above and redeclaring it below in the handler. This is probably giving you //
// Errors in the Corvid editor. Try to Take all of your $item().onCLick() handlers out//
// of this repeater block and declare them as $w() e.g. $w("#acceptBtn").onClick... //
// The $item code is correctly being set using $w.at() and is why you should do this. //
$item("#acceptBtn").onClick( (event) => {
let $item = $w.at(event.context);
let updateData = allApplicationDetails[$item("#rowIDX").value]
repeater_data.splice(row_i,1)
delete updateData._owner
delete updateData._createdDate
delete updateData._updatedDate
updateData.status = "accepted"
//console.log($item("#rowIDX").value)
//console.log(allApplicationDetails[$item("#rowIDX").value])
wixData.update("applicationCollection", updateData)
.then(() => {
$item("#acceptedBox").show("fade",{"duration":300})
});
})
$item("#rejectBtn").onClick( (event) => {
let $item = $w.at(event.context);
let updateData = allApplicationDetails[$item("#rowIDX").value]
repeater_data.splice(row_i,1)
delete updateData._owner
delete updateData._createdDate
delete updateData._updatedDate
updateData.status = "rejected"
//console.log($item("#rowIDX").value)
//console.log(allApplicationDetails[$item("#rowIDX").value])
wixData.update("applicationCollection", updateData)
.then(() => {$item("#rejectedBox").show("fade",{"duration":300})})
});
/* $w("#statistics").onClick( (event) => {
let $item = $w.at(event.context);
winLocation.to($item("#statistics").text)
}); */
$w("#idCard").onClick( (event) => {
let $item = $w.at(event.context);
if($item("#personalId").collapsed === true) {
$item("#personalId").expand();
}else {
$item("#personalId").collapse();
}
});
});
})
})
$w("#repeater1").show()
});