diff --git a/package-lock.json b/package-lock.json index 1b34b08..aa89d6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", + "@mui/icons-material": "^5.13.7", "@mui/material": "^5.13.7", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", @@ -3189,6 +3190,27 @@ "resolved": "https://registry.npmmirror.com/@mui/core-downloads-tracker/-/core-downloads-tracker-5.13.7.tgz", "integrity": "sha512-/suIo4WoeL/OyO3KUsFVpdOmKiSAr6NpWXmQ4WLSxwKrTiha1FJxM6vwAki5W/5kR9WnVLw5E8JC4oHHsutT8w==" }, + "node_modules/@mui/icons-material": { + "version": "5.13.7", + "resolved": "https://registry.npmmirror.com/@mui/icons-material/-/icons-material-5.13.7.tgz", + "integrity": "sha512-zoVtkb9jYVUGfI7CobOdDBEAlpg3XESiO6cWqSDGwEma69+CBDIAwGpnO5truvQDJHBGSAfzFj3nObwxjkyA7Q==", + "dependencies": { + "@babel/runtime": "^7.22.5" + }, + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "@mui/material": "^5.0.0", + "@types/react": "^17.0.0 || ^18.0.0", + "react": "^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, "node_modules/@mui/material": { "version": "5.13.7", "resolved": "https://registry.npmmirror.com/@mui/material/-/material-5.13.7.tgz", diff --git a/package.json b/package.json index 1f6617e..6fcb795 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "dependencies": { "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", + "@mui/icons-material": "^5.13.7", "@mui/material": "^5.13.7", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", diff --git a/src/Components.js b/src/Components.js index 24470b9..a0402b0 100644 --- a/src/Components.js +++ b/src/Components.js @@ -1,4 +1,3 @@ -// Main.js import React, { useState, useEffect } from 'react'; import axios from 'axios'; import Container from '@mui/material/Container'; @@ -9,6 +8,7 @@ import CardContent from '@mui/material/CardContent'; import Typography from '@mui/material/Typography'; import Pagination from '@mui/material/Pagination'; import { Link } from 'react-router-dom'; +import CircularProgress from '@mui/material/CircularProgress'; const config = { Host: 'http://192.168.31.121:4444', @@ -22,9 +22,12 @@ const Main = () => { length: 1, }); + const [loading, setLoading] = useState(false); + const limit = 8; const fetchMovies = async (page) => { + setLoading(true); try { const response = await axios.get( `${config.Host}/movie/?page=${page}&limit=${limit}` @@ -42,6 +45,8 @@ const Main = () => { } } catch (error) { console.error('Error fetching movies:', error); + } finally { + setLoading(false); } }; @@ -54,35 +59,66 @@ const Main = () => { fetchMovies(value); }; + const truncateFilename = (filename, maxLength) => { + return filename.length > maxLength + ? filename.substring(0, maxLength - 3) + '...' + : filename; + }; + return (
- - {pagination.movies.map((item) => ( - - - - - - {item.filename} - - - - - ))} - + {loading ? ( +
+ +
+ ) : ( + + {pagination.movies.map((item) => ( + + + + + + + {truncateFilename(item.filename, 20)} + + + + + + ))} + + )}
@@ -91,6 +127,8 @@ const Main = () => { page={pagination.page} onChange={handlePageChange} shape="rounded" + color="primary" + size="large" />