Qwiddle / moovie

0 stars 0 forks source link

Use TMDB's multi search and filter those results #2

Closed Qwiddle closed 2 years ago

Qwiddle commented 2 years ago

Expected Behavior

Filter the ResultList based on the conditions set by the user.

Current Behavior

N/A not implemented yet.

Possible Solution

Instead of querying both movies & tv shows in separate API calls, it'd be best to instead use their "multi" search that returns all content. This will also return people which is unwanted, so I'll need to filter those out.

Steps to Reproduce

N/A

Detailed Description

Using multi search, check for following variables to understand the type of result returned:

'name' - tv 'title' - movie 'known_for' - person

Possible Implementation


const { isLoading, data } = useQuery(['search', input], async () => {
    const res = await fetch(`https://api.themoviedb.org/3/search/multi?api_key=${process.env.REACT_APP_API_TMDB}&query=${input}`)
    return res.json();
  }, { 
    enabled: !!input 
});

--
data ? 
 <div className="results">
    if(data.results.title) {
        {data.results.map((movie) => (
          <div key={movie.id}>
              <h1>{movie.title}</h1>
              <p>{movie.overview}</p>
              <strong>👀 {movie.popularity}</strong>{' '}
              <strong>✨ {movie.vote_average}</strong>{' '}
              <strong>🍴 {movie.vote_count}</strong>
          </div>
        ))}
    } else if (data.results.name) {
    ......
    } else if (data.results.known_for {
    ........
    } 
</div> : ''
Qwiddle commented 2 years ago

Implemented in these two commits! https://github.com/Qwiddle/moovie/commit/6e92e29ca8a059b3c9dee66fc37a08bf68ec55a1 https://github.com/Qwiddle/moovie/commit/f8456a51b64cdd59bc6dd3c44ccd8f6e44fea6c8

Should've made a PR to do this but that's okay :)