Pythonidaer / reddie

React app for saving and retrieving Reddit comments.
0 stars 1 forks source link

typewriterSubreddits need to be randomized #19

Closed Pythonidaer closed 1 year ago

Pythonidaer commented 1 year ago

Here are some of the top ten subreddits that appear in the same order every time for the typewriter component:

It is apparent that (Home being the top) the fetched list is ordered by most popular. However, it would make for a better experience, perhaps, if there wasn't always such a guarantee to see subreddits such as these in the first few instances.

It might be better to have this completely randomized, so that the typewriter placeholder text is searching through the 4,000+ subreddits without preference to "most popular".

For example, here are some of the lower ranked subreddits people might happily stumble upon:

Pythonidaer commented 1 year ago
async function getAllSubreddits() {
  let subreddits = [];
  let afterKey = null;
  while (true) {
    let url = `https://www.reddit.com/subreddits.json?limit=25`;
    if (afterKey) {
      url += `&after=${afterKey}`;
    }
    const response = await fetch(url);
    const json = await response.json();
    const children = json.data.children;
    if (children.length === 0) {
      break;
    }
    subreddits.push(...children.map((child) => child.data.display_name));
    afterKey = children[children.length - 1].data.name;
  }
  return subreddits;
}

getAllSubreddits().then(subreddits => console.log(subreddits));

This is the code I used to get the subreddits