Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request to make a code review #1

Open
wants to merge 63 commits into
base: release_1
Choose a base branch
from
Open

Pull request to make a code review #1

wants to merge 63 commits into from

Conversation

KhristenkoE
Copy link
Owner

@KhristenkoE KhristenkoE commented Aug 10, 2022

I finished the project but in the end I had to be faster so there are many things that I would change, or make reusable.
I'm going to shown them here in the format of a code review

@@ -0,0 +1,37 @@
import React from 'react';
import { Route, Routes } from 'react-router-dom';
import BreadcrumbsContextProvider from '../../contexts/BreadcrumbsContext';
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get rid of these hard-to-read and write paths ( ../../someComponent ) you can use aliases (@someComponent). They can be configured in the webpack.config and tsconfig.json for typing to work correctly

list-style: none;
}

.list li {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too good to use specific selectors (like li or li button) because in your jsx you can change the element to div for example, but will forget to change it here.

const { breadcrumbs } = useContext(BreadcrumbsContext);
const navigate = useNavigate();

const onBreadcrumbClick = (url: string, index: number) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index is not used

<ul className={styles.list}>
{breadcrumbs.map(({ url, name }, index) => (
<li key={index}>
<button className={index === breadcrumbs.length - 1 ? styles.breadcrumbActive : ''} onClick={() => onBreadcrumbClick(url, index)}>{name}</button>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this libraries like "class names" can be used https://www.npmjs.com/package/classnames

filterContainerRef.current = document.getElementById('filters-block');
}, []);

const onChangeSelect = (value: string, name: string, type: FilterType) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line: 29, 33, 37 - not required function mapping.

<li className={styles.filter} key={label}>
<label htmlFor={label}>{name}</label>
{type === FilterType.SELECT_ONE && (
<FilterSelect initialValue={(intialAppliedFilters[label] || 'All') as string} onChange={(value) => onChangeSelect(value, label, FilterType.SELECT_ONE)} name={label} options={options} />
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line: 54, 57 "magic numbers", What are 'All' and '' and why are they the initial values? - these things need to be in constants

import { AppliedFilter, Filter } from '../interfaces/Filter';

export interface FiltersContext {
transactionFilters: Filter[];
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe transactionFilters, and appliedTransactionFilters can be one entity?

const { cards, cardsFilters} = useContext(DataContext);
const { appliedCardFilters, setAppliedCardFilters } = useContext(FiltersContext);
const [page, setPage] = useState(1);
const filteredCards = useMemo(() => (cards.filter((card) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filtration logic should not be in the component but in a separate file

}
)})), [transactions, appliedTransactionFilters]);

const updateFilters = (value: string | { min: number, max: number }, name: FilterName) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic duplication with CardsList, should be in a separate file, and imported in theses components

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant