Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';

import { Route } from 'react-router-dom';
import Film from './Filmler/Film';
import FilmListesi from "./Filmler/FilmListesi";
import KaydedilenlerListesi from './Filmler/KaydedilenlerListesi';

export default function App () {
Expand All @@ -12,6 +14,7 @@ export default function App () {
axios
.get('http://localhost:5001/api/filmler') // Burayı Postman'le çalışın
.then(response => {
setMovieList(response.data);
// Bu kısmı log statementlarıyla çalışın
// ve burdan gelen response'u 'movieList' e aktarın
})
Expand All @@ -22,15 +25,26 @@ export default function App () {
FilmleriAl();
}, []);

const KaydedilenlerListesineEkle = id => {
const KaydedilenlerListesineEkle = (movie) => {
const newArr = saved;
newArr.find((e) => e.id === movie.id) !== null && newArr.push(movie);
setSaved([...newArr]);
// Burası esnek. Aynı filmin birden fazla kez "saved" e eklenmesini engelleyin
};

return (
<div>
<KaydedilenlerListesi list={[ /* Burası esnek */]} />

<div>Bu Div'i kendi Routelarınızla değiştirin</div>
<KaydedilenlerListesi list={[ saved]} />
<Route exact path="/">
<FilmListesi movies ={movieList} />
</Route>
<Route path="/filmler/:id">
<Film
KaydedilenlerListesineEkle={KaydedilenlerListesineEkle}
saved={saved}
/>
</Route>

</div>
);
}
9 changes: 7 additions & 2 deletions client/src/Filmler/Film.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { useParams } from "react-router-dom";
import KaydedilenlerListesi from './KaydedilenlerListesi';

export default function Film(props) {
const [movie, setMovie] = useState();
const { KaydedilenlerListesineEkle } = 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 => {
setMovie(response.data);
// Bu kısmı log statementlarıyla çalışın
// ve burdan gelen response'u 'movie' e aktarın
})
Expand Down Expand Up @@ -48,7 +52,8 @@ export default function Film(props) {
</div>
))}
</div>
<div className="save-button">Kaydet</div>
<div className="save-button" onClick={() => KaydedilenlerListesineEkle(movie)}>
Kaydet</div>
</div>
);
}
6 changes: 5 additions & 1 deletion client/src/Filmler/FilmListesi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { Link } from 'react-router-dom';


export default function FilmListesi(props) {
return (
Expand All @@ -11,17 +13,19 @@ export default function FilmListesi(props) {
}

function FilmDetayları(props) {
const { title, director, metascore } = props.movie;
const { title, director, metascore, id } = props.movie;

return (
<div className="movie-card">
<Link to={`/filmler/${id}`}>
<h2>{title}</h2>
<div className="movie-director">
Director: <em>{director}</em>
</div>
<div className="movie-metascore">
Metascore: <strong>{metascore}</strong>
</div>
</Link>
</div>
);
}
8 changes: 7 additions & 1 deletion client/src/Filmler/KaydedilenlerListesi.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import React from 'react';
import { useHistory } from 'react-router-dom';

export default function KaydedilenlerListesi(props) {
const history = useHistory();
function handleClick() {
history.push("/");
}
return (
<div className="saved-list">
<h3>Kaydedilen Filmler:</h3>
{props.list.map(movie => (
<span className="saved-movie">{movie.title}</span>
))}
<div className="home-button">Anasayfa</div>
<div className="home-button" onClick={handleClick}>
Anasayfa</div>
</div>
);
}
7 changes: 5 additions & 2 deletions client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom';

import { BrowserRouter } from 'react-router-dom';
import './index.css';
import App from './App';


// Routeların çalışması için <App /> öğesini düzenlemeniz gerekir
ReactDOM.render(<App />, document.getElementById('root'));
ReactDOM.render(
<BrowserRouter><App />
</BrowserRouter>,
document.getElementById('root'));