From 2270e1c0269ab8650efc9e878158a8127acc3730 Mon Sep 17 00:00:00 2001 From: haraldnilsen Date: Thu, 19 Oct 2023 09:32:48 +0200 Subject: [PATCH] :sparkles: error handling and new start.sh-file Co-authored-by: Sindre Kjelsrud --- backend/start.sh | 4 ---- frontend/src/App.tsx | 11 ++++++++++- frontend/src/api/fetchMovie.ts | 4 ++-- start.sh | 13 +++++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) delete mode 100644 backend/start.sh create mode 100644 start.sh diff --git a/backend/start.sh b/backend/start.sh deleted file mode 100644 index 3111271..0000000 --- a/backend/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -docker-compose up -d - -cd cinemateket -dotnet run \ No newline at end of file diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index e9e3fad..bfe1e55 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -14,6 +14,7 @@ function App() { const [totalPages, setTotalPages] = useState(0) const [modalOpen, setModalOpen] = useState(false) const [modalMovie, setModalMovie] = useState(null) + const [message, setMessage] = useState('Find a list of movies by searching above ☝️') const navigateToPage = useNavigateToPage() const searchParams = new URLSearchParams(window.location.search) const [movieTitle, setMovieTitle] = useState(searchParams.get('s') || '') @@ -26,6 +27,14 @@ function App() { const handleFetchMovie = async () => { const response = await fetchMovie(title, page, type, year) console.log(year) + if (response == undefined) { + setMovies([]) + setTotalPages(0) + setCurrentPage(1) + setLoading(false) + setMessage("We unfortunately didn't have any movies matching your search 😭") + return + } if (response.response == 'OK') { setMovies(response.search) setTotalPages(Number(response.totalResults)) @@ -118,7 +127,7 @@ function App() { ) : movies.length > 0 ? ( ) : ( - Find a list of movies by searching above ☝️ + {message} )} diff --git a/frontend/src/api/fetchMovie.ts b/frontend/src/api/fetchMovie.ts index 5c7edd7..aeaf363 100644 --- a/frontend/src/api/fetchMovie.ts +++ b/frontend/src/api/fetchMovie.ts @@ -7,8 +7,8 @@ export const fetchMovie = async ( page: string = '1', type?: string, year?: string -): Promise => { - let query = `http://localhost:5212/movie?s=${title}&page=${page}` +): Promise=> { + let query = `http://localhost:5212/movie?s=${title}&pageNumber=${page}` if (type) query += `&type=${type}` if (year) query += `&y=${year}` diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..08d6355 --- /dev/null +++ b/start.sh @@ -0,0 +1,13 @@ +# backend +cd backend +docker-compose up -d + +cd cinemateket +dotnet run & + +cd ../.. + +# frontend +cd frontend +npm install +npm run dev \ No newline at end of file