DlgzRogelio / Project-1

MIT License
0 stars 1 forks source link

TMDB API: Save the data inside arrays/objects #23

Closed DlgzRogelio closed 2 years ago

ca2los commented 2 years ago

STORE THE VALUES

When the user initialize the search filter by entering an INPUT, the program will retrieve the value and look for all the results related to word. Once the program finds the data, it will filter the results by "Name", "ID", "Profile", "Profile Path", "Known For" and "Popularity".

This data is an abstract or short biography of the actor

The user should click to the actor of his/her interest. That is why the results are showing the "Profile" URL. Remember: The abstract will be inside the Cards.

@CONSOLE

    let api_key = '94f0c60308f2a42f4c8a0265000556cd';
    let submit_button = document.getElementById( 'submit');

    function api_tmdb() {

        submit_button.addEventListener('click',function(event) {
            event.preventDefault();

            let input_actor = document.getElementById('name').value;
            let request_movie = 'https://api.themoviedb.org/3/search/person?api_key=' + api_key + '&language=en-US&query=' + input_actor + '&page=1&include_adult=false';
            console.log('Results related to: ' + input_actor.toUpperCase());

            fetch(request_movie).then(function (response) {
                return response.json();
            })
            .then(function(data) {
                for (let artist in data.results) {
                    let id = data.results[artist].id;
                    let name = data.results[artist].name;
                    let known_for = data.results[artist].known_for;
                    let popularity = data.results[artist].popularity;
                    let profile_path = data.results[artist].profile_path;
                    let link = 'https://api.themoviedb.org/3/search/person?api_key=' + api_key + '&language=en-US&query=' + name.replace(/ /g, '%20') + '&page=1&include_adult=false';

                    let new_array = {
                        name:name,
                        id:id,
                        known_for:known_for,
                        profile_path:profile_path,
                        link:link,
                        popularity:popularity
                    };
                    console.log(new_array);
                }
            });
        });
    }
    api_tmdb();

You may find useful to look for the previous versions to understand how I got to this solution: #22 & #18


Team, plz feel free to share some comments with me. cc @DlgzRogelio @ltrevino @ian-dot