Skip to content

Commit

Permalink
feat: add memo for components \ profile page folders
Browse files Browse the repository at this point in the history
  • Loading branch information
TomatoVan committed Nov 27, 2023
1 parent 3b0a9e4 commit fa14912
Show file tree
Hide file tree
Showing 104 changed files with 264 additions and 80 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .loki/reference/chrome_iphone7_pages_NotFoundPage_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_pages_NotFoundPage_Normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_AppLink_Primary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_AppLink_Primary_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_AppLink_Red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_AppLink_Red_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_AppLink_Secondary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Button_Clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Button_Clear_Inverted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Button_Disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Button_Outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Button_Outline_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Button_Primary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Button_Square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Button_Square_L.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Button_Square_M.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Button_Square_XL.png
Binary file modified .loki/reference/chrome_iphone7_shared_Input_Primary.png
Binary file modified .loki/reference/chrome_iphone7_shared_Loader_Dark.png
Binary file modified .loki/reference/chrome_iphone7_shared_Loader_Normal.png
Binary file modified .loki/reference/chrome_iphone7_shared_Modal_Dark.png
Binary file modified .loki/reference/chrome_iphone7_shared_Modal_Primary.png
Binary file modified .loki/reference/chrome_iphone7_shared_ThemeSwitcher_Dark.png
Binary file modified .loki/reference/chrome_iphone7_shared_ThemeSwitcher_Normal.png
Binary file modified .loki/reference/chrome_iphone7_widget_ErrorPage_Dark.png
Binary file modified .loki/reference/chrome_iphone7_widget_ErrorPage_Light.png
Binary file modified .loki/reference/chrome_iphone7_widget_Sidebar_Dark.png
Binary file modified .loki/reference/chrome_iphone7_widget_Sidebar_Light.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file modified .loki/reference/chrome_laptop_pages_NotFoundPage_Dark.png
Binary file modified .loki/reference/chrome_laptop_pages_NotFoundPage_Normal.png
Binary file modified .loki/reference/chrome_laptop_shared_AppLink_Primary.png
Binary file modified .loki/reference/chrome_laptop_shared_AppLink_Primary_Dark.png
Binary file modified .loki/reference/chrome_laptop_shared_AppLink_Red.png
Binary file modified .loki/reference/chrome_laptop_shared_AppLink_Red_Dark.png
Binary file modified .loki/reference/chrome_laptop_shared_AppLink_Secondary.png
Binary file modified .loki/reference/chrome_laptop_shared_AppLink_Secondary_Dark.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Clear.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Clear_Inverted.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Disabled.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Outline.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Outline_Dark.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Outline_Size_L.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Outline_Size_XL.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Primary.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Square.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Square_L.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Square_M.png
Binary file modified .loki/reference/chrome_laptop_shared_Button_Square_XL.png
Binary file modified .loki/reference/chrome_laptop_shared_Input_Primary.png
Binary file modified .loki/reference/chrome_laptop_shared_Loader_Dark.png
Binary file modified .loki/reference/chrome_laptop_shared_Loader_Normal.png
Binary file modified .loki/reference/chrome_laptop_shared_Modal_Dark.png
Binary file modified .loki/reference/chrome_laptop_shared_Modal_Primary.png
Binary file modified .loki/reference/chrome_laptop_shared_ThemeSwitcher_Dark.png
Binary file modified .loki/reference/chrome_laptop_shared_ThemeSwitcher_Normal.png
Binary file modified .loki/reference/chrome_laptop_widget_ErrorPage_Dark.png
Binary file modified .loki/reference/chrome_laptop_widget_ErrorPage_Light.png
Binary file modified .loki/reference/chrome_laptop_widget_Sidebar_Dark.png
Binary file modified .loki/reference/chrome_laptop_widget_Sidebar_Light.png
1 change: 1 addition & 0 deletions extractedTranslations/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"PROFILE PAGE": "",
"auth_form": "",
"auth_password": "",
"auth_username": "",
Expand Down
11 changes: 10 additions & 1 deletion json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
"password": "123"
}
],
"profile": { "name": "typicode" }
"profile": {
"first": "Тимур",
"lastname": "Ульби",
"age": 22,
"currency": "RUB",
"country": "Russia",
"city": "Moscow",
"username": "admin",
"avatar": "https://pic.rutubelist.ru/user/3b/27/3b2758ad5492a76b578f7ee072e4e894.jpg"
}
}

2 changes: 2 additions & 0 deletions src/app/providers/StoreProvider/config/StateSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
AnyAction, EnhancedStore, Reducer, ReducersMapObject,
} from '@reduxjs/toolkit';
import { CombinedState } from 'redux';
import { ProfileSchema } from 'entities/Profile';

export interface StateSchema {
counter: CounterSchema;
user: UserSchema;
// Асинхронные редюсеры
loginForm?: LoginSchema;
profile?: ProfileSchema
}

export type StateSchemaKey = keyof StateSchema;
Expand Down
3 changes: 3 additions & 0 deletions src/entities/Profile/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { Profile, ProfileSchema } from './model/types/profile';

export { profileActions, profileReducer } from './model/slice/profileSlice';
18 changes: 18 additions & 0 deletions src/entities/Profile/model/slice/profileSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createSlice } from '@reduxjs/toolkit';
import { ProfileSchema } from '../types/profile';

const initialState: ProfileSchema = {
readonly: true,
data: undefined,
error: undefined,
isLoading: false,
};

export const profileSlice = createSlice({
name: 'profile',
initialState,
reducers: {},
});

export const { actions: profileActions } = profileSlice;
export const { reducer: profileReducer } = profileSlice;
19 changes: 19 additions & 0 deletions src/entities/Profile/model/types/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Country, Currency } from 'shared/const/common';

export interface Profile {
'first': string,
'lastname': string,
'age': number,
'currency': Currency,
'country': Country,
'city': string,
'username': string,
'avatar': string
}

export interface ProfileSchema {
data?: Profile;
isLoading: boolean;
error?: string;
readonly: boolean;
}
2 changes: 1 addition & 1 deletion src/pages/AboutPage/ui/AboutPage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from 'shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from 'app/providers/ThemeProvider';
import AboutPage from './AboutPage';
import { AboutPage } from 'pages/AboutPage';

export default {
title: 'pages/AboutPage',
Expand Down
6 changes: 3 additions & 3 deletions src/pages/AboutPage/ui/AboutPage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import React, { memo } from 'react';
import { useTranslation } from 'react-i18next';

const AboutPage = (props: any) => {
const AboutPage = memo((props: any) => {
const { t } = useTranslation('about');

return (
<div>
{t('О сайте')}
</div>
);
};
});

export default AboutPage;
2 changes: 1 addition & 1 deletion src/pages/MainPage/ui/MainPage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from 'shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from 'app/providers/ThemeProvider';
import MainPage from './MainPage';
import { MainPage } from 'pages/MainPage';

export default {
title: 'pages/MainPage',
Expand Down
6 changes: 3 additions & 3 deletions src/pages/MainPage/ui/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import React, { memo } from 'react';
import { useTranslation } from 'react-i18next';

const MainPage = (props: any) => {
const MainPage = memo((props: any) => {
const { t } = useTranslation();

return (
<div>
{t('Главная страница')}
</div>
);
};
});

export default MainPage;
5 changes: 3 additions & 2 deletions src/pages/NotFoundPage/ui/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { classNames } from 'shared/lib/classNames/classNames';
import { useTranslation } from 'react-i18next';
import { memo } from 'react';
import cls from './NotFoundPage.module.scss';

interface NotFoundPageProps {
className?: string;
}

export const NotFoundPage = ({ className }: NotFoundPageProps) => {
export const NotFoundPage = memo(({ className }: NotFoundPageProps) => {
const { t } = useTranslation();
return (
<div className={classNames(cls.NotFoundPage, {}, [className])}>
{t('Страница не найдена')}
</div>
);
};
});
1 change: 1 addition & 0 deletions src/pages/ProfilePage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ProfilePageAsync as ProfilePage } from './ui/ProfilePage.async';
7 changes: 7 additions & 0 deletions src/pages/ProfilePage/ui/ProfilePage.async.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { lazy } from 'react';

export const ProfilePageAsync = lazy(() => new Promise((resolve) => {
// @ts-ignore
// ТАК В РЕАЛЬНЫХ ПРОЕКТАХ НЕ ДЕЛАТЬ!!!!! ДЕЛАЕМ ДЛЯ КУРСА!
setTimeout(() => resolve(import('./ProfilePage')), 1500);
}));
24 changes: 24 additions & 0 deletions src/pages/ProfilePage/ui/ProfilePage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { ThemeDecorator } from 'shared/config/storybook/ThemeDecorator/ThemeDecorator';
import { Theme } from 'app/providers/ThemeProvider';
import ProfilePage from 'pages/ProfilePage/ui/ProfilePage';

export default {
title: 'pages/ProfilePage',
component: ProfilePage,
argTypes: {
backgroundColor: { control: 'color' },
},
} as ComponentMeta<typeof ProfilePage>;

const Template: ComponentStory<typeof ProfilePage> = (args) => <ProfilePage {...args} />;

export const Normal = Template.bind({});
Normal.args = {};
// Normal.decorators = [StoreDecorator({})];

export const Dark = Template.bind({});
Dark.args = {};
// Dark.decorators = [ThemeDecorator(Theme.DARK), StoreDecorator({})];
Dark.decorators = [ThemeDecorator(Theme.DARK)];
27 changes: 27 additions & 0 deletions src/pages/ProfilePage/ui/ProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { classNames } from 'shared/lib/classNames/classNames';
import { useTranslation } from 'react-i18next';
import { memo } from 'react';
import { DynamicModuleLoader, ReducersList } from 'shared/lib/components/DynamicModuleLoared/DynamicModuleLoared';
import { profileReducer } from 'entities/Profile';

const reducers: ReducersList = {
profile: profileReducer,
};

interface ProfilePageProps {
className?: string;
}

const ProfilePage = memo(({ className }: ProfilePageProps) => {
const { t } = useTranslation();
return (
<DynamicModuleLoader reducers={reducers} removeAfterUnmount>
<div className={classNames('', {}, [className])}>
{t('PROFILE PAGE')}
</div>
</DynamicModuleLoader>

);
});

export default ProfilePage;
3 changes: 3 additions & 0 deletions src/shared/assets/icons/profile-20-20.svg
9 changes: 8 additions & 1 deletion src/shared/config/routeConfig/routeConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import { RouteProps } from 'react-router-dom';
import { MainPage } from 'pages/MainPage';
import { AboutPage } from 'pages/AboutPage';
import { NotFoundPage } from 'pages/NotFoundPage';
import { ProfilePage } from 'pages/ProfilePage';

export enum AppRoutes {
MAIN = 'main',
ABOUT = 'about',
PROFILE = 'profile',
NOT_FOUND = 'not_found',
}

export const RoutePath: Record<AppRoutes, string> = {
[AppRoutes.MAIN]: '/',
[AppRoutes.ABOUT]: '/about',
// последний
[AppRoutes.PROFILE]: '/profile',
[AppRoutes.NOT_FOUND]: '*',
};

Expand All @@ -25,8 +27,13 @@ export const routeConfig: Record<AppRoutes, RouteProps> = {
path: RoutePath.about,
element: <AboutPage />,
},
[AppRoutes.PROFILE]: {
path: RoutePath.profile,
element: <ProfilePage />,
},
[AppRoutes.NOT_FOUND]: {
path: RoutePath.not_found,
element: <NotFoundPage />,
},

};
2 changes: 2 additions & 0 deletions src/shared/config/storybook/StoreDecorator/StoreDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { Story } from '@storybook/react';
import { StateSchema, StoreProvider } from 'app/providers/StoreProvider';
import { DeepPartial, ReducersMapObject } from '@reduxjs/toolkit';
import { loginReducer } from 'features/AuthByUsername/model/slice/loginSlice';
import { profileReducer } from 'entities/Profile';

const defaultAsyncReducers: DeepPartial<ReducersMapObject<StateSchema>> = {
loginForm: loginReducer,
profile: profileReducer,
};

export const StoreDecorator = (
Expand Down
13 changes: 13 additions & 0 deletions src/shared/const/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export enum Currency {
"RUB" = "RUB",
"EUR" = "EUR",
"USD" = "USD",
}

export enum Country {
Russia = 'Russia',
Belarus = 'Belarus',
Ukraine = 'Ukraine',
Kazakhstan = 'Kazahstan',
Armenia = 'Armenia',
}
13 changes: 7 additions & 6 deletions src/shared/ui/AppLink/AppLink.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { classNames } from 'shared/lib/classNames/classNames';
import { Link, LinkProps } from 'react-router-dom';
import { FC } from 'react';
import { memo, ReactNode } from 'react';
import cls from './AppLink.module.scss';

export enum AppLinkTheme {
PRIMARY = 'primary',
SECONDARY = 'secondary',
RED = 'red',
PRIMARY = 'primary',
SECONDARY = 'secondary',
RED = 'red',
}

interface AppLinkProps extends LinkProps {
className?: string;
theme?: AppLinkTheme;
children?: ReactNode
}

export const AppLink: FC<AppLinkProps> = (props) => {
export const AppLink = memo((props: AppLinkProps) => {
const {
to,
className,
Expand All @@ -32,4 +33,4 @@ export const AppLink: FC<AppLinkProps> = (props) => {
{children}
</Link>
);
};
});
9 changes: 6 additions & 3 deletions src/shared/ui/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { classNames } from 'shared/lib/classNames/classNames';
import { ButtonHTMLAttributes, FC } from 'react';
import {
ButtonHTMLAttributes, FC, memo, ReactNode,
} from 'react';
import cls from './Button.module.scss';

export enum ButtonTheme {
Expand All @@ -22,9 +24,10 @@ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>{
square?: boolean;
size?: ButtonSize;
isDisabled?: boolean;
children?: ReactNode;
}

export const Button: FC<ButtonProps> = (props) => {
export const Button = memo((props: ButtonProps) => {
const {
className,
children,
Expand Down Expand Up @@ -56,4 +59,4 @@ export const Button: FC<ButtonProps> = (props) => {
{children}
</button>
);
};
});
6 changes: 3 additions & 3 deletions src/shared/ui/LangSwitcher/LangSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { classNames } from 'shared/lib/classNames/classNames';
import { useTranslation } from 'react-i18next';
import React from 'react';
import React, { memo } from 'react';
import { Button, ButtonTheme } from 'shared/ui/Button/Button';

interface LangSwitcherProps {
className?: string;
short?: boolean;
}

export const LangSwitcher = ({ className, short }: LangSwitcherProps) => {
export const LangSwitcher = memo(({ className, short }: LangSwitcherProps) => {
const { t, i18n } = useTranslation();

const toggle = async () => {
Expand All @@ -24,4 +24,4 @@ export const LangSwitcher = ({ className, short }: LangSwitcherProps) => {
{t(short ? 'Короткий язык' : 'Язык')}
</Button>
);
};
});
5 changes: 3 additions & 2 deletions src/shared/ui/Text/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { classNames } from 'shared/lib/classNames/classNames';
import { memo } from 'react';
import cls from './Text.module.scss';

export enum TextTheme {
Expand All @@ -14,7 +15,7 @@ interface TextProps {
theme?: TextTheme;
}

export const Text = (props: TextProps) => {
export const Text = memo((props: TextProps) => {
const {
className,
text,
Expand All @@ -28,4 +29,4 @@ export const Text = (props: TextProps) => {
{text && <p className={cls.text}>{text}</p>}
</div>
);
};
});
Loading

0 comments on commit fa14912

Please sign in to comment.