hellofaizan / xprofile

𝕏 Profile - Twitter Profile Card | List your Twitter Profile
https://x.hellofaizan.tech
MIT License
61 stars 68 forks source link

fix: rendering of duplicate cards #111

Closed Anmol-Baranwal closed 1 year ago

Anmol-Baranwal commented 1 year ago

Closes #90

What does this PR do?

Type of change

Mandatory Tasks

Code

export default function handler(req, res) {
  // read users from a local JSON file
  let users = require("/data/users.json");
  // const numberOfRandomUsers = 12
  const shuffledUsers = shuffleArray(users);

  const numberOfRandomUsers = users.length;
  const count = parseInt(req.query.count || 9);
  const start = parseInt(req.query._start || 0);

  // finding the last index
  const end = Math.min(start + count, numberOfRandomUsers);

  let randomUserSubset = users.slice(start, end);

  if (req.query._start === "undefined") {
    randomUserSubset = shuffledUsers.slice(0, req.query.count);
    res.status(200).json(randomUserSubset);
  } else {
    randomUserSubset = shuffledUsers.slice(req.query._start, req.query.count);
    res.status(200).json(randomUserSubset);
  }
}
vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
xprofile ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 30, 2023 10:32pm
Anmol-Baranwal commented 1 year ago

LOL! I thought, I fixed the issue. I will ask you to review this, once it is fixed.

Anmol-Baranwal commented 1 year ago

@hellofaizan I've fixed the issue. You can review the PR :)

If you need more details about the approach or the code changed, let me know.

hellofaizan commented 1 year ago

Has a look. Looks awesome 👍