CodeNewbie Community 🌱

James Wallis
James Wallis

Posted on • Originally published at wallis.dev on

I made a free Dev.to Posting Streak Calculator using Next.js, Day.js and the Dev.to API

Do you wonder what your current weekly posting streak is?

Originally written for Dev.to. AFAIK CodeNewbie doesn't have writing streak badges. If there is interest it should be pretty easy to extend it to work with the CodeNewbie API as well as Dev.to. Comment below if you want this!

On Monday (12th April 2021), I was awarded the 16-week streak badge. It was a surprise, albeit a welcome one, as I figured that I was two weeks away from writing for sixteen continuous weeks with my first article being published on January 10th, 2021.

This made me think - how does Dev.to calculate the writing streak? Can I build a tool to help fellow Dev.to community members understand if they're on track for their next milestone.

Below you'll find the answers - tl;dr made a tool that's available for anyone to use.

The Dev.to Writing Streak Calculator

I'll demo the app first and further down explain how I calculate the user's current writing streak.



The Writing Streak Calculator

The app is simple by design.

It consists of a single input box for your username and a text box next to it. Once you've entered your username it will calculate your current writing streak and report it back to you (with some text that is borrowed from the Forem codebase).

To build it I used my usual tools with a couple of others:

  • Next.js
  • Tailwind CSS
  • Dev.to API
  • DayJS - Heavily for calculating the streaks
  • SWR - Fetches articles and user data from the Dev.to API
  • Preact - Reduced first load size from 83kB to 49kB (Used for the first time, seems good!)

Source code on GitHub.

That is pretty much it. At this point, there are no overly complicated features. Some things I'd like to add, however, are:

  • Date since last posted
  • Longest writing streak
  • A warning that the user needs to post if they're close to the end-of-week deadline
  • Support other Forem sites (CodeNewbie etc)

Something more you want to see? Add it in the comments or open an issue.

In case you missed it above, here's the link for the tool. Go check out your writing streak!

https://devto-writing-streak-calculator.wallis.dev

How the writing streak is calculated

Prewarning : There is the possibility that I'm calculating it incorrectly. Hopefully, a Forem contributor will call me out and I can correct it! Otherwise, if you think your streak isn't right let me know in the comments or raise an issue on GitHub. That being said, it's correct for me for two separate streaks so I'm confident.

I started by noting when I was awarded the 16 weeks and 4-week badges (I deleted the email for 8 weeks):

  • 4 weeks: Monday 17th August 2020
  • 16 weeks: Monday 12th April 2021

So badges are awarded on Mondays.

Next, I wanted to understand why my streak wasn't broken between the 30th December 2020 (2nd post in the streak) and the 10th January 2021 (3rd post in the streak) - that's an 11 day difference. After searching for missing articles and trying to find reason in the Dev.to Ruby on Rails code, I eventually just checked a calendar.



December 2020 - January 2021. Red circles denote published dates.

It turned out that the 10th January 2021 was the week after the 30th December 2020 when the week starts on a Monday.

So I came to the conclusion that as long as a post is published between Monday and Sunday then the streak would continue!

Here's the link again:

https://devto-writing-streak-calculator.wallis.dev

Summary

I've introduced the writing streak calculator tool made for the Dev.to community.

If you've enjoyed this article or the tool, react!

Let me know your latest streak or any comments down below.

Thanks for reading!

Top comments (5)

Collapse
 
jerr045 profile image
jerr045

That sounds like a useful project! A posting streak calculator can be a motivating tool for developers Basic Fishing Gear who want to maintain consistency in sharing content on platforms like Dev.to.

Collapse
 
jhone55 profile image
Jhone55

That sounds like a useful project! A posting streak calculator can be a motivating tool for developers who want to maintain consistency in sharing content on platforms like Dev.to.

If you'd like to share more details, I'm interested to know:

How does the calculator work?

Does it take inputs like the start date of posting, or does it automatically fetch data from Dev.to to calculate the streak?
What technologies did you use?

You mentioned Next.js, Day.js, and the Dev.to API. How did you integrate these technologies to build the calculator?
Any specific challenges or interesting aspects during the development process?

Were there any hurdles you had to overcome through grade calculator or interesting features you implemented?

Collapse
 
ellativity profile image
Ella (she/her/elle)

This is such a great project, @jameswallis ! Thanks for sharing your process and result with us!

Collapse
 
jameswallis profile image
James Wallis

Thank you! No worries, hopefully you found it somewhat helpful!

Collapse
 
georgebenzy profile image
georgebenzy

That sounds like a useful tool! Sharing GST calculator it with the Dev.to community can help others keep track of their posting streaks more easily. Great work!