Reac front end for psicometric app

temp.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. import * as React from 'react';
  2. import TextField from '@mui/material/TextField';
  3. import Dialog from '@mui/material/Dialog';
  4. import DialogTitle from '@mui/material/DialogTitle';
  5. import DialogContent from '@mui/material/DialogContent';
  6. import DialogContentText from '@mui/material/DialogContentText';
  7. import DialogActions from '@mui/material/DialogActions';
  8. import Button from '@mui/material/Button';
  9. import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
  10. const filter = createFilterOptions();
  11. export default function FreeSoloCreateOptionDialog() {
  12. const [value, setValue] = React.useState(null);
  13. const [open, toggleOpen] = React.useState(false);
  14. const handleClose = () => {
  15. setDialogValue({
  16. title: '',
  17. year: '',
  18. });
  19. toggleOpen(false);
  20. };
  21. const [dialogValue, setDialogValue] = React.useState({
  22. title: '',
  23. year: '',
  24. });
  25. const handleSubmit = (event) => {
  26. event.preventDefault();
  27. setValue({
  28. title: dialogValue.title,
  29. year: parseInt(dialogValue.year, 10),
  30. });
  31. handleClose();
  32. };
  33. return (
  34. <React.Fragment>
  35. <Autocomplete
  36. value={value}
  37. onChange={(event, newValue) => {
  38. if (typeof newValue === 'string') {
  39. // timeout to avoid instant validation of the dialog's form.
  40. setTimeout(() => {
  41. toggleOpen(true);
  42. setDialogValue({
  43. title: newValue,
  44. year: '',
  45. });
  46. });
  47. } else if (newValue && newValue.inputValue) {
  48. toggleOpen(true);
  49. setDialogValue({
  50. title: newValue.inputValue,
  51. year: '',
  52. });
  53. } else {
  54. setValue(newValue);
  55. }
  56. }}
  57. filterOptions={(options, params) => {
  58. const filtered = filter(options, params);
  59. if (params.inputValue !== '') {
  60. filtered.push({
  61. inputValue: params.inputValue,
  62. title: `Add "${params.inputValue}"`,
  63. });
  64. }
  65. return filtered;
  66. }}
  67. id="free-solo-dialog-demo"
  68. options={top100Films}
  69. getOptionLabel={(option) => {
  70. // e.g value selected with enter, right from the input
  71. if (typeof option === 'string') {
  72. return option;
  73. }
  74. if (option.inputValue) {
  75. return option.inputValue;
  76. }
  77. return option.title;
  78. }}
  79. selectOnFocus
  80. clearOnBlur
  81. handleHomeEndKeys
  82. renderOption={(props, option) => <li {...props}>{option.title}</li>}
  83. sx={{ width: 300 }}
  84. freeSolo
  85. renderInput={(params) => <TextField {...params} label="Free solo dialog" />}
  86. />
  87. <Dialog open={open} onClose={handleClose}>
  88. <form onSubmit={handleSubmit}>
  89. <DialogTitle>Add a new film</DialogTitle>
  90. <DialogContent>
  91. <DialogContentText>
  92. Did you miss any film in our list? Please, add it!
  93. </DialogContentText>
  94. <TextField
  95. autoFocus
  96. margin="dense"
  97. id="name"
  98. value={dialogValue.title}
  99. onChange={(event) =>
  100. setDialogValue({
  101. ...dialogValue,
  102. title: event.target.value,
  103. })
  104. }
  105. label="title"
  106. type="text"
  107. variant="standard"
  108. />
  109. <TextField
  110. margin="dense"
  111. id="name"
  112. value={dialogValue.year}
  113. onChange={(event) =>
  114. setDialogValue({
  115. ...dialogValue,
  116. year: event.target.value,
  117. })
  118. }
  119. label="year"
  120. type="number"
  121. variant="standard"
  122. />
  123. </DialogContent>
  124. <DialogActions>
  125. <Button onClick={handleClose}>Cancel</Button>
  126. <Button type="submit">Add</Button>
  127. </DialogActions>
  128. </form>
  129. </Dialog>
  130. </React.Fragment>
  131. );
  132. }
  133. // Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
  134. const top100Films = [
  135. { title: 'The Shawshank Redemption', year: 1994 },
  136. { title: 'The Godfather', year: 1972 },
  137. { title: 'The Godfather: Part II', year: 1974 },
  138. { title: 'The Dark Knight', year: 2008 },
  139. { title: '12 Angry Men', year: 1957 },
  140. { title: "Schindler's List", year: 1993 },
  141. { title: 'Pulp Fiction', year: 1994 },
  142. {
  143. title: 'The Lord of the Rings: The Return of the King',
  144. year: 2003,
  145. },
  146. { title: 'The Good, the Bad and the Ugly', year: 1966 },
  147. { title: 'Fight Club', year: 1999 },
  148. {
  149. title: 'The Lord of the Rings: The Fellowship of the Ring',
  150. year: 2001,
  151. },
  152. {
  153. title: 'Star Wars: Episode V - The Empire Strikes Back',
  154. year: 1980,
  155. },
  156. { title: 'Forrest Gump', year: 1994 },
  157. { title: 'Inception', year: 2010 },
  158. {
  159. title: 'The Lord of the Rings: The Two Towers',
  160. year: 2002,
  161. },
  162. { title: "One Flew Over the Cuckoo's Nest", year: 1975 },
  163. { title: 'Goodfellas', year: 1990 },
  164. { title: 'The Matrix', year: 1999 },
  165. { title: 'Seven Samurai', year: 1954 },
  166. {
  167. title: 'Star Wars: Episode IV - A New Hope',
  168. year: 1977,
  169. },
  170. { title: 'City of God', year: 2002 },
  171. { title: 'Se7en', year: 1995 },
  172. { title: 'The Silence of the Lambs', year: 1991 },
  173. { title: "It's a Wonderful Life", year: 1946 },
  174. { title: 'Life Is Beautiful', year: 1997 },
  175. { title: 'The Usual Suspects', year: 1995 },
  176. { title: 'Léon: The Professional', year: 1994 },
  177. { title: 'Spirited Away', year: 2001 },
  178. { title: 'Saving Private Ryan', year: 1998 },
  179. { title: 'Once Upon a Time in the West', year: 1968 },
  180. { title: 'American History X', year: 1998 },
  181. { title: 'Interstellar', year: 2014 },
  182. { title: 'Casablanca', year: 1942 },
  183. { title: 'City Lights', year: 1931 },
  184. { title: 'Psycho', year: 1960 },
  185. { title: 'The Green Mile', year: 1999 },
  186. { title: 'The Intouchables', year: 2011 },
  187. { title: 'Modern Times', year: 1936 },
  188. { title: 'Raiders of the Lost Ark', year: 1981 },
  189. { title: 'Rear Window', year: 1954 },
  190. { title: 'The Pianist', year: 2002 },
  191. { title: 'The Departed', year: 2006 },
  192. { title: 'Terminator 2: Judgment Day', year: 1991 },
  193. { title: 'Back to the Future', year: 1985 },
  194. { title: 'Whiplash', year: 2014 },
  195. { title: 'Gladiator', year: 2000 },
  196. { title: 'Memento', year: 2000 },
  197. { title: 'The Prestige', year: 2006 },
  198. { title: 'The Lion King', year: 1994 },
  199. { title: 'Apocalypse Now', year: 1979 },
  200. { title: 'Alien', year: 1979 },
  201. { title: 'Sunset Boulevard', year: 1950 },
  202. {
  203. title: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
  204. year: 1964,
  205. },
  206. { title: 'The Great Dictator', year: 1940 },
  207. { title: 'Cinema Paradiso', year: 1988 },
  208. { title: 'The Lives of Others', year: 2006 },
  209. { title: 'Grave of the Fireflies', year: 1988 },
  210. { title: 'Paths of Glory', year: 1957 },
  211. { title: 'Django Unchained', year: 2012 },
  212. { title: 'The Shining', year: 1980 },
  213. { title: 'WALL·E', year: 2008 },
  214. { title: 'American Beauty', year: 1999 },
  215. { title: 'The Dark Knight Rises', year: 2012 },
  216. { title: 'Princess Mononoke', year: 1997 },
  217. { title: 'Aliens', year: 1986 },
  218. { title: 'Oldboy', year: 2003 },
  219. { title: 'Once Upon a Time in America', year: 1984 },
  220. { title: 'Witness for the Prosecution', year: 1957 },
  221. { title: 'Das Boot', year: 1981 },
  222. { title: 'Citizen Kane', year: 1941 },
  223. { title: 'North by Northwest', year: 1959 },
  224. { title: 'Vertigo', year: 1958 },
  225. {
  226. title: 'Star Wars: Episode VI - Return of the Jedi',
  227. year: 1983,
  228. },
  229. { title: 'Reservoir Dogs', year: 1992 },
  230. { title: 'Braveheart', year: 1995 },
  231. { title: 'M', year: 1931 },
  232. { title: 'Requiem for a Dream', year: 2000 },
  233. { title: 'Amélie', year: 2001 },
  234. { title: 'A Clockwork Orange', year: 1971 },
  235. { title: 'Like Stars on Earth', year: 2007 },
  236. { title: 'Taxi Driver', year: 1976 },
  237. { title: 'Lawrence of Arabia', year: 1962 },
  238. { title: 'Double Indemnity', year: 1944 },
  239. {
  240. title: 'Eternal Sunshine of the Spotless Mind',
  241. year: 2004,
  242. },
  243. { title: 'Amadeus', year: 1984 },
  244. { title: 'To Kill a Mockingbird', year: 1962 },
  245. { title: 'Toy Story 3', year: 2010 },
  246. { title: 'Logan', year: 2017 },
  247. { title: 'Full Metal Jacket', year: 1987 },
  248. { title: 'Dangal', year: 2016 },
  249. { title: 'The Sting', year: 1973 },
  250. { title: '2001: A Space Odyssey', year: 1968 },
  251. { title: "Singin' in the Rain", year: 1952 },
  252. { title: 'Toy Story', year: 1995 },
  253. { title: 'Bicycle Thieves', year: 1948 },
  254. { title: 'The Kid', year: 1921 },
  255. { title: 'Inglourious Basterds', year: 2009 },
  256. { title: 'Snatch', year: 2000 },
  257. { title: '3 Idiots', year: 2009 },
  258. { title: 'Monty Python and the Holy Grail', year: 1975 },
  259. ];