function Popular()

in Elastiflix/javascript-client/src/components/Popular.js [5:82]


function Popular({ movie, setMovie }) {
    class CustomConnector {
        constructor(host) {
          this.host = host;
        }
      
        async onSearch(query, options) {
          const response = await fetch(this.host + "/search", {
            method: "POST",
            headers: {
              "Content-Type": "application/json"
            },
            body: JSON.stringify({
              query,
              options
            })
          });
          return response.json();
        }
      
        async onAutocomplete(query, options) {
          const response = await fetch(this.host + "/autocomplete", {
            method: "POST",
            headers: {
              "Content-Type": "application/json"
            },
            body: JSON.stringify({
              query,
              options
            })
          });
          return response.json();
        }
      }
      
    const endpoint =  process.env.NODE_ENV === 'development' ?  process.env.REACT_APP_NODE_BACKEND_HOST : "${NODE_BACKEND_HOST}"
    const connector = new CustomConnector(endpoint);
    
    const config = {
        initialState: { sortDirection: "desc", sortField: "popularity", resultsPerPage: 10 },
        searchQuery: {
          search_fields: {
            title: {
              weight: 3
            }
          },
          result_fields: {
            title: {
              snippet: {}
            },
            poster_path: {
              snippet: {}
            },
            backdrop_path: {
                snippet: {}
              },
            overview: {
              snippet: {}
            },
            release_date: {
                snippet: {}
              },
            id: {
              snippet: {}
            },
            "workaround-popular": {
              snippet: {}
            }
          }
        },
        apiConnector: connector,
        alwaysSearchOnInitialLoad: true,
        trackUrlState: false
      };

    return (
        <SearchProvider config={config}>
            <WithSearch mapContextToProps={({ searchTerm, setSearchTerm, results }) => ({ searchTerm, setSearchTerm, results })}>