FolderList.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React from 'react';
  2. import { makeStyles } from '@material-ui/core/styles';
  3. import GridList from '@material-ui/core/GridList';
  4. import GridListTile from '@material-ui/core/GridListTile';
  5. import GridListTileBar from '@material-ui/core/GridListTileBar';
  6. import ListSubheader from '@material-ui/core/ListSubheader';
  7. import IconButton from '@material-ui/core/IconButton';
  8. import InfoIcon from '@material-ui/icons/Info';
  9. import tileData from './tileData';
  10. import { useEffect } from 'react';
  11. import imageList from './imageList.js';
  12. const useStyles = makeStyles((theme) => ({
  13. root: {
  14. display: 'flex',
  15. flexWrap: 'wrap',
  16. justifyContent: 'space-around',
  17. overflow: 'hidden',
  18. },
  19. gridList: {
  20. width: '100%',
  21. height: '100%',
  22. },
  23. icon: {
  24. color: 'rgba(255, 255, 255, 0.54)',
  25. },
  26. }));
  27. /**
  28. * The example data is structured as follows:
  29. *
  30. * import image from 'path/to/image.jpg';
  31. * [etc...]
  32. *
  33. * const tileData = [
  34. * {
  35. * img: image,
  36. * title: 'Image',
  37. * author: 'author',
  38. * },
  39. * {
  40. * [etc...]
  41. * },
  42. * ];
  43. */
  44. export default function TitlebarGridList(props) {
  45. const classes = useStyles();
  46. const [error, setError] = React.useState(null);
  47. const [isLoaded, setIsLoaded] = React.useState(false);
  48. const [items, setItems] = React.useState([]);
  49. const [folderName, setFolderName] = React.useState('user:/Photo/Photo/uploads/');
  50. const onChanageFolder = (folderN) => {
  51. setFolderName(folderN);
  52. console.log("1" + folderName);
  53. props.onChange(folderN);
  54. }
  55. useEffect(() => {
  56. //fetch("http://localhost:3000/listFolder")
  57. fetch("/system/ajgi/interface?script=/Photo/backend/listFolder.js", {
  58. method: 'post',
  59. body: JSON.stringify({ folder: folderName })
  60. })
  61. .then(res => res.json())
  62. .then(
  63. (result) => {
  64. setIsLoaded(true);
  65. setItems(result);
  66. },
  67. // Note: it's important to handle errors here
  68. // instead of a catch() block so that we don't swallow
  69. // exceptions from actual bugs in components.
  70. (error) => {
  71. setIsLoaded(true);
  72. setError(error);
  73. }
  74. )
  75. }, [])
  76. if (error) {
  77. return <div>Error: {error.message}</div>;
  78. } else if (!isLoaded) {
  79. return <div>Loading...</div>;
  80. } else {
  81. return (
  82. <div className={classes.root}>
  83. <GridList cellHeight={180} cols={5} className={classes.gridList}>
  84. {items.map((tile) => (
  85. <GridListTile key={tile.img}>
  86. <img src={tile.img} alt={tile.Foldername} />
  87. <GridListTileBar
  88. title={tile.Foldername}
  89. actionIcon={
  90. <IconButton aria-label={`info about ${tile.Foldername}`} onClick={() => onChanageFolder(tile.VPath)} className={classes.icon}>
  91. <InfoIcon />
  92. </IconButton>
  93. }
  94. />
  95. </GridListTile>
  96. ))}
  97. </GridList>
  98. </div>
  99. );
  100. }
  101. }