зеркало из https://github.com/microsoft/helium-ui.git
No more duplicates! The Ultimate Refresh. (#15)
* fixed: doesn't delete movie on Cancel button from edit * potential fix * cleaning code, making editmovie setstate * fixed filter of genres so remove works * removing console.logs, cleaning lines * Scrolly polly olly! scroll works for roles what a party * THE FIX : * no longer need scroll package. solution from CSS * changing color of genres
This commit is contained in:
Родитель
dd9a6dcbc5
Коммит
de1d175838
|
@ -1456,9 +1456,9 @@
|
||||||
"integrity": "sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw=="
|
"integrity": "sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw=="
|
||||||
},
|
},
|
||||||
"@types/react": {
|
"@types/react": {
|
||||||
"version": "16.8.17",
|
"version": "16.8.23",
|
||||||
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.8.17.tgz",
|
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.8.23.tgz",
|
||||||
"integrity": "sha512-pln3mgc6VfkNg92WXODul/ONo140huK9OMsx62GlBlZ2lvjNK86PQJhYMPLO1i66aF5O9OPyZefogvNltBIszA==",
|
"integrity": "sha512-abkEOIeljniUN9qB5onp++g0EY38h7atnDHxwKUFz1r3VH1+yG1OKi2sNPTyObL40goBmfKFpdii2lEzwLX1cA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/prop-types": "*",
|
"@types/prop-types": "*",
|
||||||
"csstype": "^2.2.0"
|
"csstype": "^2.2.0"
|
||||||
|
@ -1472,6 +1472,15 @@
|
||||||
"@types/react": "*"
|
"@types/react": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/react-scroll": {
|
||||||
|
"version": "1.5.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/react-scroll/-/react-scroll-1.5.4.tgz",
|
||||||
|
"integrity": "sha512-EYJt9wDvyrcDZpZqI19eb2UlAzCoXBeoFu3yMkrBDC8zkwFXOhb8lv3tD9V9UAqptora096M7qWYktsWq1guEg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/react": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/react-transition-group": {
|
"@types/react-transition-group": {
|
||||||
"version": "2.9.1",
|
"version": "2.9.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-2.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-2.9.1.tgz",
|
||||||
|
|
|
@ -44,6 +44,11 @@
|
||||||
border: orange;
|
border: orange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.roleScroll {
|
||||||
|
height: 160px;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
.App-header {
|
.App-header {
|
||||||
background-color: #282c34;
|
background-color: #282c34;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
|
|
82
src/App.tsx
82
src/App.tsx
|
@ -35,6 +35,7 @@ import MovieCard from './components/movieComp';
|
||||||
import { Movie, Actor, Genre } from './models/models';
|
import { Movie, Actor, Genre } from './models/models';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import { createStyles, withStyles, WithStyles } from '@material-ui/core/styles';
|
import { createStyles, withStyles, WithStyles } from '@material-ui/core/styles';
|
||||||
|
|
||||||
const heliumApi = 'https://heliumint.azurewebsites.net/api/';
|
const heliumApi = 'https://heliumint.azurewebsites.net/api/';
|
||||||
const cors = 'https://cors-anywhere.herokuapp.com/';
|
const cors = 'https://cors-anywhere.herokuapp.com/';
|
||||||
|
|
||||||
|
@ -49,6 +50,13 @@ const styles = createStyles({
|
||||||
margin: 0,
|
margin: 0,
|
||||||
backgroundColor: "#556cd6",
|
backgroundColor: "#556cd6",
|
||||||
},
|
},
|
||||||
|
drawer: {
|
||||||
|
width: 240,
|
||||||
|
flexShrink: 0,
|
||||||
|
},
|
||||||
|
newChip: {
|
||||||
|
backgroundColor: "#FFC730"
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
|
@ -108,27 +116,18 @@ class App extends React.Component<AllProps> {
|
||||||
// grab genre data from api
|
// grab genre data from api
|
||||||
axios.get(cors + heliumApi + 'genres').then(response => {
|
axios.get(cors + heliumApi + 'genres').then(response => {
|
||||||
const genreData: Genre[] = response.data
|
const genreData: Genre[] = response.data
|
||||||
this.setState({
|
this.setState({genres: genreData})
|
||||||
genres: genreData
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
// grab movie data from api
|
// grab movie data from api
|
||||||
axios.get(cors + heliumApi + 'movies').then(response => {
|
axios.get(cors + heliumApi + 'movies').then(response => {
|
||||||
const moviesData: Movie[] = response.data
|
const moviesData: Movie[] = response.data
|
||||||
this.setState({
|
this.setState({movies: moviesData})
|
||||||
movies: moviesData
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
// grab actor data from api
|
// grab actor data from api
|
||||||
axios.get(cors + heliumApi + 'actors').then(response => {
|
axios.get(cors + heliumApi + 'actors').then(response => {
|
||||||
const actorsData: Actor[] = response.data
|
const actorsData: Actor[] = response.data
|
||||||
this.setState({
|
this.setState({actors: actorsData})
|
||||||
actors: actorsData
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
@ -190,9 +189,6 @@ class App extends React.Component<AllProps> {
|
||||||
genres: movie.genres,
|
genres: movie.genres,
|
||||||
movieId: movie.movieId,
|
movieId: movie.movieId,
|
||||||
}})
|
}})
|
||||||
|
|
||||||
this.setState({movies: this.state.movies.filter(item => item !== movie)})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteMultipleMovies = () => {
|
deleteMultipleMovies = () => {
|
||||||
|
@ -213,43 +209,43 @@ class App extends React.Component<AllProps> {
|
||||||
};
|
};
|
||||||
|
|
||||||
checkBoxToggle = (id: string, checkBox: boolean) => {
|
checkBoxToggle = (id: string, checkBox: boolean) => {
|
||||||
console.log(id);
|
|
||||||
// remove card from array of deleted movies
|
// remove card from array of deleted movies
|
||||||
if(checkBox === true) {
|
if(checkBox === true) {
|
||||||
this.state.deleteMovies.pop();
|
this.state.deleteMovies.pop();
|
||||||
console.log(this.state.deleteMovies);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add card to array of deleted movies
|
// add card to array of deleted movies
|
||||||
if(checkBox === false) {
|
if(checkBox === false) {
|
||||||
this.state.deleteMovies.push(id);
|
this.state.deleteMovies.push(id);
|
||||||
console.log(this.state.deleteMovies);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handles edit on exisiting movie's form
|
// handles edit on exisiting movie's form
|
||||||
handleEdit = (subMovie: Movie) => {
|
handleEdit = (subMovie: Movie) => {
|
||||||
let movies = this.state.movies;
|
let movies = this.state.movies.slice();
|
||||||
this.setState({snackBarMessage: "Edited " + this.state.formsMovie.title + " to " + subMovie.title, openForms: false, postSuccessAlert: true});
|
this.setState({snackBarMessage: "Edited " + subMovie.title, openForms: false, postSuccessAlert: true});
|
||||||
|
|
||||||
movies.push(subMovie);
|
for (let i = 0; i < movies.length; i++) {
|
||||||
|
if (movies[i].movieId === subMovie.movieId) {
|
||||||
|
movies[i].year = subMovie.year;
|
||||||
|
movies[i].title = subMovie.title;
|
||||||
|
movies[i].runtime = subMovie.runtime;
|
||||||
|
movies[i].genres = subMovie.genres;
|
||||||
|
movies[i].roles = subMovie.roles;
|
||||||
|
}
|
||||||
|
}
|
||||||
this.setState({movies})
|
this.setState({movies})
|
||||||
}
|
}
|
||||||
|
|
||||||
// on forms submit button clicked
|
// on forms submit button clicked
|
||||||
submitMovie = (values: Movie, action:FormikActions<Movie>) => {
|
submitMovie = (values: Movie, action:FormikActions<Movie>) => {
|
||||||
let movies = this.state.movies;
|
let movies = this.state.movies;
|
||||||
let formsMovie = this.state.formsMovie;
|
|
||||||
let subMovie: Movie;
|
|
||||||
let allGenres = [];
|
let allGenres = [];
|
||||||
let currentGenres = this.state.formsMovie.genres;
|
let currentGenres = this.state.formsMovie.genres;
|
||||||
let newGenres = this.state.movieGenres;
|
let newGenres = this.state.movieGenres;
|
||||||
|
|
||||||
allGenres = currentGenres.concat(newGenres);
|
allGenres = currentGenres.concat(newGenres);
|
||||||
console.log(allGenres);
|
|
||||||
console.log("current " + currentGenres);
|
|
||||||
|
|
||||||
subMovie = {
|
let subMovie: Movie = {
|
||||||
title: values.title,
|
title: values.title,
|
||||||
year: values.year,
|
year: values.year,
|
||||||
runtime: values.runtime,
|
runtime: values.runtime,
|
||||||
|
@ -265,13 +261,9 @@ class App extends React.Component<AllProps> {
|
||||||
// if editing a movie, perform axios PUT
|
// if editing a movie, perform axios PUT
|
||||||
if(this.state.formsTitle === "Edit Movie")
|
if(this.state.formsTitle === "Edit Movie")
|
||||||
{
|
{
|
||||||
axios.put(cors + heliumApi + 'movies/' + values.id, subMovie)
|
axios.put(cors + heliumApi + 'movies/' + values.movieId, subMovie)
|
||||||
.then(action => {this.handleEdit(subMovie)})
|
.then(action => {this.handleEdit(subMovie)})
|
||||||
.catch(error => {console.log(error.response)})
|
.catch(error => {console.log(error.response)})
|
||||||
// this.setState({movies: this.state.movies.filter(items => items.movieId !== this.state.formsMovie.movieId )})
|
|
||||||
// this.setState({movies: this.state.movies.filter(items => items !== this.state.formsMovie )})
|
|
||||||
console.log(values);
|
|
||||||
this.setState({movies: this.state.movies.filter(item => item !== values)})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,28 +281,16 @@ class App extends React.Component<AllProps> {
|
||||||
handleSearchFilter = (movie: Movie) => {
|
handleSearchFilter = (movie: Movie) => {
|
||||||
let input = this.state.textSearch;
|
let input = this.state.textSearch;
|
||||||
|
|
||||||
if(this.state.textSearch === '') {
|
if(this.state.textSearch === '') {return true}
|
||||||
return true;
|
if(movie.title.toLowerCase().includes(input)){return movie}
|
||||||
}
|
|
||||||
if(movie.title.toLowerCase().includes(input)){
|
|
||||||
return movie;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCurrentGenreRemove = (selected: string) => {
|
handleCurrentGenreRemove = (selected: string) => {
|
||||||
console.log(selected);
|
this.setState({movieGenres: this.state.movieGenres.filter(genre => genre !== selected)})
|
||||||
|
this.state.formsMovie.genres.pop()
|
||||||
// remove selected genre from formsmovie genre list
|
|
||||||
this.setState({formsMovie: {
|
|
||||||
genres: this.state.formsMovie.genres.filter(genres => genres !== selected),
|
|
||||||
}});
|
|
||||||
|
|
||||||
console.log(this.state.formsMovie.genres)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNewGenreRemove = (selected: string) => {
|
handleNewGenreRemove = (selected: string) => {
|
||||||
console.log(selected);
|
|
||||||
|
|
||||||
// remove selected genre from moviegenre list
|
// remove selected genre from moviegenre list
|
||||||
this.setState({movieGenres: this.state.movieGenres.filter(genre => genre !== selected)})
|
this.setState({movieGenres: this.state.movieGenres.filter(genre => genre !== selected)})
|
||||||
console.log(this.state.formsMovie.genres)
|
console.log(this.state.formsMovie.genres)
|
||||||
|
@ -323,7 +303,6 @@ class App extends React.Component<AllProps> {
|
||||||
// add new genre to list
|
// add new genre to list
|
||||||
newMovies.push(selectedGenre);
|
newMovies.push(selectedGenre);
|
||||||
this.setState(newMovies);
|
this.setState(newMovies);
|
||||||
console.log("movie genres" + this.state.movieGenres);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -410,6 +389,7 @@ class App extends React.Component<AllProps> {
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12}>
|
<Grid item xs={12}>
|
||||||
<InputLabel>Roles</InputLabel>
|
<InputLabel>Roles</InputLabel>
|
||||||
|
<div className="roleScroll">
|
||||||
{this.state.formsMovie.roles.map((item:any) => (
|
{this.state.formsMovie.roles.map((item:any) => (
|
||||||
<List>
|
<List>
|
||||||
<ListItem>
|
<ListItem>
|
||||||
|
@ -424,6 +404,8 @@ class App extends React.Component<AllProps> {
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</List>
|
</List>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
</div>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12}>
|
<Grid item xs={12}>
|
||||||
<div>
|
<div>
|
||||||
|
@ -434,7 +416,7 @@ class App extends React.Component<AllProps> {
|
||||||
))}
|
))}
|
||||||
<br />
|
<br />
|
||||||
{this.state.movieGenres.map(genre => (
|
{this.state.movieGenres.map(genre => (
|
||||||
<Chip color="secondary" label={genre} onDelete={() => {this.handleNewGenreRemove(genre)}} />
|
<Chip className={classes.newChip} label={genre} onDelete={() => {this.handleNewGenreRemove(genre)}} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -68,7 +68,6 @@ class movieComp extends React.Component<IProps> {
|
||||||
|
|
||||||
editMovie = (event: React.MouseEvent<HTMLLIElement, MouseEvent>) => {
|
editMovie = (event: React.MouseEvent<HTMLLIElement, MouseEvent>) => {
|
||||||
this.props.editMovie(this.state.movie);
|
this.props.editMovie(this.state.movie);
|
||||||
console.log(this.state.movie)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleCheck = (event: React.ChangeEvent<HTMLInputElement>) => {
|
toggleCheck = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче