diff --git a/messages-app-frontend/src/App.tsx b/messages-app-frontend/src/App.tsx index 3866f511aaa0979634f82ce1b4e91e5459b43794..5c1c0778e14dc406dbd0e7b0211de3ff0ad31566 100644 --- a/messages-app-frontend/src/App.tsx +++ b/messages-app-frontend/src/App.tsx @@ -1,10 +1,10 @@ import React from 'react'; import axios from 'axios'; -import {Button, IconButton, Container, Typography, Box, Input, Paper} from '@mui/material'; -import SendIcon from '@mui/icons-material/Send'; +import {Button, IconButton, Container, Box, Input, Paper} from '@mui/material'; import DeleteIcon from '@mui/icons-material/Delete'; import EditIcon from '@mui/icons-material/Edit'; -import NewMessage from "./NewMessage" +import NewMessage from "./NewMessage"; +import Welcome from "./Welcome"; //import IconButton from '@mui/material'; //import SendIcon from '@mui/icons-material'; @@ -49,6 +49,7 @@ export default class App extends React.Component{ } createMessage = async () => { + console.log("New message has been created!") await api.post('/messages', {message: this.state.newMessage}); this.setState({newMessage: ""}); this.getMessages(); @@ -76,8 +77,8 @@ export default class App extends React.Component{ this.getMessages(); } - inputValueChanged(newValue: any){ - this.setState({newMessage: newValue}) + inputValueChanged = (newValue: any) => { + this.setState({newMessage: newValue}); //(p) => this.setState({newMessage: p.target.value}) } @@ -120,18 +121,14 @@ export default class App extends React.Component{ if(this.state.editingMessage.bool){ return( <Container> - <Box sx={{bgcolor: 'white', marginX: 10, padding: 1, marginY: 2, borderRadius: 5, boxShadow: 20}}> - <Typography variant="h3" sx={{textAlign: "center", margin: 3}}>Welcome to my Messaging Application!</Typography> - </Box> + + <Welcome /> <Box sx={{bgcolor: "darkgreen", marginX: 10, padding: 3, display: "grid", /*flexDirection: "column", alignItems: "center",*/ justifyContent: "center", boxShadow: 20, borderRadius: 5}}> {this.state.messages.map((p) => this.updatingMessage(p))} </Box> - <Box sx={{textAlign: "center", paddingTop: 5}}> - <Input value={this.state.newMessage} onChange={(p) => this.setState({newMessage: p.target.value})}></Input> - <Button /*color="success"*/ sx={{margin: 1.5}} variant="contained" endIcon={<SendIcon />} onClick={this.createMessage}>Send</Button> - </Box> + <NewMessage inputValue={this.state.newMessage} createMessage={this.createMessage} onChangeValue={this.inputValueChanged}/> </Container> ) } @@ -140,9 +137,7 @@ export default class App extends React.Component{ return( <Container> - <Box sx={{bgcolor: 'white', marginX: 10, padding: 1, marginY: 2, borderRadius: 5, boxShadow: 20}}> - <Typography variant="h3" sx={{textAlign: "center", margin: 3}}>Welcome to my Messaging Application!</Typography> - </Box> + <Welcome /> <Box sx={{bgcolor: "darkgreen", marginX: 10, padding: 3, display: "grid", /*flexDirection: "column", alignItems: "center",*/ justifyContent: "center", boxShadow: 20, borderRadius: 5}}> @@ -161,11 +156,7 @@ export default class App extends React.Component{ )} </Box> - <Box sx={{textAlign: "center", paddingTop: 5}}> - <Input value={this.state.newMessage} onChange={(p) => this.setState({newMessage: p.target.value})}></Input> - <Button /*color="success"*/ sx={{margin: 1.5}} variant="contained" endIcon={<SendIcon />} onClick={this.createMessage}>Send</Button> - </Box> - + <NewMessage inputValue={this.state.newMessage} createMessage={this.createMessage} onChangeValue={this.inputValueChanged}/> </Container> ) diff --git a/messages-app-frontend/src/NewMessage.tsx b/messages-app-frontend/src/NewMessage.tsx index 20cdb8d34c0a44168f4b2ec5ccb5129430ccd6ba..c7974ebb41c7e20e8f52213fdf568a7ac5488ed4 100644 --- a/messages-app-frontend/src/NewMessage.tsx +++ b/messages-app-frontend/src/NewMessage.tsx @@ -1,47 +1,20 @@ import React from 'react'; -import {Button, IconButton, Container, Typography, Box, Input, Paper} from '@mui/material'; +import {Button, Box, Input} from '@mui/material'; import SendIcon from '@mui/icons-material/Send'; -import DeleteIcon from '@mui/icons-material/Delete'; -import EditIcon from '@mui/icons-material/Edit'; -import { AxiosInstance } from 'axios'; -type hello = { +type IProps = { inputValue: string, createMessage: Function, onChangeValue: Function } -type NewMessageState = { +export default class NewMessage extends React.Component<IProps>{ -} - -export default class NewMessage extends React.Component<hello>{ - - state: NewMessageState = { - - } - - /* - createMessage = async () => { - await this.props.api.post('/messages', {message: this.state.newMessage}); - this.setState({newMessage: ""}); - //this.getMessages(); - } - */ - - /* - - <Box sx={{textAlign: "center", paddingTop: 5}}> - <Input value={this.state.newMessage} onChange={(p) => this.setState({newMessage: p.target.value})}></Input> - <Button /*color="success"*//* sx={{margin: 1.5}} variant="contained" endIcon={<SendIcon />} onClick={this.createMessage}>Send</Button> - </Box> - - */ render(){ return( <Box sx={{textAlign: "center", paddingTop: 5}}> <Input value={this.props.inputValue} onChange={(p) => this.props.onChangeValue(p.target.value)}></Input> - <Button /*color="success"*/ sx={{margin: 1.5}} variant="contained" endIcon={<SendIcon />} onClick={this.props.createMessage()}>Send</Button> + <Button sx={{margin: 1.5}} variant="contained" endIcon={<SendIcon />} onClick={() => this.props.createMessage()}>Send</Button> </Box> ) } diff --git a/messages-app-frontend/src/Welcome.tsx b/messages-app-frontend/src/Welcome.tsx new file mode 100644 index 0000000000000000000000000000000000000000..f6a1a93564303a7c4add6484694b82be599065e0 --- /dev/null +++ b/messages-app-frontend/src/Welcome.tsx @@ -0,0 +1,12 @@ +import React from 'react'; +import {Typography, Box} from '@mui/material'; + +export default class Welcome extends React.Component{ + render(): React.ReactNode { + return( + <Box sx={{bgcolor: 'white', marginX: 10, padding: 1, marginY: 2, borderRadius: 5, boxShadow: 20}}> + <Typography variant="h3" sx={{textAlign: "center", margin: 3}}>Welcome to my Messaging Application!</Typography> + </Box> + ) + } +} \ No newline at end of file diff --git a/messagesAppBackend/src/server.ts b/messagesAppBackend/src/server.ts index 5dc201c76bdff6225b070e0e31c08f8314b7cd6a..83d3acf59ba99a6f65bed7731eea6f6f7cfad281 100644 --- a/messagesAppBackend/src/server.ts +++ b/messagesAppBackend/src/server.ts @@ -7,7 +7,7 @@ const app = express() app.use(express.json()); app.use(cors()); -//mongoose.connect("mongodb+srv://joasep:koira@messagescluster0.nvb8tqc.mongodb.net/?retryWrites=true&w=majority"); +mongoose.connect("mongodb+srv://joasep:koira@messagescluster0.nvb8tqc.mongodb.net/?retryWrites=true&w=majority"); app.get("/", async (req, res) => { res.send("This is the root of the API!");