Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiYelieva committed Aug 2, 2023
1 parent 5625918 commit f0fa843
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';

import './App.scss';

import { GoodsList } from './GoodsList';
import { GoodsList } from './types/components/GoodsList';

import {
get5First,
Expand Down
8 changes: 6 additions & 2 deletions src/api/goods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ export function getAll(): Promise<Good[]> {

export const get5First = (): Promise<Good[]> => {
return getAll()
.then(goods => goods.slice(0, 5)); // sort and get the first 5
.then(goods => {
goods.sort((a, b) => a.name.localeCompare(b.name));

return goods.slice(0, 5);
});
};

export const getRedGoods = (): Promise<Good[]> => {
return getAll()
.then(goods => goods.filter(item => item.color === 'red')); // get only red
.then(goods => goods.filter(item => item.color === 'red'));
};
11 changes: 8 additions & 3 deletions src/GoodsList.tsx → src/types/components/GoodsList.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React from 'react';
import { Good } from './types/Good';

import { Good } from '../Good';

type Props = {
goods: Good[]
goods: Good[];
};

export const GoodsList: React.FC<Props> = ({ goods }) => (
<ul>
{goods.map(good => (
<li key={good.id} data-cy="good">
<li
key={good.id}
data-cy="good"
style={{ color: good.color }}
>
{good.name}
</li>
))}
Expand Down

0 comments on commit f0fa843

Please sign in to comment.