Hello folk,
I am working to getting top 3 topics which have most active replies in last 30 days i want to show that topics only and i am customizing in show case category plugin so in js side i have run the below code but seems like its returning in promise…can anybody tell me how can i do this ?
showcased-topic-list.js
this.store.findFiltered("topicList", filter).then((topicList) => {
var idaas = [];
var final_arr = [];
topicList.topics = topicList.topics.forEach(async(t) => {
const response = await ajax(`/t/${t.id}/posts.json`).then(async(result) => {
await result.post_stream.posts.forEach((p) => {
let date1 = new Date();
let date2 = new Date(p.created_at);
let Difference_In_Time = date1.getTime() - date2.getTime();
let Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24);
if(Difference_In_Days <= 30){
idaas.push(result.id);
}
});
return idaas;
});
final_arr.push(response);
});
});
example :
var smallarrq = ['71782', '72307'];
this.set(
"topicList",
topicList.topics.filter((t) => smallarrq.includes(t.id)).slice(0, settings.max_list_length)
);
I want this final_arr array looks like above smallarrq array but its returning as promise.
Please help folks i am doing from many days so
Thank you,