From dc3f934496e903708fe2d139e7ff4988003339f1 Mon Sep 17 00:00:00 2001
From: Gorkem Gokcek <140439905+gorkemgokcek@users.noreply.github.com>
Date: Tue, 28 Nov 2023 15:55:08 +0300
Subject: [PATCH] FSWeb-S7G1-cevaplandi
---
client/src/App.js | 44 ++++++++-----
client/src/Filmler/Film.js | 30 +++++----
client/src/Filmler/FilmCard.js | 74 +++++++++++++++++++++-
client/src/Filmler/FilmListesi.js | 26 ++------
client/src/Filmler/KaydedilenlerListesi.js | 9 ++-
client/src/index.js | 14 ++--
6 files changed, 142 insertions(+), 55 deletions(-)
diff --git a/client/src/App.js b/client/src/App.js
index 16257b22f..30c293a2c 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 daf0de32a..f951f7ae9 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 5e1996cab..8597245b4 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 cad454c25..c7af32278 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 270053b55..7a97b983d 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 e973c20f4..971c295e8 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(
+
+
);