Reac front end for psicometric app

temp.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import * as React from 'react';
  2. import TextField from '@mui/material/TextField';
  3. import Autocomplete from '@mui/material/Autocomplete';
  4. import CircularProgress from '@mui/material/CircularProgress';
  5. function sleep(delay = 0) {
  6. return new Promise((resolve) => {
  7. setTimeout(resolve, delay);
  8. });
  9. }
  10. export default function Asynchronous() {
  11. const [open, setOpen] = React.useState(false);
  12. const [options, setOptions] = React.useState([]);
  13. const loading = open && options.length === 0;
  14. React.useEffect(() => {
  15. let active = true;
  16. if (!loading) {
  17. return undefined;
  18. }
  19. (async () => {
  20. await sleep(1e3); // For demo purposes.
  21. if (active) {
  22. setOptions([...topFilms]);
  23. }
  24. })();
  25. return () => {
  26. active = false;
  27. };
  28. }, [loading]);
  29. React.useEffect(() => {
  30. if (!open) {
  31. setOptions([]);
  32. }
  33. }, [open]);
  34. return (
  35. <Autocomplete
  36. id="asynchronous-demo"
  37. sx={{ width: 300 }}
  38. open={open}
  39. onOpen={() => {
  40. setOpen(true);
  41. }}
  42. onClose={() => {
  43. setOpen(false);
  44. }}
  45. isOptionEqualToValue={(option, value) => option.title === value.title}
  46. getOptionLabel={(option) => option.title}
  47. options={options}
  48. loading={loading}
  49. renderInput={(params) => (
  50. <TextField
  51. {...params}
  52. label="Asynchronous"
  53. InputProps={{
  54. ...params.InputProps,
  55. endAdornment: (
  56. <React.Fragment>
  57. {loading ? <CircularProgress color="inherit" size={20} /> : null}
  58. {params.InputProps.endAdornment}
  59. </React.Fragment>
  60. ),
  61. }}
  62. />
  63. )}
  64. />
  65. );
  66. }
  67. // Top films as rated by IMDb users. http://www.imdb.com/chart/top
  68. const topFilms = [
  69. { title: 'The Shawshank Redemption', year: 1994 },
  70. { title: 'The Godfather', year: 1972 },
  71. { title: 'The Godfather: Part II', year: 1974 },
  72. { title: 'The Dark Knight', year: 2008 },
  73. { title: '12 Angry Men', year: 1957 },
  74. { title: "Schindler's List", year: 1993 },
  75. { title: 'Pulp Fiction', year: 1994 },
  76. {
  77. title: 'The Lord of the Rings: The Return of the King',
  78. year: 2003,
  79. },
  80. { title: 'The Good, the Bad and the Ugly', year: 1966 },
  81. { title: 'Fight Club', year: 1999 },
  82. {
  83. title: 'The Lord of the Rings: The Fellowship of the Ring',
  84. year: 2001,
  85. },
  86. {
  87. title: 'Star Wars: Episode V - The Empire Strikes Back',
  88. year: 1980,
  89. },
  90. { title: 'Forrest Gump', year: 1994 },
  91. { title: 'Inception', year: 2010 },
  92. {
  93. title: 'The Lord of the Rings: The Two Towers',
  94. year: 2002,
  95. },
  96. { title: "One Flew Over the Cuckoo's Nest", year: 1975 },
  97. { title: 'Goodfellas', year: 1990 },
  98. { title: 'The Matrix', year: 1999 },
  99. { title: 'Seven Samurai', year: 1954 },
  100. {
  101. title: 'Star Wars: Episode IV - A New Hope',
  102. year: 1977,
  103. },
  104. { title: 'City of God', year: 2002 },
  105. { title: 'Se7en', year: 1995 },
  106. { title: 'The Silence of the Lambs', year: 1991 },
  107. { title: "It's a Wonderful Life", year: 1946 },
  108. { title: 'Life Is Beautiful', year: 1997 },
  109. { title: 'The Usual Suspects', year: 1995 },
  110. { title: 'Léon: The Professional', year: 1994 },
  111. { title: 'Spirited Away', year: 2001 },
  112. { title: 'Saving Private Ryan', year: 1998 },
  113. { title: 'Once Upon a Time in the West', year: 1968 },
  114. { title: 'American History X', year: 1998 },
  115. { title: 'Interstellar', year: 2014 },
  116. ];