diff --git a/.gitignore b/.gitignore index 0c43a1c..a650c75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,136 @@ -# dependencies -/node_modules -/.pnp -.pnp.js +_/ -# testing -/coverage +# Unmodified +# Created by https://www.toptal.com/developers/gitignore/api/firebase,node +# Edit at https://www.toptal.com/developers/gitignore?templates=firebase,node -# production -/build +### Firebase ### +.idea +**/node_modules/* +**/.firebaserc -# misc -.DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local +### Firebase Patch ### +.runtimeconfig.json +.firebase/ +### Node ### +# Logs +logs +*.log npm-debug.log* yarn-debug.log* yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test +.env.production + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# End of https://www.toptal.com/developers/gitignore/api/firebase,node diff --git a/.prettierrc b/.prettierrc index 9a5e038..9bae898 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,6 @@ { "semi": false, "useTabs": true, - "tabWidth": 4 + "tabWidth": 4, + "singleQuote": false } diff --git a/.vscode/settings.json b/.vscode/settings.json index a881215..475b904 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,6 @@ { + "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnPaste": true, "editor.formatOnSave": true, - "editor.defaultFormatter": "esbenp.prettier-vscode", - "editor.insertSpaces": false, - "editor.detectIndentation": false, - "cSpell.words": ["Sider"] + "cSpell.words": ["firestore", "Sider"] } diff --git a/README.md b/README.md index c67cafc..7512b79 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # llama-bot-web-interface +![License: MIT](https://img.shields.io/github/license/llama-bot/llama-bot-web-api?style=flat-square) +[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) + [Documentation](https://llama-bot.github.io/llama-bot-docs/docs/web-interface/overview) diff --git a/firebase.json b/firebase.json new file mode 100644 index 0000000..8c2886e --- /dev/null +++ b/firebase.json @@ -0,0 +1,41 @@ +{ + "functions": { + "predeploy": [ + "npm --prefix \"$RESOURCE_DIR\" run lint", + "npm --prefix \"$RESOURCE_DIR\" run build" + ], + "source": "functions" + }, + "firestore": { + "rules": "firestore.rules", + "indexes": "firestore.indexes.json" + }, + "hosting": { + "public": "frontend/build/", + "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], + "rewrites": [ + { + "source": "/api/**", + "function": "api" + }, + { + "source": "**", + "destination": "/index.html" + } + ] + }, + "emulators": { + "functions": { + "port": 5001 + }, + "firestore": { + "port": 8080 + }, + "hosting": { + "port": 5000 + }, + "ui": { + "enabled": true + } + } +} diff --git a/firestore.indexes.json b/firestore.indexes.json new file mode 100644 index 0000000..415027e --- /dev/null +++ b/firestore.indexes.json @@ -0,0 +1,4 @@ +{ + "indexes": [], + "fieldOverrides": [] +} diff --git a/firestore.rules b/firestore.rules new file mode 100644 index 0000000..c38e3ae --- /dev/null +++ b/firestore.rules @@ -0,0 +1,8 @@ +rules_version = '2'; +service cloud.firestore { + match /databases/{database}/documents { + match /{document=**} { + allow read, write: if false; + } + } +} \ No newline at end of file diff --git a/frontend/.gitignore b/frontend/.gitignore new file mode 100644 index 0000000..0c43a1c --- /dev/null +++ b/frontend/.gitignore @@ -0,0 +1,21 @@ +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/package.json b/frontend/package.json similarity index 80% rename from package.json rename to frontend/package.json index fe999fa..f84c43b 100644 --- a/package.json +++ b/frontend/package.json @@ -1,15 +1,12 @@ { "name": "llama-bot-web-interface", - "homepage": "https://llama-bot.github.io/llama-bot-web-interface", "version": "1.0.0", "private": true, "scripts": { - "start": "react-scripts start", + "start": "yarn build && firebase serve", "build": "react-scripts build", "test": "react-scripts test", - "analyze": "source-map-explorer 'build/static/js/*.js'", - "predeploy": "yarn build", - "deploy": "gh-pages -d build" + "analyze": "source-map-explorer 'build/static/js/*.js'" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^1.2.36", @@ -17,6 +14,7 @@ "@fortawesome/free-solid-svg-icons": "^5.15.4", "@fortawesome/react-fontawesome": "^0.1.15", "antd": "^4.16.13", + "axios": "^0.21.4", "react": "^17.0.2", "react-dom": "^17.0.2", "react-router-dom": "^5.3.0", @@ -34,14 +32,9 @@ "@types/react-dom": "^17.0.9", "@types/react-router-dom": "^5.1.8", "@types/styled-components": "^5.1.14", - "gh-pages": "^3.2.3", - "pre-push": "^0.1.1", "react-scripts": "^4.0.3", "source-map-explorer": "^2.5.2" }, - "pre-push": [ - "deploy" - ], "eslintConfig": { "extends": [ "react-app", diff --git a/public/index.html b/frontend/public/index.html similarity index 100% rename from public/index.html rename to frontend/public/index.html diff --git a/public/llama-color.png b/frontend/public/llama-color.png similarity index 100% rename from public/llama-color.png rename to frontend/public/llama-color.png diff --git a/public/llama.png b/frontend/public/llama.png similarity index 100% rename from public/llama.png rename to frontend/public/llama.png diff --git a/public/robots.txt b/frontend/public/robots.txt similarity index 100% rename from public/robots.txt rename to frontend/public/robots.txt diff --git a/src/components/Footer.tsx b/frontend/src/components/Footer.tsx similarity index 100% rename from src/components/Footer.tsx rename to frontend/src/components/Footer.tsx diff --git a/src/components/Navbar.tsx b/frontend/src/components/Navbar.tsx similarity index 71% rename from src/components/Navbar.tsx rename to frontend/src/components/Navbar.tsx index 89c3a2c..400045f 100644 --- a/src/components/Navbar.tsx +++ b/frontend/src/components/Navbar.tsx @@ -1,11 +1,15 @@ -import { Layout } from "antd" -import styled from "styled-components" +// import { useState } from "react" +// import { useHistory } from "react-router-dom" -import { Link } from "react-router-dom" +import { useEffect, useState } from "react" +import styled from "styled-components" +import { Layout } from "antd" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { faExternalLinkAlt } from "@fortawesome/free-solid-svg-icons" +import axios from "axios" + const { Header } = Layout const StyledHeader = styled(Header)` @@ -44,6 +48,21 @@ const StyledHeader = styled(Header)` ` const Navbar = () => { + // const history = useHistory() + + const [isLoggedIn, setIsLoggedIn] = useState(false) + const [userName, setUserName] = useState("") + + useEffect(() => { + axios + .get("/api/user-data") + .then((data) => { + setIsLoggedIn(true) + setUserName(`${data.data.username}#${data.data.discriminator}`) + }) + .catch() + }, []) + return (
@@ -70,7 +89,9 @@ const Navbar = () => {
- Login + + {isLoggedIn ? `Logged in as ${userName}` : "Login"} +
) diff --git a/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx similarity index 100% rename from src/components/Sidebar.tsx rename to frontend/src/components/Sidebar.tsx diff --git a/src/contexts.ts b/frontend/src/contexts.ts similarity index 100% rename from src/contexts.ts rename to frontend/src/contexts.ts diff --git a/src/index.css b/frontend/src/index.css similarity index 100% rename from src/index.css rename to frontend/src/index.css diff --git a/src/index.tsx b/frontend/src/index.tsx similarity index 91% rename from src/index.tsx rename to frontend/src/index.tsx index f05cb47..7ced515 100644 --- a/src/index.tsx +++ b/frontend/src/index.tsx @@ -1,7 +1,7 @@ import React, { useState, Suspense, lazy } from "react" import ReactDOM from "react-dom" -import { HashRouter, Switch, Route } from "react-router-dom" +import { BrowserRouter, Switch, Route } from "react-router-dom" import Loader from "react-spinners/CircleLoader" import { Layout } from "antd" @@ -21,7 +21,6 @@ const Dashboard = lazy(() => import("./routes/Dashboard")) const Modules = lazy(() => import("./routes/Modules")) const Logs = lazy(() => import("./routes/Logs")) const Incidents = lazy(() => import("./routes/Incidents")) -const Login = lazy(() => import("./routes/Login")) const StyledSpinContainer = styled.div` width: 100%; @@ -55,7 +54,7 @@ const App = () => { - + @@ -98,9 +97,6 @@ const App = () => { - - -
@@ -109,7 +105,7 @@ const App = () => {