-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added comment form in article page; profiles pages
- Loading branch information
Showing
32 changed files
with
363 additions
and
81 deletions.
There are no files selected for viewing
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
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
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
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,2 @@ | ||
export { AddCommentFormSchema } from './model/types/addCommentForm'; | ||
export { AddCommentFormAsync as AddCommentForm } from './ui/AddCommentForm/AddCommentForm.async'; |
4 changes: 4 additions & 0 deletions
4
src/features/AddCommentForm/model/selectors/addCommentFormSelectors.ts
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,4 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
|
||
export const getAddCommentFormText = (state: StateSchema) => state.addCommentForm?.text; | ||
export const getAddCommentFormError = (state: StateSchema) => state.addCommentForm?.error; |
31 changes: 31 additions & 0 deletions
31
src/features/AddCommentForm/model/slice/addCommentFormSlice.ts
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,31 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
import { AddCommentFormSchema } from '../types/addCommentForm'; | ||
|
||
const initialState: AddCommentFormSchema = { | ||
error: '', | ||
text: '', | ||
}; | ||
|
||
export const addCommentFormSlice = createSlice({ | ||
name: 'addCommentForm', | ||
initialState, | ||
reducers: { | ||
setText: (state, action: PayloadAction<string>) => { | ||
state.text = action.payload; | ||
}, | ||
}, | ||
extraReducers: (builder) => { | ||
// builder.addCase(_.pending, (state) => { | ||
// state.error = undefined; | ||
// }) | ||
// .addCase(_.fulfilled, (state) => { | ||
// | ||
// }) | ||
// .addCase(_.rejected, (state, action) => { | ||
// state.error = action.payload; | ||
// }); | ||
}, | ||
}); | ||
|
||
export const { actions: addCommentFormActions } = addCommentFormSlice; | ||
export const { reducer: addCommentFormReducer } = addCommentFormSlice; |
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,4 @@ | ||
export interface AddCommentFormSchema { | ||
text?: string; | ||
error?: string; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/features/AddCommentForm/ui/AddCommentForm/AddCommentForm.async.ts
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,7 @@ | ||
import { FC, lazy } from 'react'; | ||
import { AddCommentFormProps } from './AddCommentForm'; | ||
|
||
// eslint-disable-next-line no-return-await | ||
export const AddCommentFormAsync = lazy<FC<AddCommentFormProps>>(async () => await new Promise((resolve) => { | ||
setTimeout(() => { resolve(import('./AddCommentForm')); }, 1500); | ||
})); |
7 changes: 7 additions & 0 deletions
7
src/features/AddCommentForm/ui/AddCommentForm/AddCommentForm.module.scss
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,7 @@ | ||
.AddCommentForm { | ||
border: 1px solid var(--primary-color); | ||
padding: 10px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} |
53 changes: 53 additions & 0 deletions
53
src/features/AddCommentForm/ui/AddCommentForm/AddCommentForm.tsx
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,53 @@ | ||
import { classNames } from 'shared/lib/classNames/classNames'; | ||
import { memo, useCallback } from 'react'; | ||
import { Input } from 'shared/ui/Input/Input'; | ||
import { Button, ButtonTheme } from 'shared/ui/Button/Button'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useSelector } from 'react-redux'; | ||
import { useAppDispatch } from 'shared/lib/hooks/useAppDispatch/useAppDispatch'; | ||
import { DynamicModuleLoader, ReducersList } from 'shared/lib/components/DynamicModuleLoader/DynamicModuleLoader'; | ||
import { addCommentFormActions, addCommentFormReducer } from '../../model/slice/addCommentFormSlice'; | ||
import { | ||
getAddCommentFormError, | ||
getAddCommentFormText, | ||
} from '../../model/selectors/addCommentFormSelectors'; | ||
import cls from './AddCommentForm.module.scss'; | ||
|
||
const reducers: ReducersList = { | ||
addCommentForm: addCommentFormReducer, | ||
}; | ||
export interface AddCommentFormProps { | ||
className?: string; | ||
onSendComment: (text: string) => void | ||
} | ||
|
||
const AddCommentForm = memo((props: AddCommentFormProps) => { | ||
const { | ||
className, | ||
onSendComment, | ||
} = props; | ||
|
||
const { t } = useTranslation(); | ||
const text = useSelector(getAddCommentFormText); | ||
const dispatch = useAppDispatch(); | ||
|
||
const onCommentTextChange = useCallback((text: string) => { | ||
dispatch(addCommentFormActions.setText(text)); | ||
}, [dispatch]); | ||
|
||
const onSendHandler = useCallback(() => { | ||
onSendComment(text || ''); | ||
onCommentTextChange(''); | ||
}, [onCommentTextChange, onSendComment, text]); | ||
|
||
return ( | ||
<DynamicModuleLoader reducers={reducers}> | ||
<div className={classNames(cls.AddCommentForm, {}, [className])}> | ||
<Input value={text} onChange={onCommentTextChange} placeholder={t('Ваш комментарий')} /> | ||
<Button onClick={onSendHandler} className={className} theme={ButtonTheme.SUBMIT}>{t('Отправить')}</Button> | ||
</div> | ||
</DynamicModuleLoader> | ||
); | ||
}); | ||
|
||
export default AddCommentForm; |
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
Oops, something went wrong.
fdda5bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
social-media-ndg8 – ./
social-media-ndg8-yaazzik.vercel.app
social-media-ndg8.vercel.app
social-media-ndg8-git-master-yaazzik.vercel.app
www.xn--90aeezcbq.xn--p1ai
xn--90aeezcbq.xn--p1ai