Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C15355361-wks-5 #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15,623 changes: 15,623 additions & 0 deletions Worksheet5/package-lock.json

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions Worksheet5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"firebase": "^5.5.8",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-scripts": "2.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Binary file added Worksheet5/public/favicon.ico
Binary file not shown.
10 changes: 10 additions & 0 deletions Worksheet5/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> React App </title>
</head>
<body>
<div id="root"> </div>
</body>
</html>
15 changes: 15 additions & 0 deletions Worksheet5/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
24 changes: 24 additions & 0 deletions Worksheet5/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.app {
text-align: center;
}
.app__logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}
.app__header {
background-color: black;
padding: 20px;
color: white;
}

.chat__list {
width: 100%;
max-width: 600px;
padding: 20px;
margin: 0 auto;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
41 changes: 41 additions & 0 deletions Worksheet5/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Form from './Form.js';
import firebase from 'firebase';
import firebaseConfig from './config';

firebase.initializeApp(firebaseConfig); // Initialize firebase

class App extends Component
{
constructor(props)
{
super(props);
this.state =
{
user: null,
}
}

render()
{
return (
<div className="app">
<div className="app__header">
<img src={logo} className="app__logo" alt="logo" />

<h2>
CHAT ROOM
</h2>
</div>

<div className="chat__list">
<Form user={this.state.user} />
</div>
</div>
);
}
}

export default App;
74 changes: 74 additions & 0 deletions Worksheet5/src/Form.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
.form
{
display: flex;
flex-wrap: nowrap;
flex-direction: column;
width: 100%;
}

.inputMessegeRow
{
display: flex;
flex-wrap: nowrap;
width: 100%;
padding: 20px;
}

.typeMessage
{
width: 100%;
padding: 15px 20px;
border-radius: 5px 0 0 5px;
border: 1px solid #ddd;
box-sizing: border-box;
outline: 0;
}

.typeMessage:focus
{
background-color: rgba(245, 243, 243, 0.5);
}

.messageBtn
{
padding: 0 30px;
background-color: #000;
color: #fff;
border: 0;
border-radius: 0 5px 5px 0;
outline: 0;
cursor: pointer;
}

.messegeList
{
width: 100%;
padding: 0 20px;
}

.inputName
{
width: 50%;
padding: 10px 20px;
border-radius: 5px 0 0 5px;
border: 1px solid #ddd;
box-sizing: border-box;
outline: 0;
}

.inputName:focus
{
background-color: rgba(245, 243, 243, 0.5);
}

.nameBtn
{
margin: 10px;
padding: 10px 30px;
background-color: #000;
color: #fff;
border: 0;
border-radius: 0 5px 5px 0;
outline: 0;
cursor: pointer;
}
159 changes: 159 additions & 0 deletions Worksheet5/src/Form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import React, { Component } from 'react';
import './Form.css';
import Message from './Message';
import firebase from 'firebase';
export default class Form extends Component
{

constructor(props)
{
super(props);
this.state =
{
fbUsername: 'Luke Marshell',
fbMessage: '',
list: [],
};

// Places messege into firebase database called "FireBaseMessages"
this.myRef = firebase.database().ref().child('FirebaseMessages');
this.listMessages();
}

//What is put in the input bar is placed in fb
//This also stops it from freezing
inputMessageChange(event)
{
this.setState({fbMessage: event.target.value});
}

inputNameChange(event)
{
this.setState({fbUsername: event.target.value});
}

// Takes what is in the input bar and pushes it to the list of messages
// It will then reset FBMessage to NULL
sendMessage()
{
if (this.state.fbMessage)
{
var newItem =
{
fbUsername: this.state.fbUsername,
fbMessage: this.state.fbMessage,
}

this.myRef.push(newItem);
this.setState({ fbMessage: '' });
}

console.log("Message Sent!");
}

// If they press the ENTER button
enterButton(event)
{
if (event.key !== 'Enter') return;
this.sendMessage();
}

// Set new Name for the user
newName()
{
if(this.state.fbUsername)
{
var newName =
{
fbUsername: this.state.fbUsername,
fbMessage: "New User has entered the chatroom!",
}

this.myRef.push(newName);
this.setState({ fbMessage: '' });

}
}

// Recall Messages DO NOT USE I WIPED MY DATABASE
/*recallMessage()
{
this.myRef.remove(newName);
}*/

listMessages()
{
//const myRef: firebase.database.Reference = firebase.database().ref().child('FirebaseMessages');
//myRef .on('value', allMessages => {
//this.setState = allMessages.val();
//});//

this.myRef
.limitToLast(10)
.on('value', allMessages => {
this.setState({
list: Object.values(allMessages.val()),
});
});

}

//Renders HTML output
render()
{
return (

<div className="form">

<div className="messegeList">
{ this.state.list.map((item, index) =>
<Message key={index} fbMessage={item} />
)}
</div>

<div className="inputMessegeRow">

<input
className="typeMessage"
type="text"
placeholder="Type message"
value={this.state.fbMessage}

onChange={this.inputMessageChange.bind(this)}
onKeyPress={this.enterButton.bind(this)}
/>

<button
className="messageBtn"
onClick={this.sendMessage.bind(this)}>

Send
</button>

</div>

<div>

<input
className="inputName"
type="text"
placeholder="Enter new Name"
value={this.state.fbUsername}

onChange={this.inputNameChange.bind(this)}
/>

<button
className="nameBtn"
onClick={this.newName.bind(this)}>

Set new Name
</button>


</div>

</div>
);
}
}
18 changes: 18 additions & 0 deletions Worksheet5/src/Message.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.cssMessage {
position: relative;
padding: 10px 60px 10px 20px;
font-size: 12px;
color: rgba(0, 0, 0, 0.6);

background-color: lavender;
text-align: left;
line-height: 1.7;
}
.cssMessage:nth-child(even) {
background-color: lavenderblush;
}
.cssUsername {
font-weight: 600;
margin-right: 10px;
color: rgba(0, 0, 0, 1);
}
Loading