Skip to content

Commit

Permalink
cleaned code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo Serra committed Jul 17, 2022
1 parent 30938f4 commit 23fa941
Show file tree
Hide file tree
Showing 25 changed files with 1,009 additions and 984 deletions.
8 changes: 4 additions & 4 deletions src/Routes/Path.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Route, Routes, Switch, useLocation } from "react-router-dom";
import About from '../components/About/About.jsx'
import Home from "../components/Home/Home.jsx";
import Project from "../components/Project/Project.jsx";
import Work from '../components/Work/Work.jsx'
import NavBar from '../components/NavBar/NavBar.jsx'
import Error from '../components/Error/Error.jsx'
import Login from '../components/Login/Login.jsx'
import LoginPage from '../components/LogInPage/LoginPage.jsx'


export default function Path(){
Expand All @@ -23,9 +23,9 @@ export default function Path(){

<Route path="/" index element={<Home/>}/>
<Route path="about" element={<About/>}/>
<Route path="dashboard" element={<Login/>}/>
<Route path="dashboard" element={<LoginPage/>}/>

<Route path="work" element={<Work/>}>
<Route path="work" element={<NavBar/>}>
<Route path=":workName" element={<Project/>}/>
</Route>

Expand Down
22 changes: 8 additions & 14 deletions src/components/Context/DataContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ export default function DataContextProvider(props){


const [ project, setProject]=useState({})
const [ library, setLibrary]=useState()

const [ message , setMessage]=useState("")

// data from mongoose
const [ data, setData]=useState([])

const [ mainDataUpdate, setMainDataUpdate] = useState(false)

// alert messages

// variables for each input on the forms for creating a project or update a project
const [ title , setTitle ]= useState('')
const [ year, setYear ]= useState()
const [ description, setDescription ]= useState('')
Expand All @@ -37,16 +35,15 @@ export default function DataContextProvider(props){
const [ author, setAuthor ]= useState('')
const [ type, setType ]=useState("")


const [ render, setRender]=useState(false)


useEffect(()=>{

fetch("http://localhost:8000/project")
fetch(" https://ivoserrawebdev.herokuapp.com/project")
.then(response=> response.json())
.then(result => {
if(result.confirm){
setLibrary(result.project)
setMessage(result.message)
setData(result.project)
console.log('fetch')
Expand All @@ -55,14 +52,14 @@ export default function DataContextProvider(props){
})
.catch(error => console.log(error.message))

},[])
},[render])



const contextData = {
data,
data, setData,
type, setType,
title,setTitle,
title, setTitle,
year, setYear,
description, setDescription,
tools, setTools,
Expand All @@ -72,13 +69,10 @@ export default function DataContextProvider(props){
author, setAuthor,
image,setImage,
video, setVideo,
library, setLibrary,
project, setProject,
message, setMessage,
project, setProject,
mainDataUpdate, setMainDataUpdate,


render, setRender,
}


Expand Down
95 changes: 50 additions & 45 deletions src/components/Context/UserContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,76 @@ import {useState}from 'react'
export const UserContext =React.createContext(null)

export default function UserContextProvider(props){




// to open the dashboard is login is true
const [ login, setLogin ] = useState(false)
const [ update, setUpdate ] = useState(false)

// condition to distinguish admin from visitor
const [ visitor, setVisitor ] = useState(false)

// set the user when logged
const [ user, setUser ] = useState('')

// to confirm if the user has authority for create and delete projects
const [ authorization, setAuthorization]=useState(false)

// to open a window to update or edit a project
const [ updateProject, setUpdateProject ] = useState(false)

// to open the window of a new project to create
const [ newProject, setNewProject ] = useState(false)
const [ confirm, setConfirm ] = useState(false)


// condition when a project is successfully submited
const [ successful, setSuccessful ] = useState(false)

// state for delete button
const [ deleteButton, setDeleteButton ] = useState(false)

// state variable for specific alert messages from the backend
const [ alert, setAlert ] = useState('')


// register to open or close the register form
const [ register, setRegister ] = useState(false)

// state for specific messages from backend
const [ registerMsg, setRegisterMsg ] = useState('')

// state for specific messages on backend
const [ message, setMessage ]=useState('')

// state to warn user when visitor that cannot perform admin actions
const [ alertUser, setAlertUser ] = useState('')
const [ alertPassword, setAlertPassword ] = useState('')
const [ alertType, setAlertType ] = useState('')
const [ alertTitle, setAlertTitle ] = useState("")
const [ alertYear, setAlertYear ] = useState("")
const [ alertDescription, setAlertDescription ] = useState('')
const [ alertTools, setAlertTools ] = useState('')
const [ alertDeploy, setAlertDeploy ] = useState('')
const [ alertRepository, setAlertRepository ] = useState('')
const [ alertVideo, setAlertVideo ] = useState('')
const [ alertImage, setAlertImage ] = useState('')
const [ alertAuthor, setAlertAuthor ] = useState('')
const [ alertRegName, setAlertRegName ] = useState('')
const [ alertRegPass, setAlertRegPass ] = useState('')
const [ alertReg, setAlertReg ] = useState('')
const [ alertVisitorMsg, setAlertVisitorMsg] = useState('')


const [ name, setName ] = useState('')
const [ password, setPassword ] = useState('')
const [ regName, setRegName]=useState('')
const [ regPass, setRegPass]=useState('')
const [ visitor, setVisitor ] = useState(false)
const [ user, setUser ] = useState('')

const contextUser = {

login, setLogin,
update, setUpdate,
updateProject, setUpdateProject,
newProject, setNewProject,
confirm, setConfirm,
successful, setSuccessful,
register, setRegister,
registerMsg, setRegisterMsg,
message, setMessage,

alert, setAlert,
alertUser, setAlertUser,
alertPassword, setAlertPassword,
alertType, setAlertType,
alertTitle, setAlertTitle,
alertYear,setAlertYear,
alertDescription, setAlertDescription,
alertTools, setAlertTools,
alertDeploy, setAlertDeploy,
alertRepository, setAlertRepository,
alertVideo, setAlertVideo,
alertImage, setAlertImage,
alertAuthor, setAlertAuthor,
name, setName,
password, setPassword,


alertVisitorMsg, setAlertVisitorMsg,

deleteButton, setDeleteButton,
alertRegName,setAlertRegName,
alertRegPass, setAlertRegPass,
alertReg, setAlertReg,
visitor, setVisitor,
regName,setRegName,
regPass, setRegPass,
user, setUser


user, setUser,
authorization, setAuthorization,


}


Expand Down
Loading

0 comments on commit 23fa941

Please sign in to comment.