DEV Community

Tuan Thanh Tan
Tuan Thanh Tan

Posted on

OSD600 - Release 0.3 - Second Pull Request

Introduction

Hello everyone, my name is Dustin. Today I'd like to talk about one of my pull requests in Telescope project.

Progress

Instead of choosing another project to work on, I decided to go with Telescope again because why not?. This is also an external project and can compete with other open source projects.

My second pull request was about showing the feeds count on a status report webpage, which is up and running here. If you go to the page, you could see total feeds displaying right there below commit count card.

This issue proposed a lot of problems as this is a completely new feature and nobody has touched the code before.

First, I ran into a problem with base url so I had to disable a couple lines to get it work properly on my local. After solving that problem, I had another one which I was not able to extract x-total-count from header because the posts api didn't expose headers for some reason. In order to get it work, I added cors: { exposedHeaders: ['X-Total-Count', 'Link'] } which basically means expose x-total-count in header so that I can access it.

However, I just saw another potential bug which may happen when someone uses window.onload(), which may be resolved by the time you read this blog, but I'll have a discussion with other people to see how they'd like it to be.

const apiHost = new URL(location).origin;

async function getFeedCount() {
  try {
    const data = await fetch(`${apiHost}/v1/posts/feeds`, {
      method: 'HEAD',
    });
    const feedCount = data.headers.get('x-total-count');
    const feedCountElement = document.getElementById('feeds-count');
    feedCountElement.innerText = feedCount ?? 'N/A';
  } catch (err) {
    console.error(err);
  }
}

window.onload = () => {
  getFeedCount();
};
Enter fullscreen mode Exit fullscreen mode

For the last 3 lines, window.onload() should be changed to window.addEventListener('load') in order that the main window.onload() won't be override accidentally.

Wrap up

This is actually interesting and I've learnt a lot from it. Not only the code I wrote but how an issue, and a pull request on Github will be treated and how to work with Git correctly. Although this is not a big pull request, but I'm proud of what I've done.

Top comments (0)