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
// useEffect(..., []); | |
useEffect(() => { | |
const subscription = API | |
.graphql(graphqlOperation(onCreateMessage)) | |
.subscribe({ | |
next: (event) => { | |
setMessages([...messages, event.value.data.onCreateMessage]); | |
} | |
}); |
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
import '@aws-amplify/pubsub'; | |
import { onCreateMessage } from '../graphql/subscriptions'; |
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
export const onCreateMessage = /* GraphQL */ ` | |
subscription OnCreateMessage { | |
onCreateMessage { | |
id | |
channelID | |
author | |
body | |
createdAt | |
updatedAt | |
} |
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
mutation createMessage1 { | |
createMessage(input: { | |
author: "Monica", | |
body: "Hi there Dave!" | |
}) { | |
id | |
author | |
body | |
createdAt | |
updatedAt |
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
.message { | |
align-self: flex-start; | |
... | |
} | |
.message.me { | |
align-self: flex-end; | |
... | |
} |
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
{messages.map((message) => ( | |
<div | |
key={message.id} | |
className={message.author === 'Dave' ? 'message me' : 'message'}>{message.body}</div> | |
))} |
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
const [messages, setMessages] = useState([]); | |
useEffect(() => { | |
API | |
.graphql(graphqlOperation(listMessages)) | |
.then((response) => { | |
const items = response.data?.listMessages?.items; | |
if (items) { | |
setMessages(items); |
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
import React, { useEffect, useState } from 'react'; | |
import API, { graphqlOperation } from '@aws-amplify/api'; | |
import { listMessages } from './graphql/queries'; | |
// ... rest of the code here |
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
* { | |
box-sizing: border-box; | |
} | |
html, body { | |
height: 100%; | |
} | |
#root { | |
display: flex; |
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
// ... import statements here | |
function App() { | |
// Placeholder function for handling changes to our chat bar | |
const handleChange = () => {}; | |
// Placeholder function for handling the form submission | |
const handleSubmit = () => {}; | |