Giter Site home page Giter Site logo

star-wars-list's Introduction

Star Wars List

Description

This app provides data of star wars characters. Users can filter/sort the characters list.

Purpose

  • Deepening my understanding of TypeScript
  • Getting used to writing tests with React Testing Library
  • Try CI/CD cycle with Hunsky and Github Action

Stack

  • TypeScript
  • React
  • RTK Query
  • Chakura UI
  • React Testing Library

Plan Overview: https://www.notion.so/My-Review-Project-Plan-Overview-710006b226924a778071f5adabe32c25>
Story: My First TypeScript Project: Tips from 'Learning TypeScript'

star-wars-list's People

Contributors

lada496 avatar

Watchers

 avatar

star-wars-list's Issues

abstract this function at a higher level

          It's better for you to abstract this function at a higher level as you have assigned `BrowserRouter` in multiple places too. Prob you can even combine this with Redux's `<Provider />` as well so that you won't need to invoke different functions on each test cases

Originally posted by @kei95 in #29 (comment)

put lines b/w code snippet

          I found some codes are too to each other that it's harming readability a bit. For these lines case, prob you can do like;
        const newRenderedCharacters = [...state.renderedCharacters]
        sort(newRenderedCharacters, action.sortFactor)
        
        return {
          ...state,
          renderedCharacters: newRenderedCharacters,
          sortFactor: action.sortFactor,
        }
      }
      
      const homelandTarget = state.filterTargets.homelandTarget
      const genderTarget = state.filterTargets.genderTarget
      let newRenderedCharacters = state.originalCharacters

Originally posted by @kei95 in #34 (comment)

re-think folder structure where to put redux related types

    using a name "index" for this file is a bit too vague. You are not using an index export pattern and this file contains types for API response shape so I'd say it makes more sense to be under `/api`. Be careful of using `index-` for file name as it easily contaminates your project coz they are all the same name so the more you name files `index-` the less searchability your project has.

Originally posted by @kei95 in #2 (comment)

set custom color theme

Previous design:
Navigation and other components use different blacks
Screenshot 2023-04-01 at 18 42 35

After fix:
Use the same black:
Screenshot 2023-04-01 at 18 45 38

make a custom hook by extracting the logic

    > I'd love to receive a feedback in AllSpecies.tsx. Especially I want to know where is the good place to put reducer functions.

I wouldn't mind having this reducer logic in this file as it's small enough and encapsulated in this domain. Though it's ok to leave them here, if you don't feel comfortable leaving them in this file then I'd advise you to make a custom hook by extracting the logic so that you can separate the logic part of this file and render part of it. It could be called something like; useSortCharacters

Originally posted by @kei95 in #23 (comment)

I prefer to generate a new array before execute `sort()`. I notice you understand that `sort()` is destructive and you pass a new array in some conditions. But, you sometimes assign a reference to a variable, for example, line 159 `let newRenderedCharacters = state.originalCharacters`. So far you can manage them but it may be confusing if another dev needs to modify.

          I prefer to generate a new array before execute `sort()`. I notice you understand that `sort()` is destructive and you pass a new array in some conditions. But, you sometimes assign a reference to a variable, for example, line 159 `let newRenderedCharacters = state.originalCharacters`. So far you can manage them but it may be confusing if another dev needs to modify.

Originally posted by @koh1project in #34 (comment)

setting up a github action

    @Lada496 Now that you have quite a decent testing coverage for your project, do you wanna try setting up a github action to run unit/integration tests upon each push on all branches? It's important to automate tests so that you won't need to run them locally and that results in preventing your teammates to be pushing untested broken code by accident since the automation runs and tells its result no matter what.

Originally posted by @kei95 in #10 (comment)

re-think folder structure where to put api related functions

    This file can be under an independent `api` folder rather than util since you will have more logics that are tightly coupled with an API request/response treatment. `utils` get big and messy so try to avoid using this folder as much as you can by coupling some files under a single folder.

The following link is for an article that is about file structure for react project. Ngl I doesn't fully agree with it(especially its usage of test and util) but it generally makes sense. You might wanna casually check on API folder to see what it would look like.

https://dev.to/larswaechter/how-i-structure-my-react-projects-jii

Originally posted by @kei95 in #2 (comment)

create error card component

          Is this TODO comment still relevant? ๐Ÿ‘€ If so, might be better to mention when to fix as TODO comments can be abandoned quite quickly. The most common way to do so is to mention the ticket that fixes it. If you don't have one, create it so that it's forcing you to at least have some ticket to work on in the future. It's better for other developers who don't have context too.

Originally posted by @kei95 in #34 (comment)

put this under API folder

    Might be better to put this under API folder as it's the closest place that the original value(the type definition and the logic to retrieve this data in this case).

Originally posted by @kei95 in #10 (comment)

set tile file under the same level of original implementation

    I'd personally prefer to set tile file under the same level of original implementation such as below;
// no need for tests folder
CharacterDetails.tsx
CharacterDetails.test.tsx
CharacterItem.tsx
CharacterItem.test.tsx
[...]

And the mock data can be close to where its original value is defined. In this case, you can declare modifiedCaracter(mocks/modifiedCharacters.tsx) under API folders as that's where you define it.

Originally posted by @kei95 in #10 (comment)

fix the file structure

  1. I found that the file structure is a bit odd. Currently, pretty much all the UI files are under components/ but there're multiple files that are mentally bigger than "components" such as AllSpecies.tsx. For such a file, you might want to have page folder and you can put AllSpecies.tsx and SpeciesItem.tsx. Also, UI folder can be de-structured and put on the same level as other components. Something like the following image is what I mean, but we can have a quick call to go over this structure once you are back from Japan ๐Ÿ™‚

Screenshot 2023-03-10 at 12 13 31 AM

Originally posted by @kei95 in #53 (comment)

narrow this type to a union of string literals

    I think you can narrow this type to a union of string literals. In this use case, you know the selected value is always either `height` or `mass`, so I'd recommend you create an enumerator-like object so that you can couple all the logic looking at the single source of truth. This is phenomenally effective when all the logic is based on a single factor/domain. In this case, we know they all are trying to "sort" characters with these keys, so it's ok to couple them together to look at the single place. 

This is just a pseudo code so don't count on it lol but I hope you get the idea.

// enum like object - make sure to leave a comment about why you use this object as it has multiple dependencies. 
// Means that a single change on this object can cause a big mess 
const SORT_FACTOR = {
  MASS: "mass",
  HEIGHT: "height",
  DEFAULT: "default" // you might not need this value
} as cosnt

// "mass" | "height" | "default"
type SortFactor = typeof SORT_FACTOR[keyof typeof SORT_FACTOR]

type CharacterState = {
  originalCharacters: ModifiedCharacter[]
  modifiedCharacters: ModifiedCharacter[]
  selectedValue: SortFactor // here, you narrowed the type from "string" to "mass" | "height" | "default"
}

// this function now can accept "mass" | "height" | "default". You might want to handle the case "default" explicitly
const sort = (characters: ModifiedCharacter[], key: SortFactor) =>
  characters.sort((a, b) => (b[key] || 0) - (a[key] || 0))

[...]

{
    Object.keys(SORT_FACTOR).map(sortFactorKey => (
        // You might need some logic or CSS trick to change the value to the title case
        <option value={SORT_FACTOR[sortFactorKey]}>{SORT_FACTOR[sortFactorKey]}</option>
     ))
}

Originally posted by @kei95 in #23 (comment)

create loading component

          Is this TODO comment still relevant? ๐Ÿ‘€ If so, might be better to mention when to fix as TODO comments can be abandoned quite quickly. The most common way to do so is to mention the ticket that fixes it. If you don't have one, create it so that it's forcing you to at least have some ticket to work on in the future. It's better for other developers who don't have context too.

Originally posted by @kei95 in #34 (comment)

name more explicitly

          [nitpick] - It might be better to rename this variable, as `value` is a bit too generic. Other devs might think; _"What kind of value do you mean?"_

Originally posted by @kei95 in #34 (comment)

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.