GithubHelp home page GithubHelp logo

bepsik777 / shopping-cart Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 2.48 MB

Shopping cart made with react

Home Page: https://shopping-cart-nu-sand.vercel.app/

JavaScript 98.40% HTML 1.37% CSS 0.22%

shopping-cart's Introduction

Welcom to my mock shopping cart!

This is a project from theodinproject.com [https://www.theodinproject.com/lessons/node-path-react-new-shopping-cart]

In this project, i practiced a bunch of new skills all based around React.

The tools i have used:

  • React as the main UI library
  • react-router to create a SPA
  • vitest and react-testing-library for unit testing
  • Mock Service Worker for intercepting requests and mocking responses
  • propTypes for type checking

preview: Alt text

Alt text

Alt text

The design is very raw, but i may revisit this app when i will create my portfolio. It was a lot of fun. I had the most trouble with proper testing, but at the end i managed to resolve them. More in debth overview of problems i stumbled upon can be found below.

TO DO:

  • Finish constructing layout (Cart.jsx) with fake data DONE
  • Find all the states of the app and where they live DONE
  • fetch the data from external api DONE
  • implement the different states and pass the props DONE
  • Add the remove from cart function in cart.jsx DONE
  • add propTypes DONE
  • test DONE
  • create an error page DONE
  • finish styling DONE

TO DO WHEN REVISIT:

  • Improve design
  • Add localStorage
  • Find an API with more concise products? (like bestbuy for example)
  • Add search by category
  • Enabling removing from cart specific amount of items
  • Create a search option and a search bar?

to fix:

  • Fix amount showing more then 2 numbers after 0

Layout creation:

  • So i tried for the first time to use tailwind in my project. I really liked how fast you can prototype the layout.
  • What i didn't liked was how difficult it is to debug it. you just have a forest of html tags, with no meaningful names, especially when it is just a container. To find the one with the rules i wanted to change was very difficult.
  • Which leads me to my main epiphany: DON'T USE FIXED WIDTH AND HEIGHT (or max/min sizes) UNLESS YOU HAVE TO. and certainly not for creating the first layout. It was super difficult to debug the ItemCard.jsx for me, because of that, at the end i had to rewrite all the stylings from scratch, because i could't figure out which rules break the layout. When i re-wrote it without fixed sizes, it went really smoothly. At the end i used fixed sizes for the desktop layout implementation. Whenever you can, use padding and margin instead, as they are fully responsive.

Testing:

  • One of the first issues i encountered, is that i cannot use any network requests (like fetch) in vitest (At the beginning i didn't understand that it was due to the fact vitest run in node, so i freaked out like hell). After some research and going through other people submission, i found out about mswjs, and thus this is what i will try to implement. As for now, when i try to test the App.jsx component to check if 'I am Home' heading is present, i receive an error and the default react router error page is rendered

  • Another question i want to tackle, is how to pass mock data to the outlet element of react router

  • And also i want to understand how to use MemoryRouter, and how to test an app build with React Router

  • So at the end, i learned to use mswjs to intercept network requests and mock responses. It was quite complicated to me (i think it is because i don't really understand how requests and servers work)

  • But i managed to implement it in my unit tests. I run into a lot of issues, particularly when testing confitional rendering based on state changing right after the fetch request.

  • But now it works! I really learned a lot. I have an impression, that mocking libraries and external API's is a really great way to get a better understanding of those tools.

shopping-cart's People

Contributors

bepsik777 avatar

Watchers

 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.