diff --git a/.arcconfig b/.arcconfig deleted file mode 100644 index 4bd7236..0000000 --- a/.arcconfig +++ /dev/null @@ -1,6 +0,0 @@ -{ - "phabricator.uri": "https://hub.sealcode.org/", - "load": [ - "arcanist-linters" - ] -} diff --git a/.arclint b/.arclint deleted file mode 100644 index 0b093d4..0000000 --- a/.arclint +++ /dev/null @@ -1,14 +0,0 @@ -{ - "linters": { - "prettier": { - "type": "prettier", - "bin": "./node_modules/.bin/prettier", - "include": ["(\\.js$)", "(\\.ts$)", "(\\.css$)"] - }, - "eslint": { - "type": "eslint", - "include": ["(\\.ts$)", "(\\.js$)"] - } - - } -} diff --git a/.eslintrc.js b/.eslintrc.js index 5989066..740746d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { env: { node: true }, parser: "@typescript-eslint/parser", - plugins: ["@typescript-eslint", "prettier"], + plugins: ["@typescript-eslint", "prettier", "jsdoc"], extends: [ "eslint:recommended", "plugin:@typescript-eslint/recommended", @@ -14,11 +14,11 @@ module.exports = { modules: true, }, project: "./tsconfig.json", + tsconfigRootDir: __dirname, }, rules: { "@typescript-eslint/require-await": 0, "jsdoc/require-description": 2, - "no-await-in-loop": 2, }, settings: { jsdoc: { mode: "typescript" } }, diff --git a/package-lock.json b/package-lock.json index 4094122..4566768 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1842,19 +1842,11 @@ "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" }, "axios": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz", - "integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==", + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", "requires": { - "follow-redirects": "1.5.10", - "is-buffer": "^2.0.2" - }, - "dependencies": { - "is-buffer": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", - "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==" - } + "follow-redirects": "^1.10.0" } }, "babel-plugin-dynamic-import-node": { @@ -3768,6 +3760,14 @@ } } }, + "eslint-plugin-prettier": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.3.1.tgz", + "integrity": "sha512-Rq3jkcFY8RYeQLgk2cCwuc0P7SEFwDravPhsJZOQ5N4YI4DSg50NyqJ/9gdZHzQlHf8MvafSesbNJCcP/FF6pQ==", + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -4044,6 +4044,11 @@ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==" + }, "fast-glob": { "version": "2.2.7", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-2.2.7.tgz", @@ -4140,27 +4145,9 @@ "dev": true }, "follow-redirects": { - "version": "1.5.10", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", - "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", - "requires": { - "debug": "=3.1.0" - }, - "dependencies": { - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "requires": { - "ms": "2.0.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - } - } + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.2.tgz", + "integrity": "sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==" }, "for-in": { "version": "1.0.2", @@ -7246,6 +7233,14 @@ "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", "dev": true }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty-ms": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-7.0.1.tgz", @@ -7978,6 +7973,15 @@ "color-convert": "^2.0.1" } }, + "axios": { + "version": "0.18.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz", + "integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==", + "requires": { + "follow-redirects": "1.5.10", + "is-buffer": "^2.0.2" + } + }, "chalk": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", @@ -8029,6 +8033,22 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + } + }, "get-port": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/get-port/-/get-port-5.1.1.tgz", @@ -8039,11 +8059,21 @@ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" }, + "is-buffer": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", + "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==" + }, "mime": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/mime/-/mime-2.5.0.tgz", "integrity": "sha512-ft3WayFSFUVBuJj7BMLKAQcSlItKtfjsKDDsii3rqFDAZ7t11zRe8ASw/GlmivGwVUYtwkQrxiGGpL6gFvB0ag==" }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", diff --git a/package.json b/package.json index fe09cc0..af0c2f3 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "scripts": { "back:build": "tsc", "back:watch": "npm run back:build -- --watch", - "front:build": "parcel build --out-dir public src/front/index.html", - "front:watch": "parcel watch --out-dir public src/front/index.html", + "front:build": "parcel build --out-dir public src/front/*.html", + "front:watch": "parcel watch --out-dir public src/front/*.html", "start": "nodemon lib/back/index.js" }, "repository": { @@ -24,6 +24,8 @@ "@types/koa__router": "^8.0.3", "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", + "axios": "^0.21.1", + "eslint-plugin-prettier": "^3.3.1", "koa": "^2.13.0", "koa-mount": "^4.0.0", "koa-static": "^5.0.0", @@ -32,18 +34,17 @@ "react": "^17.0.1", "react-dom": "^17.0.1", "react-leaflet": "^3.0.5", - "sealious": "^0.13.8", - "typescript": "^4.1.3" + "sealious": "^0.13.8" }, "devDependencies": { "@types/leaflet": "^1.5.19", "@types/node": "^14.14.20", "@types/request": "^2.48.5", - "sass": "^1.32.0", - "typescript": "^4.1.3", - "prettier": "^2.0.5", - "eslint-plugin-jsdoc": "^30.0.3", "eslint": "^7.5.0", - "eslint-config-prettier": "^6.11.0" + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-jsdoc": "^30.0.3", + "prettier": "^2.0.5", + "sass": "^1.32.0", + "typescript": "^4.1.3" } } diff --git a/src/back/index.ts b/src/back/index.ts index d8a3744..cfa5535 100644 --- a/src/back/index.ts +++ b/src/back/index.ts @@ -20,7 +20,7 @@ const app = new (class extends App { datastore_mongo: { host: "localhost", port: 20724, - db_name: "cloud-dashboard", + db_name: "zglaszansko-web", }, email: { from_address: "sealious-playground@example.com", @@ -44,7 +44,7 @@ const app = new (class extends App { }; })(); -const port = 3000; +const port = 8080; console.log(`Listening on 127.0.0.1:${port}`); app.start(); diff --git a/src/front/Nav.tsx b/src/front/Nav.tsx index e96dd7c..9b7a1aa 100644 --- a/src/front/Nav.tsx +++ b/src/front/Nav.tsx @@ -1,19 +1,33 @@ -import React, { ReactElement } from "react"; -import "./styles/app.scss"; +import React, { ReactElement, useEffect, useState } from "react"; +import "./styles/nav.scss"; +interface Props { + isLogged: boolean; +} +const NOT_LOGGED = [ + { name: "aplikacja", href: "/" }, + { name: "logowanie", href: "login.html" }, +]; +const LOGGED = [ + { name: "aplikacja", href: "/" }, + { name: "wyloguj", href: "login.html" }, +]; -interface Props {} -const logged = [{ name: "Login" }]; -function Nav({}: Props): ReactElement { +function Nav({ isLogged }: Props): ReactElement { return ( ); diff --git a/src/front/app.tsx b/src/front/app.tsx index d2ae1ca..8eabc88 100644 --- a/src/front/app.tsx +++ b/src/front/app.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import React, { useState, useReducer, @@ -7,8 +8,9 @@ import React, { FormEvent, useEffect, } from "react"; -import * as ReactDOM from "react-dom"; +import { render } from "react-dom"; import { offenses } from "./offenses"; +import axios from "axios"; import Nav from "./Nav"; //Importing fileReducer to use in useReducer hook, and File interface to use in looping over array of files import { fileReducer, filesInitialState, File } from "./fileReducer"; @@ -18,8 +20,25 @@ import { MapContainer, TileLayer, Marker, useMapEvents } from "react-leaflet"; import "./styles/reset.css"; import "./styles/app.scss"; import { getAddress } from "./location"; - +import { FileType } from "./file"; const App: FC = () => { + const [isLogged, setIsLogged] = useState(false); + + const checkUser = async (): Promise => { + try { + await axios.get( + "http://localhost:8080/api/v1/collections/users/me" + ); + setIsLogged(true); + } catch (error) { + setIsLogged(false); + } + }; + + useEffect(() => { + void checkUser(); + }, []); + //This reducer handles adding and selecting files. //I'm passing in initial state "{files: []}" from fileReducer file. //State can be changed by using dispatch function with object contaning right type and payload. @@ -35,7 +54,7 @@ const App: FC = () => { const [formState, formDispatch] = useReducer(formReducer, fromInitialState); //This hook handles pining location on the map - const [mapPin, setMapPin] = useState({ lat: 52.39663, lon: 16.89866 }); + const [mapPin, setMapPin] = useState({ lat: 0, lon: 0 }); const handleSubmit = async ( event: FormEvent | MouseEvent @@ -46,10 +65,12 @@ const App: FC = () => { const handleUpload = (e: ChangeEvent) => { const files = e.target.files; - const readAndPreview = (file: any) => { + const readAndPreview = (file: FileType) => { + console.log(file); // Make sure `file.name` matches our extensions criteria + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (/\.(jpe?g|png|svg)$/i.test(file.name)) { - let reader = new FileReader(); + const reader = new FileReader(); reader.addEventListener( "load", function () { @@ -64,15 +85,16 @@ const App: FC = () => { }, false ); - reader.readAsDataURL(file); + reader.readAsDataURL((file as unknown) as Blob); } }; if (files) { [].forEach.call(files, readAndPreview); } }; + useEffect(() => { - getAddress(mapPin).then((blob) => + void getAddress(mapPin).then((blob) => formDispatch({ type: "CHANGE_FIELD", payload: { @@ -82,6 +104,7 @@ const App: FC = () => { }) ); }, [mapPin]); + const MapComponent = () => { useMapEvents({ click: async (e) => { @@ -90,7 +113,7 @@ const App: FC = () => { }); return null; }; - // console.log(getAddress(mapPin)); + const formMessage = `Rejestracja: ${formState.plate}\nMiejsce: ${ formState.address.road === undefined ? "" : formState.address.road } ${ @@ -108,7 +131,7 @@ const App: FC = () => { return ( <> -