├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.tsx ├── AuthPage │ ├── LogInForm.tsx │ ├── SignUpForm.tsx │ ├── components │ │ ├── Button.tsx │ │ ├── Link.tsx │ │ ├── PhotoInput.tsx │ │ └── TextInput.tsx │ └── index.tsx ├── ChatsPage │ ├── ChatCard.tsx │ ├── ChatHeader.tsx │ ├── MessageForm.tsx │ ├── Sidebar.tsx │ ├── UserSearch.tsx │ └── index.tsx ├── app.css ├── assets │ ├── VisbyRoundCF-DemiBold.woff │ ├── VisbyRoundCF-Heavy.woff │ ├── VisbyRoundCF-Regular.woff │ ├── adam.png │ ├── bob.png │ ├── callum.png │ ├── daniel.png │ └── valley.jpeg ├── functions │ ├── constants.tsx │ ├── context.tsx │ ├── dates.tsx │ ├── getOtherUser.tsx │ └── isMobile.tsx ├── index.tsx ├── react-app-env.d.ts └── theme.css └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pretty Chat React/Typescript 2 | 3 | This project is a pretty full-stack chat app built with React and Typesctipt. 4 | 5 | To learn how this project works, watch the following YouTube tutorial. 6 | 7 | ## Setup 8 | 9 | Go to [chatengine.io](https://chatengine.io) and create your own project. There you will get a Project ID and Private Key which are needed for user signup and authentication. 10 | 11 | ### `.env.local` 12 | 13 | Create a `.env.local` file at the top-level of your project, and replace the UUIDs with your own Project ID and Private Key from [chatengine.io](https://chatengine.io). 14 | 15 | ``` 16 | REACT_APP_PROJECT_ID=12341234-1234-1234-1234-123412341234 17 | REACT_APP_PROJECT_KEY=abcdabcd-abcd-abcd-abcd-abcdabcdabcd 18 | ``` 19 | 20 | This will link your new React App to the right Chat Engine project. 21 | 22 | ### `npm install` 23 | 24 | Build out your node modules by running `npm install`. Then you cn start the app. 25 | 26 | ### `npm run start` 27 | 28 | This will start the app. By default it will run on [localhost:3000](http://localhost:3000/) 29 | 30 | ### `npm run build` 31 | 32 | Builds the app for production to the `build` folder.\ 33 | It correctly bundles React in production mode and optimizes the build for the best performance. 34 | 35 | The build is minified and the filenames include the hashes.\ 36 | Your app is ready to be deployed! 37 | 38 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pretty-chat-react-typescript", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.14.1", 7 | "@testing-library/react": "^13.0.0", 8 | "@testing-library/user-event": "^13.2.1", 9 | "@types/jest": "^27.0.1", 10 | "@types/node": "^16.7.13", 11 | "@types/react": "^18.0.0", 12 | "@types/react-dom": "^18.0.0", 13 | "antd": "4.21.5", 14 | "axios": "^0.27.2", 15 | "react": "^18.2.0", 16 | "react-chat-engine-advanced": "0.1.21", 17 | "react-dom": "^18.2.0", 18 | "react-scripts": "5.0.1", 19 | "typescript": "^4.4.2", 20 | "web-vitals": "^2.1.0" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "test": "react-scripts test", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": [ 30 | "react-app", 31 | "react-app/jest" 32 | ] 33 | }, 34 | "browserslist": { 35 | "production": [ 36 | ">0.2%", 37 | "not dead", 38 | "not op_mini all" 39 | ], 40 | "development": [ 41 | "last 1 chrome version", 42 | "last 1 firefox version", 43 | "last 1 safari version" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alamorre/pretty-chat-react-typescript/80ac9a2d48bff8779020e8fc87b1dd17a4994642/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alamorre/pretty-chat-react-typescript/80ac9a2d48bff8779020e8fc87b1dd17a4994642/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alamorre/pretty-chat-react-typescript/80ac9a2d48bff8779020e8fc87b1dd17a4994642/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import { useContext } from "react"; 2 | 3 | import { Context } from "./functions/context"; 4 | 5 | import AuthPage from "./AuthPage"; 6 | import ChatsPage from "./ChatsPage"; 7 | 8 | import "./app.css"; 9 | 10 | function App() { 11 | const { user } = useContext(Context); 12 | 13 | if (user) { 14 | return ; 15 | } else { 16 | return ; 17 | } 18 | } 19 | 20 | export default App; 21 | -------------------------------------------------------------------------------- /src/AuthPage/LogInForm.tsx: -------------------------------------------------------------------------------- 1 | import { useState, useContext } from "react"; 2 | 3 | import axios from "axios"; 4 | 5 | import TextInput from "./components/TextInput"; 6 | import Button from "./components/Button"; 7 | import Link from "./components/Link"; 8 | 9 | import { Context } from "../functions/context"; 10 | import { projectId } from "../functions/constants"; 11 | import { PersonObject } from "react-chat-engine-advanced"; 12 | 13 | interface LogInFormProps { 14 | onHasNoAccount: () => void; 15 | } 16 | 17 | const LogInForm = (props: LogInFormProps) => { 18 | // State 19 | const [email, setEmail] = useState(""); 20 | const [password, setPassword] = useState(""); 21 | // Hooks 22 | const { setUser } = useContext(Context); 23 | 24 | const onSubmit = (event: React.FormEvent) => { 25 | event.preventDefault(); 26 | 27 | const headers = { 28 | "Project-ID": projectId, 29 | "User-Name": email, 30 | "User-Secret": password, 31 | }; 32 | 33 | axios 34 | .get("https://api.chatengine.io/users/me/", { 35 | headers, 36 | }) 37 | .then((r) => { 38 | if (r.status === 200) { 39 | const user: PersonObject = { 40 | first_name: r.data.first_name, 41 | last_name: r.data.last_name, 42 | email: email, 43 | username: email, 44 | secret: password, 45 | avatar: r.data.avatar, 46 | custom_json: {}, 47 | is_online: true, 48 | }; 49 | setUser(user); 50 | } 51 | }) 52 | .catch((e) => console.log("Error", e)); 53 | }; 54 | 55 | return ( 56 |
57 |
Welcome Back
58 | 59 |
60 | New here? props.onHasNoAccount()}>Sign Up 61 |
62 | 63 |
64 | setEmail(e.target.value)} 69 | /> 70 | 71 | setPassword(e.target.value)} 77 | /> 78 | 79 | 80 | 81 |
82 | ); 83 | }; 84 | 85 | export default LogInForm; 86 | -------------------------------------------------------------------------------- /src/AuthPage/SignUpForm.tsx: -------------------------------------------------------------------------------- 1 | import { useContext, useState } from "react"; 2 | 3 | import axios from "axios"; 4 | 5 | import { PersonObject } from "react-chat-engine-advanced"; 6 | 7 | import { useIsMobile } from "../functions/isMobile"; 8 | import { Context } from "../functions/context"; 9 | import { privateKey } from "../functions/constants"; 10 | 11 | import TextInput from "./components/TextInput"; 12 | import PhotoInput from "./components/PhotoInput"; 13 | import Button from "./components/Button"; 14 | import Link from "./components/Link"; 15 | 16 | interface SignUpFormProps { 17 | onHasAccount: () => void; 18 | } 19 | 20 | const SignUpForm = (props: SignUpFormProps) => { 21 | // State 22 | const [firstName, setFirstName] = useState(""); 23 | const [lastName, setLastName] = useState(""); 24 | const [email, setEmail] = useState(""); 25 | const [password, setPassword] = useState(""); 26 | const [avatar, setAvatar] = useState(undefined); 27 | // Hooks 28 | const { setUser } = useContext(Context); 29 | const isMobile: boolean = useIsMobile(); 30 | 31 | const onSubmit = (event: React.FormEvent) => { 32 | event.preventDefault(); 33 | 34 | const userJson: PersonObject = { 35 | email: email, 36 | username: email, 37 | first_name: firstName, 38 | last_name: lastName, 39 | secret: password, 40 | avatar: null, 41 | custom_json: {}, 42 | is_online: true, 43 | }; 44 | 45 | let formData = new FormData(); 46 | formData.append("email", email); 47 | formData.append("username", email); 48 | formData.append("first_name", firstName); 49 | formData.append("last_name", lastName); 50 | formData.append("secret", password); 51 | if (avatar) { 52 | formData.append("avatar", avatar, avatar.name); 53 | } 54 | 55 | const headers = { "Private-Key": privateKey }; 56 | 57 | axios 58 | .post("https://api.chatengine.io/users/", formData, { 59 | headers, 60 | }) 61 | .then((r) => { 62 | if (r.status === 201) { 63 | userJson.avatar = r.data.avatar; 64 | setUser(userJson); 65 | } 66 | }) 67 | .catch((e) => console.log("Error", e)); 68 | }; 69 | 70 | return ( 71 |
72 |
Create an account
73 | 74 |
75 | Already a member?{" "} 76 | props.onHasAccount()}>Log in 77 |
78 | 79 |
80 | setFirstName(e.target.value)} 86 | /> 87 | 88 | setLastName(e.target.value)} 97 | /> 98 | 99 | setEmail(e.target.value)} 105 | /> 106 | 107 | setPassword(e.target.value)} 117 | /> 118 | 119 | { 125 | if (e.target.files !== null) { 126 | setAvatar(e.target.files[0]); 127 | } 128 | }} 129 | /> 130 | 131 | 140 | 141 |
142 | ); 143 | }; 144 | 145 | export default SignUpForm; 146 | -------------------------------------------------------------------------------- /src/AuthPage/components/Button.tsx: -------------------------------------------------------------------------------- 1 | import { CSSProperties, ReactNode, useState } from "react"; 2 | 3 | interface ButtonProps { 4 | children?: ReactNode; 5 | style?: CSSProperties; 6 | type?: string; 7 | } 8 | 9 | const Button = (props: ButtonProps) => { 10 | const [hovered, setHovered] = useState(false); 11 | 12 | return ( 13 | 24 | ); 25 | }; 26 | 27 | const styles = { 28 | style: { 29 | width: "100%", 30 | height: "53px", 31 | color: "white", 32 | backgroundColor: "#fa541c", 33 | border: "none", 34 | outline: "none", 35 | borderRadius: "8px", 36 | fontFamily: "VisbyRoundCF-DemiBold", 37 | cursor: "pointer", 38 | transition: "all .44s ease", 39 | WebkitTransition: "all .44s ease", 40 | MozTransition: "all .44s ease", 41 | } as CSSProperties, 42 | hoverStyle: { filter: "brightness(145%)" } as CSSProperties, 43 | }; 44 | 45 | export default Button; 46 | -------------------------------------------------------------------------------- /src/AuthPage/components/Link.tsx: -------------------------------------------------------------------------------- 1 | import { CSSProperties, ReactNode, useState } from "react"; 2 | 3 | interface LinkProps { 4 | children?: ReactNode; 5 | style?: CSSProperties; 6 | type?: string; 7 | onClick?: () => void; 8 | } 9 | 10 | const Link = (props: LinkProps) => { 11 | const [hovered, setHovered] = useState(false); 12 | 13 | return ( 14 | setHovered(true)} 17 | onMouseLeave={() => setHovered(false)} 18 | style={{ 19 | ...styles.style, 20 | ...(hovered && styles.hoverStyle), 21 | ...props.style, 22 | }} 23 | > 24 | {props.children} 25 | 26 | ); 27 | }; 28 | 29 | const styles = { 30 | style: { 31 | color: "#fa541c", 32 | cursor: "pointer", 33 | transition: "all .44s ease", 34 | WebkitTransition: "all .44s ease", 35 | MozTransition: "all .44s ease", 36 | } as CSSProperties, 37 | hoverStyle: { 38 | filter: "brightness(145%)", 39 | textDecoration: "underline", 40 | } as CSSProperties, 41 | }; 42 | 43 | export default Link; 44 | -------------------------------------------------------------------------------- /src/AuthPage/components/PhotoInput.tsx: -------------------------------------------------------------------------------- 1 | import { CSSProperties, ChangeEventHandler, useState } from "react"; 2 | 3 | interface PhotoInputProps { 4 | label: string; 5 | id: string; 6 | name: string; 7 | placeholder?: string; 8 | style?: CSSProperties; 9 | onChange: ChangeEventHandler; 10 | } 11 | 12 | const PhotoInput = (props: PhotoInputProps) => { 13 | const [selectedImage, setSelectedImage] = useState( 14 | undefined 15 | ); 16 | 17 | const onChange: ChangeEventHandler = (event) => { 18 | if (event.target.files !== null) { 19 | const image = event.target.files[0]; 20 | setSelectedImage(image); 21 | props.onChange(event); 22 | } 23 | }; 24 | 25 | return ( 26 |
32 |