Advertisement
sak1b

autocomplete

Feb 9th, 2021
1,292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* eslint-disable no-use-before-define */
  2. import React, { Dispatch, useState } from 'react';
  3. import Chip from '@material-ui/core/Chip';
  4. import Autocomplete from '@material-ui/lab/Autocomplete';
  5. import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
  6. import TextField from '@material-ui/core/TextField';
  7. import { useSelector } from 'react-redux';
  8. import { RootStore } from '../Store';
  9. import { RepoDispatchTypes, RepoXType } from '../actions/RepoActionTypes';
  10.  
  11. const useStyles = makeStyles((theme: Theme) =>
  12.   createStyles({
  13.     root: {
  14.       // display: 'flex',
  15.       // flexDirection: 'column',
  16.       // justifyContent: 'center',
  17.       // alignItems: 'center',
  18.       width: '50%',
  19.       // '& > * + *': {
  20.       //   marginTop: theme.spacing(3),
  21.       // },
  22.     },
  23.   }),
  24. );
  25.  
  26. export default function Tags() {
  27.  
  28.   const classes = useStyles();
  29.  
  30.   const repoState = useSelector((state: RootStore) => state.repo);
  31.   let repoList: RepoXType[] = [];
  32.   let names = [];
  33.  
  34.   if(repoState.user?.allRepo)
  35.   {
  36.     repoList = repoState.user.allRepo;
  37.  
  38.     // repoList.map(item => {
  39.     //   names.push(item.name);
  40.     // });
  41.   }
  42.   const [input, setInput] = React.useState<RepoXType | null>()
  43.   const Register = (v: any) => async (dispatch: Dispatch<RepoDispatchTypes>) => {
  44.    
  45.     setInput(v);
  46.     console.log(v);
  47.  
  48.   };
  49.  
  50.   // const handleChange = (values: any) => dispatch(Register(values));
  51.   const [selectValue, setSelectValue] = useState();
  52.  
  53.  
  54.  
  55.   return (
  56.     <div className={classes.root}>
  57.       <Autocomplete
  58.         multiple
  59.         id="tags-standard"
  60.         options={repoList}
  61.         getOptionLabel={(option: RepoXType) => option.name}
  62.         // onChange={handleChange(e,values)}
  63.         //defaultValue={[top100Films[13]]}
  64.         //onChange={(e,v) => handleChange(v)}
  65.          renderInput={(params) => (
  66.           <TextField
  67.             {...params}
  68.             variant="standard"
  69.             label="Repositories"
  70.             placeholder=""
  71.           />
  72.         )}
  73.       />
  74.  
  75.  
  76.       {/* <Autocomplete
  77.       options={repoList}
  78.       getOptionLabel={(option: RepoXType) => option.name}
  79.       inputValue={"" | input.name}
  80.       onChange={(e,v) => setInput(v)}
  81.       style={{ width: 300 }}
  82.       renderInput={(params) => (
  83.         <TextField {...params} label="Combo box" onChange={({ target }) => setInput(target)} variant="outlined" fullWidth />
  84.       )}
  85.       /> */}
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.     </div>
  93.   );
  94. }
  95.  
  96.  
  97. function dispatch(arg0: (dispatch: Dispatch<RepoDispatchTypes>) => Promise<void>) {
  98.   throw new Error('Function not implemented.');
  99. }
  100. // Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
  101. // const top100Films = [
  102. //   { title: 'The Shawshank Redemption', year: 1994 },
  103. //   { title: 'The Godfather', year: 1972 },
  104. //   { title: 'Monty Python and the Holy Grail', year: 1975 },
  105. // ];
  106.  
  107. //==================================
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement