Coder Social home page Coder Social logo

pomodoro-timer's Introduction

Pomodoro Timer

This is a Next.js project bootstrapped with create-next-app.

Getting Started

  1. Install the dependencies
npm install
  1. Run the development server
npm run dev

Leveraging Generative AI for Code Writing

To implement the circular progress bar feature, I asked ChatGPT for a code snippet. I used the prompt: 'Create an animated circular progress bar with a SVG, without using an external library'. The response provided an accurate SVG element with nested circle elements, which I adapted to fit the style and radius I want. The response also provided the percentage function calculation, which I then adjusted with the variables representing work time or break time"

I then prompted for a more stylized circular progress bar with inner tick lines and labels and rounded circle stroke ends using the prompt: "Add tick lines and labels at intervals (evenly distributed based on time value) to the circular progress bar". It responded with an updated code snippet. I then adjusted various radius values to style it better.

I am new to Chakra UI, so ChatGPT came in handy when i had questions such as "How to implement theming with Chakra UI in a Next.js app?" and "How do use theme colors to have a purple highlight color for the circular progress bar and button?"

I also used ChatGPT to create the Jest test scenarios by creating a prompt listing the app features. The response also included steps on how to set up Jest and configure it. However, I had problems running the test because I was importing a JSX React component into the test file. I resolved it by going to the Next.js with documentation on how to setting up Jest with Next.js. The response output the full test file with 4 test scenarios.

The test "increments cycle count after one complete cycle" failed, though the cycle variable incremented by 1 on the UI when I ran the app. I then prompted ChatGPT on why the test failed along with the error logs and a code snippet of the useEffect hook where the work to break cycle transition takes place. The response suggested that this could be due to a timing issue where the state update for cycles is not happening as expected within the test's timeframe. It suggested that to test the asynchronous updates correctly, I needed to ensure that the assertions account for the updates that happen as a result of the setInterval and the state changes within your component. It suggested:

  • using the waitFor function provided by React Testing Library to wait for the specified condition to be true, repeatedly calling the callback until it is.
  • split the act calls into two separate parts to accurately simulate the timer for both the work and break periods.

Only the last suggestion was required to solve the problem as the act calls should be separate to simulate the passage of time correctly. The test can still pass successfully without using waitFor, because actually the DOM updates immediately when the break session ends to immediately transition the text displaying the cycles from 0 to 1. I think ChatGPT assumed there was asynchronicity involved because the code snippet included 'setTimeout';

pomodoro-timer's People

Contributors

dianaow avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.