Advertisement
markRobertSara

half done frontend

Jul 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState } from 'react';
  2. //import i{ relative } from 'path';
  3. import { Grid, Container, Paper, Typography, TextField, Button, ButtonGroup } from '@material-ui/core'
  4.  
  5. function App() {
  6.   /*const [ware,setWare] = useState("");
  7.   const [weight,setWeight] = useState("");
  8.   const [price,setPrice] = useState("");
  9.   const [wares,setWares] = useState([]);
  10.   const [weights, setWeights] = useState([]);
  11.   const [prices, setPrices] = useState([]);
  12.  
  13.   let sumw = 0;
  14.   let sump = 0;
  15.   let rows = [];
  16.  
  17.   for(let i = 0; i < wares.length; i++){
  18.       rows.push(<tr><th>{wares[i]}</th><th>{weights[i]}</th><th>{prices[i]}</th></tr>);
  19.       sumw += parseFloat(weights[i]);
  20.       sump += parseFloat(prices[i]);
  21.   }
  22.  
  23.  
  24.   return (
  25.     <div className="App">
  26.       <header className="App-header">
  27.         Sum:{sumw}<br/>
  28.         Price:{sump}<br/>
  29.         <table>
  30.           <tablebody>
  31.             {rows}
  32.           </tablebody>
  33.         </table>
  34.         <p>
  35.           <input type="text" value = {ware}  onChange={e => setWare(e.target.value)}/>
  36.           <input type="number"  value = {weight}  onChange={e => setWeight(e.target.value)} />
  37.           <input type="number"  value = {price}  onChange={e => setPrice(e.target.value)} />
  38.  
  39.           <button type = "button" onClick = {
  40.            
  41.             () =>
  42.             (setWares([...wares,ware]), setWeights([...weights,weight]),setPrices([...prices,price]),
  43.  
  44.               setWare(""), setPrice(""),setWeight(""))}>Add</button>
  45.         </p>
  46.       </header>
  47.     </div>
  48.   );
  49.  
  50.   const [oneName, setOneName] = useState("");
  51.   const [names, setnames] = useState([]);
  52.   let comps = [];
  53.  
  54.   for(let i = 0; i < names.length;i++){
  55.       comps.push(<Competitor  name = {names[i]} key = {i}/>);
  56.   }
  57.  
  58.   return(
  59.     <div>
  60.       <input type="text" value = {oneName}  onChange={e => setOneName(e.target.value)}/>
  61.       <button type = "button" onClick = { () => (setnames([...names,oneName]), setOneName(""))}>Add competitor</button>
  62.       {names.map((name,i) => {
  63.         return(<Competitor  name = {name} key = {i}/>);
  64.       })}
  65.     </div>
  66.   )
  67. }
  68.  
  69. function Competitor(props){
  70.       const [score,setScore] = useState(0);
  71.  
  72.   return(
  73.     <div>
  74.         {props.name}{" "}
  75.         {score}{" "}
  76.         <button type = "button" onClick = {() =>setScore(score+1)} >Add point</button>
  77.         <button type = "button" onClick = {() =>score > 0 && setScore(score+-1)} >Lower points</button>
  78.     </div>
  79.   )
  80. */
  81.   const [deps, setDeps] = useState([]);
  82.   const [locs, setLocs] = useState([]);
  83.   const [dests, setDests] = useState([]);
  84.   const [IDs, setIDs] = useState([]);
  85.   const [gates, setGates] = useState([]);
  86.  
  87.   let test =deps.map((dep, i) => {return(
  88.     <GenerateFlight deptime = {deps[i]} location = {locs[i]}
  89.     destination = {dests[i]} ID = {IDs[i]} key = {IDs[i]} gate ={gates[i]}/>);
  90.    
  91.     })
  92.  
  93.  
  94.  
  95.  
  96.   return (
  97.  
  98.     <Container fixed>
  99.       <Grid container spacing={3}>
  100.  
  101.           <h1 align="center">Egy nagyszerű cím</h1>
  102.         </Grid>
  103.         <Grid container sx = {12}>
  104.             {test}
  105.         </Grid>
  106.           <Paper>
  107.           <AddFlight setDeps = {setDeps} deps = {deps} locs = {locs} setLocs = {setLocs} dests = {dests} setDests = {setDests}
  108.           IDs = {IDs} setIDs = {setIDs} gates ={gates} setGates = {setGates}/>
  109.           </Paper>
  110.  
  111.  
  112.    
  113.     </Container>
  114.   )
  115.  
  116. }
  117.  
  118. function GenerateFlight(props) {
  119.   const [deptime, setDeptime] = useState(props.deptime);
  120.   const [location, setLocation] = useState(props.location);
  121.   const [destination, setDestination] = useState(props.destination);
  122.   const [ID, setID] = useState(props.ID);
  123.   const [gate, setGate] = useState(props.gate);
  124.   const [isEditing, setEdit] = useState(false);
  125.   const [del, setDel] = useState(false);
  126.  
  127.   if(del){
  128.     return null
  129.   }
  130.   if (!isEditing ) {
  131.     return (
  132.       <Grid item xs = {12}>
  133.         <Paper>
  134.       <ButtonGroup fullWidth = {true} variant='contained'>
  135.         <Button disabled={true}>{deptime}</Button>
  136.         <Button disabled={true}>{location}</Button>
  137.         <Button disabled={true}>{destination}</Button>
  138.         <Button disabled={true}>{ID}</Button>
  139.         <Button disabled={true}>{gate}</Button>
  140.         <Button onClick={() => setEdit(true)}>EDIT</Button>
  141.       </ButtonGroup>
  142.       </Paper>
  143.       </Grid>
  144.     )
  145.   }
  146.   else {
  147.     return (
  148.       <Typography variant="h5">
  149.       <Grid container xs = {12}>
  150.         <Grid item>
  151.           <TextField value={deptime} onChange={e => setDeptime(e.target.value)}></TextField>
  152.         </Grid>
  153.         <Grid item>
  154.           <TextField value={location} onChange={e => setLocation(e.target.value)}></TextField>
  155.         </Grid>
  156.         <Grid item>
  157.           <TextField value={destination} onChange={e => setDestination(e.target.value)}></TextField>
  158.         </Grid>
  159.         <Grid item>
  160.           <TextField value={ID} onChange={e => setID(e.target.value)}></TextField>
  161.         </Grid>
  162.         <Grid item>
  163.           <TextField value={gate} onChange={e => setGate(e.target.value)}></TextField>
  164.         </Grid>
  165.         <Grid item>
  166.           <Button onClick={() => setEdit(false)}>DONE</Button>
  167.         </Grid>
  168.         <Grid item>
  169.           <Button onClick = {() => setDel(true)}>DELETE</Button>
  170.         </Grid>
  171.       </Grid>
  172.       </Typography>
  173.  
  174.     )
  175.   }
  176.  
  177. }
  178.  
  179.  
  180. function AddFlight(props) {
  181.   const [dept,setDept] = useState("");
  182.   const [loc,setLoc] = useState("");
  183.   const [id,setID] = useState("");
  184.   const [dest,setDest] = useState("");
  185.   const [gate,setGate] = useState("");
  186.  
  187.   return (
  188.       <Typography variant="h5">
  189.       <Grid container  sx = {10} spacing = {1}>
  190.         <Grid item>
  191.           <TextField  label = "Time" value ={dept}onChange={e => setDept(e.target.value)} margin = "normal"></TextField>
  192.         </Grid>
  193.  
  194.         <Grid item>
  195.           <TextField label = "Location" value ={loc}  onChange={e => setLoc(e.target.value)}margin = "normal"></TextField>
  196.         </Grid>
  197.  
  198.         <Grid item>
  199.           <TextField  label = "Destination" value ={dest} onChange={e => setDest(e.target.value)}margin = "normal"></TextField>
  200.         </Grid>
  201.  
  202.         <Grid item>
  203.           <TextField label = "ID" value ={id} onChange={e => setID(e.target.value)}margin = "normal"></TextField>
  204.         </Grid>
  205.  
  206.         <Grid item>
  207.           <TextField label = "Gate" value ={gate} onChange={e => setGate(e.target.value)}margin = "normal"></TextField>
  208.         </Grid>
  209.  
  210.         <Grid item>
  211.           <Button  variant = "contained" onClick ={() => (id === "" || dept === "" || loc === "" || dest === "" || gate === ""
  212.           || (props.setDeps([...props.deps,dept]), props.setLocs([...props.locs,loc]), props.setDests([...props.dests,dest]), props.setIDs([...props.IDs,id]), props.setGates([...props.gates,gate]),
  213.  
  214.            setDept(""),setLoc(""),setDest(""),setID(""),setGate("")) )}>ADD</Button>
  215.           </Grid>
  216.       </Grid>
  217.       </Typography>
  218.   )
  219.  
  220. }
  221.  
  222.  
  223.  
  224.  
  225. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement