import React from 'react';
import classes from './Dialogs.module.css';
import DialogItem from "./DialogItem/DialogItem";
import Message from "./Message/Message";
import {Redirect} from "react-router-dom";
import {Field, Form, Formik} from 'formik';
const Dialogs = (props) => {
let state = props.dialogsPage;
let dialogsElements = state.dialogs
.map(el => <DialogItem name={el.name} key={el.id} id={el.id} avatar={el.avatar}/>);
let messagesElements = state.messages
.map(el => <Message message={el.message} key={el.id}/>);
if (!props.isAuth) return <Redirect to={"/login"}/>;
return (
<div className={classes.dialogs}>
<div className={classes.dialogsItems}>
{dialogsElements}
</div>
<div className={classes.messages}>
<div>{messagesElements}</div>
</div>
<AddMessageForm sendMessage={props.sendMessage}/>
</div>
)
}
const AddMessageForm = (props) => {
const initialValues = {
newMessageBody: ''
}
const onSubmit = values => {
props.sendMessage(values.newMessageBody);
console.log('запись', values)
}
return (
<Formik initialValues={initialValues} onSubmit={onSubmit}>
<Form>
<div>
<div>
<Field as='textarea'
id='newMessageBody'
name='newMessageBody'/>
</div>
<button type='submit'>Submit</button>
</div>
</Form>
</Formik>
)
}
export default Dialogs;
const WorkQuery = graphql`
query WP_Posts {
allWpPost {
edges {
post: node {
id
title
slug
excerpt
uri
}
}
}
}
}
`
const Work = () => {
const query = useStaticQuery()
return (
{query.allWpPost.edges.map(({ post }) => (
<div>
<Link to={post.slug}>
<p>{post.title}</p>
</Link>
<div dangerouslySetInnerHTML={{ __html: post.excerpt }} />
</div>
))}
)
}
export default Work
- export const WorkQuery = graphql`
query WP_Posts {
allWpPost {
edges {
post: node {
id
title
slug
excerpt
uri
}
}
}
}
}
`
-
+ export const query = graphql`
query WP_Posts {
allWpPost {
edges {
post: node {
id
title
slug
excerpt
uri
}
}
}
}
}
`
import React from "react"
function App(props) {
// при изменении путя работает только с путем #
window.onhashchange = () => {
switch (document.location.pathname) {
case '/': {
return <Index />
}
default: {
return <h1>Error</h1>
}
}
}
}
export default App
import App from "path/to/App.js(x)"
ReactDOM.render(
<App />
document.getElementById('root'),
);