diff --git a/webstillas/src/App.css b/webstillas/src/App.css index 3e76366be3b6b79f551140fcf34b6c36af3123ae..cf1503fcdbe26b4edcc10b6f2d1c8680aae0a9b9 100644 --- a/webstillas/src/App.css +++ b/webstillas/src/App.css @@ -1,5 +1,6 @@ .link{ text-decoration: none; + color: black; } .button{ diff --git a/webstillas/src/App.js b/webstillas/src/App.js index 4b683385ee1ce7a18f912dd9b59b26bb2f388563..5739acddd339bb7e9698dc4310637b283f51d190 100644 --- a/webstillas/src/App.js +++ b/webstillas/src/App.js @@ -18,7 +18,6 @@ import {UserInfo} from "./components/userinformation/userInfo"; import {NotFound} from "./components/error/error"; import { ADD_PROJECT_URL, ADD_SCAFFOLDING_URL, LOGIN, - LOGISTICS_URL, MAP_URL, NOTFOUND, PROJECT_URL, PROJECT_URL_ID, @@ -28,6 +27,12 @@ import { const queryClient = new QueryClient() + +/** + * Function that will route the + * @returns {JSX.Element} + * @constructor + */ function App() { return ( //Authorisation of user diff --git a/webstillas/src/components/Login.js b/webstillas/src/components/Login.js index e9129acccd5c575b844a20ba61b467b80a3c3bd1..9ee607a1698ca7a743aaad17efcd6d50f6dd30f9 100644 --- a/webstillas/src/components/Login.js +++ b/webstillas/src/components/Login.js @@ -6,6 +6,12 @@ import { useUserAuth } from "../context/UserAuthContext"; import {PROJECT_URL, SIGNUP} from "./constants"; import "../firebaselogin.css" + +/** + * Function to display login site. + * @returns {JSX.Element} + * @constructor + */ const Login = () => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); @@ -13,6 +19,11 @@ const Login = () => { const { logIn } = useUserAuth(); const navigate = useNavigate(); + /** + * Function to submit the users request to log in. On success navigate to project site. + * @param e forms submit + * @returns {Promise<void>} + */ const handleSubmit = async (e) => { e.preventDefault(); setError(""); diff --git a/webstillas/src/components/projects/projects.js b/webstillas/src/components/projects/projects.js index b8d32b9ab8a77b499a4cda0dc68fccea470e8560..2ddefe85b05ae4575a7721757805fe7e57a84c6f 100644 --- a/webstillas/src/components/projects/projects.js +++ b/webstillas/src/components/projects/projects.js @@ -5,7 +5,6 @@ import {Route, Routes} from "react-router-dom"; import {PROJECTS_WITH_SCAFFOLDING_URL} from "../../modelData/constantsFile"; import {GetDummyData} from "../../modelData/addData"; import {SpinnerDefault} from "../Spinner"; -import DatePicker from "react-datepicker" import {InternalServerError} from "../error/error"; diff --git a/webstillas/src/components/scaffolding/elements/ModalScaffolding.js b/webstillas/src/components/scaffolding/elements/ModalScaffolding.js index f057db5ec1341a0d7af2a2602eb01f87485c5057..bbaf607b7b47d4a5ebfb1c86737473d9c87818b0 100644 --- a/webstillas/src/components/scaffolding/elements/ModalScaffolding.js +++ b/webstillas/src/components/scaffolding/elements/ModalScaffolding.js @@ -2,7 +2,6 @@ import React, {useState} from "react"; import {Button, Modal} from "react-bootstrap"; import img from "../images/spirstillas_solideq_spir_klasse_5_stillas_135_1.jpg"; import {Link} from "react-router-dom"; -import {useQueryClient} from 'react-query' import {GetDummyData} from "../../../modelData/addData"; import {PROJECTS_WITH_SCAFFOLDING_URL} from "../../../modelData/constantsFile"; import "./Modalscaffolding.css" diff --git a/webstillas/src/components/scaffolding/scaffolding.js b/webstillas/src/components/scaffolding/scaffolding.js index 343164a747b3a8bd084d54efe0f65856204a22cf..d28fcc77d8dd98922581b630a6e95c599456b180 100644 --- a/webstillas/src/components/scaffolding/scaffolding.js +++ b/webstillas/src/components/scaffolding/scaffolding.js @@ -3,14 +3,12 @@ import "./scaffolding.css" import CardElement from "./elements/scaffoldingCard"; import {PROJECTS_WITH_SCAFFOLDING_URL, SCAFFOLDING_URL, STORAGE_URL} from "../../modelData/constantsFile"; import {GetDummyData} from "../../modelData/addData"; -import {useQueryClient} from "react-query"; import {SpinnerDefault} from "../Spinner"; import {InternalServerError} from "../error/error"; /** Class that will create an overview of the scaffolding parts */ - class ScaffoldingClass extends React.Component { constructor(props) { super(props); @@ -25,6 +23,13 @@ class ScaffoldingClass extends React.Component { } + /** + * Function that will count numbers of occurrences different types of scaffolding. + * + * @param arr is the array we are iterating. + * @param key is the field we want to count. + * @returns {*[]} + */ countObjects(arr, key){ let arr2 = []; arr?.forEach((x)=>{ @@ -37,7 +42,6 @@ class ScaffoldingClass extends React.Component { k["occurrence"]++ } }) - }else{ // If not! Then create a new object initialize // it with the present iteration key's value and @@ -53,14 +57,21 @@ class ScaffoldingClass extends React.Component { } + /** + * Function to add occurrences of type scaffolding in desired body. + * + * @param scaffold count of occurrences + * @param storage objects in an array. + * @returns {{scaffolding: *[]}} + */ scaffoldingAndStorage(scaffold, storage){ const scaffoldVar = { scaffolding: [] }; - for(var scaffoldIndex of scaffold) { - var scaff = scaffoldIndex; - for (var storageIndex of storage){ - var stor = storageIndex; + for(const scaffoldIndex of scaffold) { + const scaff = scaffoldIndex; + for (const storageIndex of storage){ + const stor = storageIndex; if (stor.type.toLowerCase() === scaff.type.toLowerCase()){ scaffoldVar.scaffolding.push({ "type" :scaff.type, @@ -80,9 +91,9 @@ class ScaffoldingClass extends React.Component { const objectArr = this.countObjects(scaffolding, "type") const scaffoldingObject = this.scaffoldingAndStorage(objectArr, storage) - console.log(scaffoldingObject); const result = Object.keys(scaffoldingObject).map((key) => scaffoldingObject[key]); + //If user would like to sort based on scaffolding if (selectedOption === "ascending") { result[0]?.sort((a, b) => (a.scaffolding < b.scaffolding) ? 1 : -1) } else if (selectedOption === "descending") { @@ -91,7 +102,6 @@ class ScaffoldingClass extends React.Component { result[0]?.sort((a, b) => (a.type > b.type)) } return ( - //todo only scroll the scaffolding not the map <div className={"scaffolding"}> <div className={"all-scaffolding"}> <div className={"sorting"}> @@ -126,6 +136,12 @@ class ScaffoldingClass extends React.Component { } + +/** + * Function to display information about scaffolding + * @returns {JSX.Element} + * @constructor + */ export const Scaffolding = () => { const {isLoading: LoadingScaffolding, data: Scaffolding, isError: scaffoldingError} = GetDummyData("scaffolding", SCAFFOLDING_URL) const {isLoading: LoadingStorage, data: Storage, isError: storageError} = GetDummyData("storage", STORAGE_URL) @@ -133,14 +149,13 @@ export const Scaffolding = () => { - - - + //If loading if (LoadingScaffolding || LoadingStorage || LoadingAll) { return <SpinnerDefault /> - } else if(scaffoldingError || storageError || allProjectError){ + } else if(scaffoldingError || storageError || allProjectError) //If loading error + { return <InternalServerError /> - } else { + } else { //On success const scaffoldingData = JSON.parse(Scaffolding.text) const storageData = JSON.parse(Storage.text) const projectData = JSON.parse(Project.text) diff --git a/webstillas/src/components/topBar/topBar.css b/webstillas/src/components/topBar/topBar.css index 8e384981bf2b86d15d4c48a2e8f48367b75c5a92..5c271aa77a57d1e0a5ba796fb28b7729083a225e 100644 --- a/webstillas/src/components/topBar/topBar.css +++ b/webstillas/src/components/topBar/topBar.css @@ -17,6 +17,16 @@ position: fixed; } -.dropdown-button{ - text-decoration-color: rebeccapurple; + + +.link-dropdown{ + text-decoration-color: black; +} + +.dropDownMenu{ + color: black; +} + +.dropDownMenu:focus{ + background-color: black; } diff --git a/webstillas/src/components/topBar/topBar.js b/webstillas/src/components/topBar/topBar.js index 0b33d9734bd4c9fe554b62a92dbccbed966f72dc..45d906c0a57d2f52fd3c9bd68babca6c8ecae74d 100644 --- a/webstillas/src/components/topBar/topBar.js +++ b/webstillas/src/components/topBar/topBar.js @@ -17,8 +17,10 @@ import {ADD_PROJECT_URL, ADD_SCAFFOLDING_URL, MAP_URL, PROJECT_URL, SCAFFOLDING_ /** Component that will be used as a top bar for the user to navigate throughout the application. */ + const TopBar = () => { const {logOut} = useUserAuth(); + let loading, user @@ -27,13 +29,8 @@ const TopBar = () => { const {isLoading, data} = GetDummyData("user", USER_URL + auth.currentUser.uid) loading = isLoading user = data - } - - - - /* If the user is not authenticated, the topbar will be empty. */ @@ -41,7 +38,6 @@ const TopBar = () => { return ( <AppBar position="sticky"> <Toolbar className="toolbar"> - </Toolbar> </AppBar> ) @@ -63,23 +59,30 @@ const TopBar = () => { <Link className="link" to={MAP_URL}> <Button className="button">Kart</Button> </Link> + <NavDropdown id="basic-nav-dropdown1" title={"Logistikk"} size="sm" + className={"dropDownMenu"} > <DropdownItem> - <Link to={ADD_PROJECT_URL}>Legg til prosjekt </Link> + <Link className={"link"} + to={ADD_PROJECT_URL}>Legg til prosjekt </Link> </DropdownItem> <DropdownItem> - <Link to={ADD_SCAFFOLDING_URL}>Legg til stillas</Link> + <Link className={"link"} + to={ADD_SCAFFOLDING_URL}>Legg til stillas</Link> </DropdownItem> </NavDropdown> <DropdownButton id="dropdown-button" title={userData?.name.firstName} size="sm" + className={"dropDownMenu"} > <DropdownItem> - <Link to={USERINFO_URL}>Bruker Informasjon</Link> + <Link className={"link"} + to={USERINFO_URL}> + Bruker Informasjon</Link> </DropdownItem> <DropdownItem onClick={logOut}>Logg ut</DropdownItem> </DropdownButton> diff --git a/webstillas/src/components/userinformation/userInfo.js b/webstillas/src/components/userinformation/userInfo.js index e72f5c5052a26d32ea13633a6e34d999e6b2da00..1d50d082e222a83efd4df9118f910a8efc9a641b 100644 --- a/webstillas/src/components/userinformation/userInfo.js +++ b/webstillas/src/components/userinformation/userInfo.js @@ -18,6 +18,7 @@ export function UserInfo(){ let isLoadingUser, userData, isErrorUser + //If user is authenticated load user data if (auth.currentUser){ const {isLoading, data, isError} = GetDummyData("user", USER_URL + auth.currentUser.uid) isLoadingUser = isLoading diff --git a/webstillas/src/context/UserAuthContext.js b/webstillas/src/context/UserAuthContext.js index a5762e8a0ec65833358ede400b03d9539b724d26..f4e3fdefa1e5123dc786265bd503119c4f758fc8 100644 --- a/webstillas/src/context/UserAuthContext.js +++ b/webstillas/src/context/UserAuthContext.js @@ -63,6 +63,8 @@ export function UserAuthContextProvider({ children }) { }; }, []); + + return ( <userAuthContext.Provider value={{ user, logIn, signUp, logOut }} diff --git a/webstillas/src/modelData/constantsFile.js b/webstillas/src/modelData/constantsFile.js index 10dd7cb7b569ba5f3cd585810d5efd31d21e5d01..14d1732e4c275b698324c834c0d4f34128bf4781 100644 --- a/webstillas/src/modelData/constantsFile.js +++ b/webstillas/src/modelData/constantsFile.js @@ -4,10 +4,7 @@ export const SCAFFOLDING_URL = "unit" export const STORAGE_URL = "storage" export const USER_URL = "user?id=" export const USER_POST_URL = "user" - export const PROJECTS_URL = "project" -export const PROJECTS_URL_WITH_SCAFFOLDING = "project?scaffolding=true" - export const PROJECTS_URL_WITH_ID = "project?id=" export const WITH_SCAFFOLDING_URL = "&scaffolding=true" export const MAP_STYLE_V11 = "mapbox://styles/mapbox/streets-v11" diff --git a/webstillas/src/modelData/deleteProject.js b/webstillas/src/modelData/deleteProject.js index c4cb473388dca3c768fe955d0629518236322892..f461563b6ef3645ffef9b286fb1a4551122d732c 100644 --- a/webstillas/src/modelData/deleteProject.js +++ b/webstillas/src/modelData/deleteProject.js @@ -1,5 +1,12 @@ import {BASE_URL} from "./constantsFile" +/** + * Function that will send a delete request to an api. + * + * @param url to the request we would like to send + * @param body request body + * @returns {Promise<unknown>} + */ export default function deleteModel(url, body) { return new Promise(function (resolve, reject) { const xhr = new XMLHttpRequest(); diff --git a/webstillas/src/modelData/fetchData.js b/webstillas/src/modelData/fetchData.js index 05c88dfb827d196a8f613dc4e4815121d2b28d95..63689219143e7a0da3b215bfc77417702fe3b268 100644 --- a/webstillas/src/modelData/fetchData.js +++ b/webstillas/src/modelData/fetchData.js @@ -1,5 +1,11 @@ import {BASE_URL} from "./constantsFile" +/** + * Function to fetch data from an api + * + * @param url we would like to fetch data from. + * @returns {Promise<unknown>} + */ export default function fetchModel(url) { return new Promise(function (resolve, reject) { const xhr = new XMLHttpRequest(); diff --git a/webstillas/src/modelData/postModel.js b/webstillas/src/modelData/postModel.js index 0c85fee4e0e6ccd094d53c6973ea609daf24b840..4089f85426e4ef40b26bff7acc65d83f4205e6a5 100644 --- a/webstillas/src/modelData/postModel.js +++ b/webstillas/src/modelData/postModel.js @@ -1,5 +1,12 @@ import {BASE_URL} from "./constantsFile"; +/** + * Function to post data to an api + * + * @param url of the request we would like to send. + * @param body post body the user is sending to the api + * @returns {Promise<unknown>} + */ export default function postModel(url, body) { return new Promise(function (resolve, reject) { const xhr = new XMLHttpRequest(); diff --git a/webstillas/src/modelData/putData.js b/webstillas/src/modelData/putData.js index 2c8fea475d899ece5a1951a6f991d2d5cf28f43a..2b9f3b6272de8a4c53574acc53567c7fe5dc1a90 100644 --- a/webstillas/src/modelData/putData.js +++ b/webstillas/src/modelData/putData.js @@ -1,5 +1,13 @@ import {BASE_URL} from "./constantsFile"; + +/** + * Function to change data to the API + * + * @param url of the request we would like to send. + * @param body put body the user is sending to the api + * @returns {Promise<unknown>} + */ export default function putModel(url, body) { return new Promise(function (resolve, reject) { const xhr = new XMLHttpRequest();