-
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.
- Loading branch information
Showing
28 changed files
with
290 additions
and
252 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 was deleted.
Oops, something went wrong.
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,61 @@ | ||
import React from "react"; | ||
import { InjectedFormProps, reduxForm } from "redux-form"; | ||
import { initialStateType } from "../../redux/dialogsReducer"; | ||
import { maxLengthCreator, required } from "../../utils/validators/validators"; | ||
import { createField, GetStringKeys, TextArea } from "../FormsControl/FormsControl"; | ||
import DialogItem from "./DialogItem/Dialog"; | ||
import s from "./Dialogs.module.css"; | ||
import Message from "./Messages/Messages"; | ||
|
||
type OwnPropsType = { | ||
dialogsPage: initialStateType | ||
sendMessage: (messageText: string) => void | ||
} | ||
|
||
const Dialogs: React.FC<OwnPropsType> = ({ dialogsPage, sendMessage }) => { | ||
|
||
const addNewMessage = (values: { newMessageBody: string }) => { | ||
sendMessage(values.newMessageBody); | ||
} | ||
return ( | ||
<div className={s.dialogs}> | ||
<div className={s.dialogsItems}> | ||
{dialogsPage.dialogs.map((item) => { | ||
return <DialogItem key={item.id} name={item.name} path={item.id} />; | ||
})} | ||
</div> | ||
<div className={s.messages}> | ||
{dialogsPage.messages.map((item) => { | ||
return <Message messageContent={item.message} key={item.id} />; | ||
})} | ||
</div> | ||
|
||
<AddReduxMessageForm onSubmit={addNewMessage} /> | ||
</div> | ||
); | ||
}; | ||
|
||
type NewMessageFormFormValuesType = { | ||
newMessageBody: string | ||
} | ||
type PropsType = {} | ||
type NewMessageFormValuesKeysType = GetStringKeys<NewMessageFormFormValuesType> | ||
|
||
const maxLength50 = maxLengthCreator(50); | ||
|
||
const AddMessageForm: React.FC<InjectedFormProps<NewMessageFormFormValuesType, PropsType> & PropsType> = ({ handleSubmit }) => { | ||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<div> | ||
{createField<NewMessageFormValuesKeysType>("Enter your message", "newMessageBody", [required, maxLength50], TextArea)} | ||
</div> | ||
<div> | ||
<button>Send</button> | ||
</div> | ||
</form> | ||
); | ||
}; | ||
|
||
const AddReduxMessageForm = reduxForm<NewMessageFormFormValuesType>({ form: "dialogAddMessageForm" })(AddMessageForm); | ||
|
||
export default Dialogs; |
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 was deleted.
Oops, something went wrong.
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,65 @@ | ||
import React from "react"; | ||
import { Form, InjectedFormProps, reduxForm } from "redux-form"; | ||
import { | ||
required | ||
} from "../../../utils/validators/validators"; | ||
import { createField, GetStringKeys, TextArea } from "../../FormsControl/FormsControl"; | ||
import s from "./MyPosts.module.css"; | ||
import Post from "./Posts/Post"; | ||
import { PostType } from "../../../types/types"; | ||
|
||
type PropsType = { | ||
|
||
} | ||
|
||
type AddPostFormValuesType = { | ||
newPostText: string | ||
} | ||
|
||
type LoginFormValuesTypeKeys = GetStringKeys<AddPostFormValuesType> | ||
|
||
const MyPostForm: React.FC<InjectedFormProps<AddPostFormValuesType, PropsType> & PropsType> = ({handleSubmit}) => { | ||
return ( | ||
<Form onSubmit={handleSubmit}> | ||
{createField<LoginFormValuesTypeKeys>("Post a message", "newPostText", [required], TextArea)} | ||
<button type="submit">Add Post</button> | ||
<button>Remove</button> | ||
</Form> | ||
); | ||
}; | ||
|
||
const LoginReduxForm = reduxForm<AddPostFormValuesType>({ | ||
form: "posts", | ||
})(MyPostForm); | ||
|
||
type MyPostsPropsType = { | ||
postsData: Array<PostType> | ||
addPost: (newPostText: string) => void | ||
} | ||
|
||
const MyPosts: React.FC<MyPostsPropsType> = ({ postsData, addPost }) => { | ||
|
||
const onSubmit = (values: AddPostFormValuesType) => { | ||
addPost(values.newPostText); | ||
}; | ||
|
||
return ( | ||
<div className={s.postBlock}> | ||
<h3>My Posts</h3> | ||
<LoginReduxForm onSubmit={onSubmit} /> | ||
<div className={s.posts}> | ||
{[...postsData].reverse().map((item) => { | ||
return ( | ||
<Post | ||
message={item.message} | ||
likeCount={item.likeCount} | ||
key={item.id} | ||
/> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MyPosts; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.