Skip to content

hqz3/fem-interactive-comments-section

Repository files navigation

Frontend Mentor - Interactive comments section solution

This is a solution to the Interactive comments section challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Note: Delete this note and update the table of contents based on what sections you keep.

Overview

The challenge

Users should be able to:

  • View the optimal layout for the app depending on their device's screen size
  • See hover states for all interactive elements on the page
  • Create, Read, Update, and Delete comments and replies
  • Upvote and downvote comments
  • Bonus: If you're building a purely front-end project, use localStorage to save the current state in the browser that persists when the browser is refreshed.
  • Bonus: Instead of using the createdAt strings from the data.json file, try using timestamps and dynamically track the time since the comment or reply was posted.

Screenshot

Mobile

localhost_5173_

Desktop

localhost_5173_ (1)

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • CSS Flexbox
  • CSS Grid
  • Mobile-first workflow
  • TypeScript
  • Object-oriented programming

Notes

This project was well-suited for OOP. In addition to the App class which initiates the application, I also created two classes, Comment and Reply, both of which are essentially the same with some slight differences. Ideally, I could have reused the Comment class recursively to make reply instances but the differences in their respective DOM structures made it tricky to implement. Instead, I created a Post parent class that extends to both the Comment and Reply subclasses.

Using object inheritance helped remove a significant number of properties and methods from the child classes. Most of these properties and methods are either the same or very similar. For the latter case, adding parameters made these methods dynamically reusable. Having a single source of truth kept the code DRY and significantly simplified the process of reading and modifying the code.

Useful resources

  • quicktype - Handy tool to generate all JSON types from data.json.