Limit items returned by "Repeat with"

Our app let’s users select friends from their phone contacts list.

We’re getting the device’s contacts and saving them as an app variable that we reference in a repeating list.

Small problem: I have almost 800 contacts in my phone, and it takes a loooooong time to load. (Getting the contacts and updating the app variable is almost instantaneous, but rendering the repeated list is slow.) Is it possible to limit the list to show only items 0 to 19 with a “see more” button at the bottom?

Here’s a follow-on question to that:

I implemented a search bar for that list which works swell…except for how long it takes to process a search. Any recommendations on how to make it load faster? (Complete list, partial list, and/or searched list)

Hi @Erin_Wagner

I currently do this using Javascript once the list of data is loaded up in memory.

Takes a few moments to load but once loaded the search is fast.

Here’s some sample code to search an object (inputs.input1) with a search string (inputs.input2). As a bonus, this also sorts the list by name.

const search = new RegExp( inputs.input2,"i");

return { result: Object.entries(inputs.input1)
      .filter( ({ name }) => name.match(search) )            
      .sort(function(a, b) {
          var nameA = a.name.toUpperCase(); // ignore upper and lowercase
          var nameB = b.name.toUpperCase(); // ignore upper and lowercase
          if (nameA < nameB) {
            return -1;
          }
          if (nameA > nameB) {
            return 1;
          }
          // names must be equal
          return 0;
        })
};
2 Likes

Thank you so much, @vereggen!