├── .gitignore ├── README.md ├── craco.config.js ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.js ├── app │ └── store.js ├── components │ ├── Channel.js │ ├── Chat.js │ ├── Header.js │ ├── Hero.js │ ├── Home.js │ ├── Message.js │ └── ServerIcon.js ├── features │ └── channelSlice.js ├── firebase.js ├── index.css ├── index.js └── reportWebVitals.js ├── tailwind.config.js └── yarn.lock /.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 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `yarn build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /craco.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | style: { 3 | postcss: { 4 | plugins: [require("tailwindcss"), require("autoprefixer")], 5 | }, 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "discord-2", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@craco/craco": "^6.1.2", 7 | "@heroicons/react": "^1.0.1", 8 | "@reduxjs/toolkit": "^1.5.1", 9 | "@testing-library/jest-dom": "^5.11.4", 10 | "@testing-library/react": "^11.1.0", 11 | "@testing-library/user-event": "^12.1.10", 12 | "firebase": "^8.6.5", 13 | "moment": "^2.29.1", 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-firebase-hooks": "^3.0.4", 17 | "react-redux": "^7.2.4", 18 | "react-router-dom": "^5.2.0", 19 | "react-scripts": "4.0.3", 20 | "tailwind-scrollbar-hide": "^1.0.3", 21 | "web-vitals": "^1.0.1" 22 | }, 23 | "scripts": { 24 | "start": "craco start", 25 | "build": "craco build", 26 | "test": "craco test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": [ 31 | "react-app", 32 | "react-app/jest" 33 | ] 34 | }, 35 | "browserslist": { 36 | "production": [ 37 | ">0.2%", 38 | "not dead", 39 | "not op_mini all" 40 | ], 41 | "development": [ 42 | "last 1 chrome version", 43 | "last 1 firefox version", 44 | "last 1 safari version" 45 | ] 46 | }, 47 | "devDependencies": { 48 | "autoprefixer": "^9", 49 | "postcss": "^7", 50 | "tailwindcss": "npm:@tailwindcss/postcss7-compat" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alimehdiofficial/Discord-2.0-reactjs-tailwindcss/43158096be7e90944884fdeb5562f377999da993/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/alimehdiofficial/Discord-2.0-reactjs-tailwindcss/43158096be7e90944884fdeb5562f377999da993/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alimehdiofficial/Discord-2.0-reactjs-tailwindcss/43158096be7e90944884fdeb5562f377999da993/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.js: -------------------------------------------------------------------------------- 1 | import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; 2 | import Hero from "./components/Hero"; 3 | import Header from "./components/Header"; 4 | import Home from "./components/Home"; 5 | 6 | function App() { 7 | return ( 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | ); 23 | } 24 | 25 | export default App; 26 | -------------------------------------------------------------------------------- /src/app/store.js: -------------------------------------------------------------------------------- 1 | import { configureStore } from "@reduxjs/toolkit"; 2 | import channelReducer from "../features/channelSlice"; 3 | 4 | export const store = configureStore({ 5 | reducer: { 6 | channel: channelReducer, 7 | }, 8 | }); 9 | -------------------------------------------------------------------------------- /src/components/Channel.js: -------------------------------------------------------------------------------- 1 | import { HashtagIcon } from "@heroicons/react/outline"; 2 | import { useDispatch } from "react-redux"; 3 | import { useHistory } from "react-router-dom"; 4 | import { setChannelInfo } from "../features/channelSlice"; 5 | 6 | function Channel({ id, channelName }) { 7 | const dispatch = useDispatch(); 8 | const history = useHistory(); 9 | 10 | const setChannel = () => { 11 | dispatch( 12 | setChannelInfo({ 13 | channelId: id, 14 | channelName: channelName, 15 | }) 16 | ); 17 | 18 | history.push(`/channels/${id}`); 19 | }; 20 | 21 | return ( 22 |
26 | {channelName} 27 |
28 | ); 29 | } 30 | 31 | export default Channel; 32 | -------------------------------------------------------------------------------- /src/components/Chat.js: -------------------------------------------------------------------------------- 1 | import { HashtagIcon, SearchIcon } from "@heroicons/react/outline"; 2 | import { 3 | BellIcon, 4 | ChatIcon, 5 | UsersIcon, 6 | InboxIcon, 7 | QuestionMarkCircleIcon, 8 | PlusCircleIcon, 9 | GiftIcon, 10 | EmojiHappyIcon, 11 | } from "@heroicons/react/solid"; 12 | import { useSelector } from "react-redux"; 13 | import { selectChannelId, selectChannelName } from "../features/channelSlice"; 14 | import { auth, db } from "../firebase"; 15 | import Message from "./Message"; 16 | import firebase from "firebase"; 17 | import { useRef } from "react"; 18 | import { useAuthState } from "react-firebase-hooks/auth"; 19 | import { useCollection } from "react-firebase-hooks/firestore"; 20 | 21 | function Chat() { 22 | const channelId = useSelector(selectChannelId); 23 | const channelName = useSelector(selectChannelName); 24 | const [user] = useAuthState(auth); 25 | const inputRef = useRef(""); 26 | const chatRef = useRef(null); 27 | const [messages] = useCollection( 28 | channelId && 29 | db 30 | .collection("channels") 31 | .doc(channelId) 32 | .collection("messages") 33 | .orderBy("timestamp", "asc") 34 | ); 35 | 36 | const scrollToBottom = () => { 37 | chatRef.current.scrollIntoView({ 38 | behavior: "smooth", 39 | block: "start", 40 | }); 41 | }; 42 | 43 | const sendMessage = (e) => { 44 | e.preventDefault(); 45 | 46 | if (inputRef.current.value !== "") { 47 | db.collection("channels").doc(channelId).collection("messages").add({ 48 | timestamp: firebase.firestore.FieldValue.serverTimestamp(), 49 | message: inputRef.current.value, 50 | name: user?.displayName, 51 | photoURL: user?.photoURL, 52 | email: user?.email, 53 | }); 54 | } 55 | 56 | inputRef.current.value = ""; 57 | scrollToBottom(); 58 | }; 59 | 60 | return ( 61 |
62 |
63 |
64 | 65 |

{channelName}

66 |
67 |
68 | 69 | 70 | 71 |
72 | 77 | 78 |
79 | 80 | 81 |
82 |
83 |
84 | {messages?.docs.map((doc) => { 85 | const { message, timestamp, name, photoURL, email } = doc.data(); 86 | 87 | return ( 88 | 97 | ); 98 | })} 99 |
100 |
101 |
102 | 103 |
104 | 113 | 116 |
117 | 118 | 119 |
120 |
121 | ); 122 | } 123 | 124 | export default Chat; 125 | -------------------------------------------------------------------------------- /src/components/Header.js: -------------------------------------------------------------------------------- 1 | import { MenuIcon } from "@heroicons/react/outline"; 2 | import { useAuthState } from "react-firebase-hooks/auth"; 3 | import { useHistory } from "react-router-dom"; 4 | import { auth, provider } from "../firebase"; 5 | 6 | function Header() { 7 | const [user] = useAuthState(auth); 8 | const history = useHistory(); 9 | 10 | const signIn = (e) => { 11 | e.preventDefault(); 12 | 13 | auth 14 | .signInWithPopup(provider) 15 | .then(() => history.push("/channels")) 16 | .catch((error) => alert(error.message)); 17 | }; 18 | 19 | return ( 20 |
21 | 22 | 27 | 28 |
29 | Download 30 | Why Discord? 31 | Nitro 32 | Safety 33 | Support 34 |
35 |
36 | 42 | 43 |
44 |
45 | ); 46 | } 47 | 48 | export default Header; 49 | -------------------------------------------------------------------------------- /src/components/Hero.js: -------------------------------------------------------------------------------- 1 | import { DownloadIcon } from "@heroicons/react/outline"; 2 | // import { auth, provider } from "../firebase"; 3 | 4 | function Hero() { 5 | // const signIn = (e) => { 6 | // e.preventDefault(); 7 | 8 | // auth.signInWithPopup(provider).catch((error) => alert(error.message)); 9 | // }; 10 | 11 | return ( 12 |
13 |
14 |
15 |

Your place to talk

16 |

17 | Whether you’re part of a school club, gaming group, worldwide art 18 | community, or just a handful of friends that want to spend time 19 | together, Discord makes it easy to talk every day and hang out more 20 | often. 21 |

22 |
23 | 27 | 30 |
31 |
32 |
33 | 38 | 43 |
44 |
45 |
46 | ); 47 | } 48 | 49 | export default Hero; 50 | -------------------------------------------------------------------------------- /src/components/Home.js: -------------------------------------------------------------------------------- 1 | import { ChevronDownIcon, PlusIcon } from "@heroicons/react/outline"; 2 | import { MicrophoneIcon, PhoneIcon, CogIcon } from "@heroicons/react/solid"; 3 | import Channel from "../components/Channel"; 4 | import ServerIcon from "../components/ServerIcon"; 5 | import Chat from "../components/Chat"; 6 | import { useAuthState } from "react-firebase-hooks/auth"; 7 | import { auth, db } from "../firebase"; 8 | import { Redirect } from "react-router-dom"; 9 | import { useCollection } from "react-firebase-hooks/firestore"; 10 | 11 | function Home() { 12 | const [user] = useAuthState(auth); 13 | const [channels] = useCollection(db.collection("channels")); 14 | 15 | const handleAddChannel = () => { 16 | const channelName = prompt("Enter a new channel name"); 17 | 18 | if (channelName) { 19 | db.collection("channels").add({ 20 | channelName: channelName, 21 | }); 22 | } 23 | }; 24 | 25 | return ( 26 | <> 27 | {!user && } 28 |
29 |
30 |
31 | 32 |
33 |
34 | 35 | 36 | 37 | 38 | 39 |
40 | 41 |
42 |
43 | 44 |
45 |

46 | Official PAPA Server... 47 |

48 |
49 |
50 | 51 |

Channels

52 | 56 |
57 |
58 | {channels?.docs.map((doc) => ( 59 | 64 | ))} 65 |
66 |
67 |
68 |
69 | auth.signOut()} 74 | /> 75 |

76 | {user?.displayName}{" "} 77 | 78 | #{user?.uid.substring(0, 4)} 79 | 80 |

81 |
82 | 83 |
84 |
85 | 86 |
87 |
88 | 89 |
90 |
91 | 92 |
93 |
94 |
95 |
96 | 97 |
98 | 99 |
100 |
101 | 102 | ); 103 | } 104 | 105 | export default Home; 106 | -------------------------------------------------------------------------------- /src/components/Message.js: -------------------------------------------------------------------------------- 1 | import { TrashIcon } from "@heroicons/react/solid"; 2 | import moment from "moment"; 3 | import { useAuthState } from "react-firebase-hooks/auth"; 4 | import { useSelector } from "react-redux"; 5 | import { selectChannelId } from "../features/channelSlice"; 6 | import { auth, db } from "../firebase"; 7 | 8 | function Message({ id, message, timestamp, name, email, photoURL }) { 9 | const channelId = useSelector(selectChannelId); 10 | const [user] = useAuthState(auth); 11 | 12 | return ( 13 |
14 | 19 |
20 |

21 | 22 | {name} 23 | 24 | 25 | {moment(timestamp?.toDate().getTime()).format("lll")} 26 | 27 |

28 |

{message}

29 |
30 | {user?.email === email && ( 31 |
34 | db 35 | .collection("channels") 36 | .doc(channelId) 37 | .collection("messages") 38 | .doc(id) 39 | .delete() 40 | } 41 | > 42 | 43 |
44 | )} 45 |
46 | ); 47 | } 48 | 49 | export default Message; 50 | -------------------------------------------------------------------------------- /src/components/ServerIcon.js: -------------------------------------------------------------------------------- 1 | function ServerIcon({ image }) { 2 | return ( 3 | 8 | ); 9 | } 10 | 11 | export default ServerIcon; 12 | -------------------------------------------------------------------------------- /src/features/channelSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | 3 | const initialState = { 4 | channelId: null, 5 | channelName: null, 6 | }; 7 | 8 | export const channelSlice = createSlice({ 9 | name: "channel", 10 | initialState, 11 | reducers: { 12 | setChannelInfo: (state, action) => { 13 | state.channelId = action.payload.channelId; 14 | state.channelName = action.payload.channelName; 15 | }, 16 | }, 17 | }); 18 | 19 | export const { setChannelInfo } = channelSlice.actions; 20 | 21 | export const selectChannelId = (state) => state.channel.channelId; 22 | export const selectChannelName = (state) => state.channel.channelName; 23 | 24 | export default channelSlice.reducer; 25 | -------------------------------------------------------------------------------- /src/firebase.js: -------------------------------------------------------------------------------- 1 | import firebase from "firebase"; 2 | 3 | const firebaseConfig = { 4 | apiKey: "AIzaSyCk3Jep7m0nWBF5-iAuCmXFgX9Lgx6LBPE", 5 | authDomain: "discord-clone-768d4.firebaseapp.com", 6 | projectId: "discord-clone-768d4", 7 | storageBucket: "discord-clone-768d4.appspot.com", 8 | messagingSenderId: "89139412998", 9 | appId: "1:89139412998:web:243eb102fe14c096a1c387", 10 | }; 11 | 12 | const firebaseApp = firebase.initializeApp(firebaseConfig); 13 | 14 | const db = firebaseApp.firestore(); 15 | const auth = firebase.auth(); 16 | const provider = new firebase.auth.GoogleAuthProvider(); 17 | 18 | export { auth, provider, db }; 19 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | @layer components { 6 | .link { 7 | @apply cursor-pointer font-semibold text-sm text-white hover:underline; 8 | } 9 | 10 | .server-default { 11 | @apply h-12 bg-[#36393f] rounded-full flex justify-center items-center cursor-pointer hover:rounded-2xl transition-all duration-100 ease-out; 12 | } 13 | 14 | .icon { 15 | @apply h-6 text-[#b9bbbe] cursor-pointer hover:text-[#dcddde]; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import "./index.css"; 4 | import App from "./App"; 5 | import reportWebVitals from "./reportWebVitals"; 6 | import { Provider } from "react-redux"; 7 | import { store } from "./app/store"; 8 | 9 | ReactDOM.render( 10 | 11 | 12 | 13 | 14 | , 15 | document.getElementById("root") 16 | ); 17 | 18 | // If you want to start measuring performance in your app, pass a function 19 | // to log results (for example: reportWebVitals(console.log)) 20 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 21 | reportWebVitals(); 22 | -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | mode: "jit", 3 | purge: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"], 4 | darkMode: false, // or 'media' or 'class' 5 | theme: { 6 | extend: { 7 | colors: { 8 | discord_blue: "#295DE7", 9 | discord_blurple: "#7289da", 10 | discord_purple: "#5865f2", 11 | discord_green: "#3ba55c", 12 | }, 13 | }, 14 | }, 15 | variants: { 16 | extend: {}, 17 | }, 18 | plugins: [require("tailwind-scrollbar-hide")], 19 | }; 20 | --------------------------------------------------------------------------------