From 80ee83534580a759403ede849a3027e71275bbbb Mon Sep 17 00:00:00 2001 From: "Leomotors (Ubuntu)" <59821765+Leomotors@users.noreply.github.com> Date: Sat, 12 Feb 2022 19:16:50 +0700 Subject: [PATCH] New Version --- .eslintrc | 35 + .eslintrc.json | 42 - api/addquote.ts | 13 +- lib/getQuote.ts | 2 + package.json | 52 +- src/App.tsx | 24 +- src/components/AdminModal.tsx | 6 +- src/components/DeleteModal.tsx | 1 - src/components/FormModal.scss | 4 + src/components/FormModal.tsx | 22 +- src/models/Quote.ts | 5 + src/views/Admin.tsx | 12 +- yarn.lock | 2218 +++++++++++++++++--------------- 13 files changed, 1310 insertions(+), 1126 deletions(-) create mode 100644 .eslintrc delete mode 100644 .eslintrc.json diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..d11b98d --- /dev/null +++ b/.eslintrc @@ -0,0 +1,35 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:@typescript-eslint/recommended" + ], + "settings": { + "react": { + "version": "detect" + } + }, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": ["react", "@typescript-eslint"], + "rules": { + "indent": ["warn", 2], + "linebreak-style": ["warn", "unix"], + "quotes": ["warn", "double"], + "semi": ["warn", "always"], + "eol-last": "warn", + "react/react-in-jsx-scope": "off", + "react/no-unescaped-entities": "off", + "@typescript-eslint/ban-ts-comment": "off" + } +} diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 7ddaeca..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "env": { - "browser": true, - "es2021": true - }, - "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:@typescript-eslint/recommended" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": 12, - "sourceType": "module" - }, - "plugins": [ - "react", - "@typescript-eslint" - ], - "rules": { - "indent": [ - "warn", - 2 - ], - "linebreak-style": [ - "warn", - "unix" - ], - "quotes": [ - "warn", - "double" - ], - "semi": [ - "warn", - "always" - ], - "eol-last": "warn" - } -} diff --git a/api/addquote.ts b/api/addquote.ts index cfbe512..46e27f9 100644 --- a/api/addquote.ts +++ b/api/addquote.ts @@ -3,13 +3,21 @@ import { VercelRequest, VercelResponse } from "@vercel/node"; import { db } from "../lib/Firestore"; import { collection, addDoc } from "firebase/firestore"; import auth from "../lib/AdminAuth"; +import { AvailableImagesValue } from "../src/models/Quote"; export default async (req: VercelRequest, res: VercelResponse) => { - const { quote, lang, count, password } = req.body; + const { quote, lang, image, count, password } = req.body; if (!auth(password as string, res)) return; - if (!(quote.length && count && (lang == "en" || lang == "th"))) { + if ( + !( + quote.length && + count && + ["en", "th"].includes(lang) && + AvailableImagesValue.includes(image) + ) + ) { res.status(400).send("Bad Request"); return; } @@ -18,6 +26,7 @@ export default async (req: VercelRequest, res: VercelResponse) => { await addDoc(collection(db, "quotes"), { quote, lang, + image, count, created_at: Date().toString(), }); diff --git a/lib/getQuote.ts b/lib/getQuote.ts index 3849377..dcd8a21 100644 --- a/lib/getQuote.ts +++ b/lib/getQuote.ts @@ -14,6 +14,7 @@ export async function getQuote( return { quote: quote.quote.replace("__PARAM__", count.toString()), lang: quote.lang, + image: quote.image, }; } @@ -28,6 +29,7 @@ export async function getAllQuotes(): Promise { lang: data.lang, quote: data.quote, count: data.count, + image: data.image, created_at: data.created_at, }); }); diff --git a/package.json b/package.json index 29e19dd..0cbbff7 100644 --- a/package.json +++ b/package.json @@ -1,27 +1,25 @@ { "name": "food-waste-quotes", - "version": "1.0.10", + "version": "1.0.13", "private": true, "scripts": { - "dev": "yarn inc && yarn config-pkg && vite --port $PORT", - "build": "yarn config-pkg && vite build", + "dev": "yarn lm-config && vite --port $PORT", + "build": "yarn lm-config && vite build", "serve": "vite preview", - "inc": "node node_modules/leomotors-automation/incrementVersion.js", - "config-pkg": "node node_modules/leomotors-automation/configPackage.js" + "lint": "prettier --check \"src/**/*.{ts,tsx}\" && eslint src", + "format": "prettier --write \"src/**/*.{ts,tsx}\"" }, "dependencies": { - "@reduxjs/toolkit": "^1.6.2", - "axios": "^0.22.0", - "bootstrap": "^5.1.1", - "bootstrap-icons": "^1.5.0", - "firebase": "^9.1.1", - "leomotors-automation": "^1.0.1", + "@reduxjs/toolkit": "^1.7.2", + "axios": "^0.25.0", + "bootstrap": "^5.1.3", + "bootstrap-icons": "^1.8.1", + "firebase": "^9.6.6", + "leomotors-automation": "^3.0.0", "react": "^17.0.2", - "react-bootstrap": "^2.0.0-rc.0", + "react-bootstrap": "^2.1.2", "react-dom": "^17.0.2", - "react-redux": "^7.2.5", - "react-router-dom": "^5.3.0", - "redux": "^4.1.1" + "react-router-dom": "^6.2.1" }, "repository": { "type": "git", @@ -33,17 +31,19 @@ }, "homepage": "https://github.com/Food-Busters/food-waste-quotes", "devDependencies": { - "@types/node": "^16.10.2", - "@types/react": "^17.0.27", - "@types/react-dom": "^17.0.9", - "@types/react-router-dom": "^5.3.0", - "@types/uuid": "^8.3.1", + "@types/node": "^17.0.17", + "@types/react": "^17.0.39", + "@types/react-dom": "^17.0.11", + "@types/react-router-dom": "^5.3.3", + "@types/uuid": "^8.3.4", + "@typescript-eslint/eslint-plugin": "^5.11.0", + "@typescript-eslint/parser": "^5.11.0", "@vercel/node": "^1.12.1", - "@vitejs/plugin-react": "^1.0.2", - "eslint": "^7.32.0", - "eslint-plugin-react": "^7.26.1", - "sass": "^1.42.1", - "typescript": "^4.4.3", - "vite": "^2.6.3" + "@vitejs/plugin-react": "^1.2.0", + "eslint": "^8.9.0", + "eslint-plugin-react": "^7.28.0", + "sass": "^1.49.7", + "typescript": "^4.5.5", + "vite": "^2.8.1" } } \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 979c24b..5e54daf 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ import "./App.scss"; -import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom"; +import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom"; import Home from "./views/Home"; import Admin from "./views/Admin"; @@ -12,12 +12,22 @@ export default function App() {
-
+
Food Waste Quotes - {Version} + + {Version} + PREVIEW + + GitHub +
@@ -26,10 +36,10 @@ export default function App() {
- - - - + + } /> + } /> +
diff --git a/src/components/AdminModal.tsx b/src/components/AdminModal.tsx index 8a037d3..196fe84 100644 --- a/src/components/AdminModal.tsx +++ b/src/components/AdminModal.tsx @@ -1,6 +1,6 @@ import { useState } from "react"; import { Modal } from "react-bootstrap"; -import { useHistory } from "react-router"; +import { useNavigate } from "react-router"; import "./AdminModal.scss"; @@ -13,12 +13,12 @@ export default function AdminModal({ submitPassword: (password: string) => () => void; errorMsg?: string; }) { - const history = useHistory(); + const navigate = useNavigate(); const [password, setPassword] = useState(""); function goHome() { - history.replace("/"); + navigate("/"); } return ( diff --git a/src/components/DeleteModal.tsx b/src/components/DeleteModal.tsx index d91bdc0..d811c19 100644 --- a/src/components/DeleteModal.tsx +++ b/src/components/DeleteModal.tsx @@ -1,4 +1,3 @@ -import { useState } from "react"; import { Modal } from "react-bootstrap"; export default function DeleteModal({ diff --git a/src/components/FormModal.scss b/src/components/FormModal.scss index cd82a81..4ab0900 100644 --- a/src/components/FormModal.scss +++ b/src/components/FormModal.scss @@ -3,3 +3,7 @@ padding: 0.3em 0.6em; border-radius: 0.3em; } + +label { + margin-top: 0.75em; +} diff --git a/src/components/FormModal.tsx b/src/components/FormModal.tsx index 67f07da..36ed10c 100644 --- a/src/components/FormModal.tsx +++ b/src/components/FormModal.tsx @@ -1,5 +1,6 @@ import { useState } from "react"; import { Modal } from "react-bootstrap"; +import { AvailableImages, AvailableImagesValue } from "../models/Quote"; import "./FormModal.scss"; @@ -10,10 +11,16 @@ export default function FormModal({ }: { show: boolean; onHide: () => void; - onSubmit: (quote: string, lang: string, count: number) => Promise; + onSubmit: ( + quote: string, + lang: string, + image: AvailableImages, + count: number + ) => Promise; }) { const [quote, setQuote] = useState(""); const [lang, setLang] = useState("en"); + const [image, setImage] = useState(AvailableImagesValue[0]); const [count, setCount] = useState(0); return ( @@ -31,7 +38,7 @@ export default function FormModal({ __PARAM__ will be replaced by 'count' proportional to amount of food left

-
+