,

Day

https://github.com/DraconInteractive/Dracon.Frontend.WeatherTodo

Overview

“Day” is a project I have undertaken to expand my frontend abilities, specifically looking at React development.

This ended up being a short and sweet project. I started with the idea of an app you can use to organise your day, but with an extremely simple scope:

  1. View the weather
  2. Interactable Todo list

I’m no stranger to utilising AI coding tools, so in full this ended up taking me no longer than a couple of hours. The largest hurdle here was parsing the generated code and taking what lessons from it that I could.

Creating this blog post has given me a perfect opportunity to break down the implementation of this app to assist in that process.

Installation

The studio runs on a standard Node.JS installation pipeline. Clone the repository, and run npm install. This should install all of the required libraries for it to run.

Once the environment is setup, run npm run dev to begin the app. This will print a local url such as http://localhost:5173 to the console, and it will open a standalone (and resizable) window with the app.

Components

As above, the two major components of this app are the Weather view and the Todo list.

The Weather area is comprised of three (3) components: LocationBar, Metric and WeatherPanel.

Weather Panel

The WeatherPanel is the parent object that contains the LocationBar and Metrics. The LocationBar is responsible for parsing user input containing geolocation, and the WeatherPanel will use that data to fetch location name and weather statistics. This data is displayed, and the Metric component is used for the individual weather statistics such as temp, condition, wind and time of update.

WeatherPanel – Location logic

Formatting adjusted for web display

WeatherPanel – Metric logic

Formatting adjusted for web display

LocationBar

The LocationBar is an input-focused component for the user to enter their location in order for the WeatherPanel to use that to get geolocation.

It consists of a form that uses an injected ‘onPick’ to perform a geo-query hook found in hooks/usePreferredLocation.ts

If the query returns a result, it gets displayed and returned to the WeatherPanel. If not, an error message is displayed based on the query result.

Geolocation Hook

Formatting adjusted for web display

LocationBar Form

Formatting adjusted for web display

Metric

Our final weather component, the Metric component focuses on displaying the four (4) items returned from the geo-location query; Temperature, Condition, Wind and Updated

This component is very simple, and is mostly just used for display purposes.

Metric Function

Formatting adjusted for web display

TodoList

The TodoList component is comparable to the WeatherPanel component in that it contains the primary logic for its functionality set.

The TodoList is comprised of an array of Todo items structured like so:

These items are filtered according to three values, “all”, “active” or “done”.

The functionality is basic, allowing the user to add items, toggle them (aka complete them), remove them and to clear all completed items from the list.

The Todo items and their filters / query has a simple setup:

Note the use of ‘useLocalStorage’. This is a shortcut for a persistence function that uses the key to access the universal localStorage function to store information in a browser. I could have done a backend api to store tasks in, but I felt that was out of scope for this project.

The list manipulation functions all make simple mutations to the setItems array. For example:

Formatting adjusted for web display

Filtering is achieve by a “visible” filter const.

I’m not going to go over the rest of the TodoList here. It’s quite lengthy and almost all focused on display logic rather than mechanics. Feel free to check it out at the repo linked at the top!

Conclusion

Working in the react frontend space is new to me. This project was a great opportunity for exploration, but I have a lot more to learn and I will definitely be heading straight onto something new.

Let me know if you have any suggestions for cool projects!

Leave a comment