diff --git a/client/src/App.js b/client/src/App.js index 16257b22..30c293a2 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,36 +1,50 @@ -import React, { useState, useEffect } from 'react'; -import axios from 'axios'; +import React, { useState, useEffect } from "react"; +import axios from "axios"; +import { Switch, Route } from "react-router-dom"; +import KaydedilenlerListesi from "./Filmler/KaydedilenlerListesi"; +import FilmListesi from "./Filmler/FilmListesi"; +import FilmCard from "./Filmler/FilmCard"; -import KaydedilenlerListesi from './Filmler/KaydedilenlerListesi'; - -export default function App () { +export default function App() { const [saved, setSaved] = useState([]); // Stretch: the ids of "saved" movies const [movieList, setMovieList] = useState([]); useEffect(() => { const FilmleriAl = () => { axios - .get('http://localhost:5001/api/filmler') // Burayı Postman'le çalışın - .then(response => { + .get("http://localhost:5001/api/filmler") // Burayı Postman'le çalışın + .then((response) => { + console.log(response); + setMovieList(response.data); // Bu kısmı log statementlarıyla çalışın // ve burdan gelen response'u 'movieList' e aktarın }) - .catch(error => { - console.error('Sunucu Hatası', error); + .catch((error) => { + console.error("Sunucu Hatası", error); }); - } + }; FilmleriAl(); }, []); - const KaydedilenlerListesineEkle = id => { + const KaydedilenlerListesineEkle = (movie) => { + if (!saved.includes(movie)) { + setSaved([...saved, movie]); + } + // Burası esnek. Aynı filmin birden fazla kez "saved" e eklenmesini engelleyin }; return (
- - -
Bu Div'i kendi Routelarınızla değiştirin
+ + + + + + + + +
); -} +} \ No newline at end of file diff --git a/client/src/Filmler/Film.js b/client/src/Filmler/Film.js index daf0de32..f951f7ae 100644 --- a/client/src/Filmler/Film.js +++ b/client/src/Filmler/Film.js @@ -1,28 +1,34 @@ -import React, { useState, useEffect } from 'react'; -import axios from 'axios'; +import React, { useState, useEffect } from "react"; +import axios from "axios"; +import { useParams } from "react-router-dom/cjs/react-router-dom.min"; +import KaydedilenlerListesi from "./KaydedilenlerListesi"; export default function Film(props) { const [movie, setMovie] = useState(); + const { kaydet } = props; - let id = 1; + let { id } = useParams(); // URL'den alınan :id parametresini bu değişkene aktarın useEffect(() => { axios .get(`http://localhost:5001/api/filmler/${id}`) // Bu uç noktayı Postman'le çalışın - .then(response => { - // Bu kısmı log statementlarıyla çalışın - // ve burdan gelen response'u 'movie' e aktarın + .then((response) => { + setMovie(response.data); + // Bu kısmı log statementlarıyla çalışın + // ve burdan gelen response'u 'movie' e aktarın }) - .catch(error => { + .catch((error) => { console.error(error); }); // Bu effect her `id ` değiştiğinde çalışmalı // Bunu nasıl gerçekleştirebiliriz? - }, []); + }, [id]); // Yalnızca esnek görevlere geçtiğinizde burdaki yorum etiketini kaldırın - // const filmiKaydet = evt => { } + const filmiKaydet = (evt) => { + kaydet(movie); + }; if (!movie) { return
Film bilgisi yükleniyor...
; @@ -42,13 +48,15 @@ export default function Film(props) {

Actors

- {stars.map(star => ( + {stars.map((star) => (
{star}
))} - + ); } diff --git a/client/src/Filmler/FilmCard.js b/client/src/Filmler/FilmCard.js index 5e1996ca..8597245b 100644 --- a/client/src/Filmler/FilmCard.js +++ b/client/src/Filmler/FilmCard.js @@ -1,5 +1,73 @@ -import React from 'react'; +import React, { useState, useEffect } from "react"; +import axios from "axios"; +import { useParams } from "react-router-dom/cjs/react-router-dom.min"; +import KaydedilenlerListesi from "./KaydedilenlerListesi"; -export default function FilmCard (props) { - return; +export default function Film(props) { + const [movie, setMovie] = useState(); + const { kaydet } = props; + const { film } = props; + + let { id } = useParams(); + // URL'den alınan :id parametresini bu değişkene aktarın + + useEffect(() => { + if (film) { + setMovie(film); + } + if (id) { + axios + .get(`http://localhost:5001/api/filmler/${id}`) // Bu uç noktayı Postman'le çalışın + .then((response) => { + setMovie(response.data); + // Bu kısmı log statementlarıyla çalışın + // ve burdan gelen response'u 'movie' e aktarın + }) + .catch((error) => { + console.error(error); + }); + // Bu effect her `id ` değiştiğinde çalışmalı + // Bunu nasıl gerçekleştirebiliriz? + } + }, [id]); + + // Yalnızca esnek görevlere geçtiğinizde burdaki yorum etiketini kaldırın + const filmiKaydet = (evt) => { + kaydet(movie); + }; + + if (!movie) { + return
Film bilgisi yükleniyor...
; + } + + const { title, director, metascore, stars } = movie; + + return ( +
+
+

{title}

+
+ Director: {director} +
+
+ Metascore: {metascore} +
+ {!film && ( + <> +

Actors

+ {stars.map((star) => ( +
+ {star} +
+ ))} + + )} +
+ {!film && ( + + )} +
+ ); } diff --git a/client/src/Filmler/FilmListesi.js b/client/src/Filmler/FilmListesi.js index cad454c2..c7af3227 100644 --- a/client/src/Filmler/FilmListesi.js +++ b/client/src/Filmler/FilmListesi.js @@ -1,27 +1,15 @@ -import React from 'react'; +import React from "react"; +import FilmCard from "./FilmCard"; +import { Link } from "react-router-dom/cjs/react-router-dom.min"; export default function FilmListesi(props) { return (
- {props.movies.map(movie => ( - + {props.movies.map((movie) => ( + + {" "} + ))}
); - } - -function FilmDetayları(props) { - const { title, director, metascore } = props.movie; - - return ( -
-

{title}

-
- Director: {director} -
-
- Metascore: {metascore} -
-
- ); } diff --git a/client/src/Filmler/KaydedilenlerListesi.js b/client/src/Filmler/KaydedilenlerListesi.js index 270053b5..7a97b983 100644 --- a/client/src/Filmler/KaydedilenlerListesi.js +++ b/client/src/Filmler/KaydedilenlerListesi.js @@ -1,13 +1,20 @@ import React from "react"; +import { Link, useHistory } from "react-router-dom/cjs/react-router-dom.min"; export default function KaydedilenlerListesi(props) { + const history = useHistory(); + const handleClick = () => { + history.push("/"); + }; return (

Kaydedilen Filmler:

{props.list.map((movie) => ( {movie.title} ))} - +
); } diff --git a/client/src/index.js b/client/src/index.js index e973c20f..971c295e 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -1,13 +1,15 @@ -import React from 'react'; -import ReactDOM from 'react-dom/client'; - -import './index.css'; -import App from './App'; +import React from "react"; +import ReactDOM from "react-dom/client"; +import { BrowserRouter } from "react-router-dom"; +import "./index.css"; +import App from "./App"; // Routeların çalışması için öğesini düzenlemeniz gerekir -const root = ReactDOM.createRoot(document.getElementById('root')); +const root = ReactDOM.createRoot(document.getElementById("root")); root.render( + + );