-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from Studio-Yandex-Practicum/development-195-…
…category-list-api development-195-category-list-api
- Loading branch information
Showing
11 changed files
with
83 additions
and
30 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ | |
margin-bottom: 17px; | ||
margin-left: auto; | ||
margin-right: auto; | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { TCategory } from '@/shared/model/types/CategoryModel' | ||
|
||
import card1 from '../../assets/images/categoryCards/img-categories-01-210x263.webp' | ||
|
||
import { CategoryCard } from './CategoryCard' | ||
|
||
const meta = { | ||
title: 'entities/CategoryCard', | ||
component: CategoryCard | ||
} satisfies Meta<typeof CategoryCard> | ||
} as Meta<typeof CategoryCard> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = { | ||
args: { | ||
src: card1, | ||
name: 'FM-трансмиттеры' | ||
interface CategoryCardArgs { | ||
category: TCategory | ||
} | ||
|
||
export const Default: Story = (args: CategoryCardArgs) => <CategoryCard category={args.category} /> | ||
|
||
Default.args = { | ||
category: { | ||
image: card1, | ||
name: 'FM-трансмиттеры', | ||
slug: 'fm-transmitters' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
import { type FC } from 'react' | ||
import { FC } from 'react' | ||
|
||
import FM from '@/assets/images/categoryPage/FM.webp' | ||
import { TCategory } from '@/shared/model/types/CategoryModel' | ||
import Paragraph from '@/shared/ui/Paragraph/Paragraph' | ||
|
||
import card1 from '../../assets/images/categoryCards/placeholder-1200x800.png' | ||
|
||
import styles from './CategoryCard.module.scss' | ||
|
||
/** | ||
* Карточка категории | ||
*/ | ||
interface CategoryCardProps { | ||
category: TCategory | ||
} | ||
|
||
export const CategoryCard: FC = () => { | ||
export const CategoryCard: FC<CategoryCardProps> = ({ category }) => { | ||
return ( | ||
<div className={styles['category-card']}> | ||
<img src={FM} alt="FM-трансмиттеры" className={styles['category-card__img']} /> | ||
<Paragraph className={styles['category-card__text']}>FM-трансмиттеры</Paragraph> | ||
{category && ( | ||
<> | ||
<img src={category.image || card1} alt={category.name} className={styles['category-card__img']} /> | ||
<Paragraph className={styles['category-card__text']}>{category.name}</Paragraph> | ||
</> | ||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit' | ||
|
||
import { ThunkConfig } from '@/app/providers/StoreProvider/config/StateSchema' | ||
import { apiErrorIdentify } from '@/shared/api/apiErrorIdentify' | ||
import { ApiError, ApiErrorTypes, ApiRoutes } from '@/shared/api/types' | ||
import { ACTION_GET_СATEGORY } from '@/shared/constants/constants' | ||
|
||
import { CategoryInfo } from './types' | ||
|
||
export const getCategoryCard = createAsyncThunk<CategoryInfo, number, ThunkConfig<ApiError>>( | ||
ACTION_GET_СATEGORY, | ||
async (id: number, thunkAPI) => { | ||
const { rejectWithValue, extra } = thunkAPI | ||
try { | ||
const { data } = await extra.api.get(`api/${ApiRoutes.CATEGORIES}`) | ||
return data | ||
} catch (error) { | ||
return rejectWithValue(apiErrorIdentify(error, ApiErrorTypes.DATA_EMPTY_ERROR)) | ||
} | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Тип данных для категории | ||
export interface Category { | ||
id: string | ||
name: string | ||
image: string | ||
} | ||
|
||
export interface CategoryInfo { | ||
name: string | ||
count: number | ||
next: string | ||
previous: string | ||
results: Category[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters