tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

YelpRealtimeSuggestions.sys.mjs (3628B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 import { RealtimeSuggestProvider } from "moz-src:///browser/components/urlbar/private/RealtimeSuggestProvider.sys.mjs";
      6 
      7 /**
      8 * A feature that supports Yelp realtime suggestions.
      9 */
     10 export class YelpRealtimeSuggestions extends RealtimeSuggestProvider {
     11  get realtimeType() {
     12    // Ideally this would simply be "yelp" but we want to avoid confusion with
     13    // offline Yelp suggestions.
     14    return "yelpRealtime";
     15  }
     16 
     17  get isSponsored() {
     18    return true;
     19  }
     20 
     21  get merinoProvider() {
     22    return "yelp";
     23  }
     24 
     25  makeMerinoResult(queryContext, suggestion, searchString) {
     26    return super.makeMerinoResult(queryContext, suggestion, searchString, {
     27      // Group label settings.
     28      hideRowLabel: false,
     29      rowLabel: {
     30        id: "urlbar-result-yelp-realtime-group-label",
     31      },
     32    });
     33  }
     34 
     35  getViewTemplateForDescriptionTop(_item, index) {
     36    return [
     37      {
     38        name: `title_${index}`,
     39        tag: "span",
     40        classList: ["urlbarView-yelpRealtime-title"],
     41      },
     42    ];
     43  }
     44 
     45  getViewTemplateForDescriptionBottom(_item, index) {
     46    return [
     47      {
     48        name: `address_${index}`,
     49        tag: "span",
     50        classList: ["urlbarView-yelpRealtime-description-address"],
     51      },
     52      {
     53        tag: "span",
     54        classList: ["urlbarView-realtime-description-separator-dot"],
     55      },
     56      {
     57        name: `pricing_${index}`,
     58        tag: "span",
     59        classList: ["urlbarView-yelpRealtime-description-pricing"],
     60      },
     61      {
     62        tag: "span",
     63        classList: ["urlbarView-realtime-description-separator-dot"],
     64      },
     65      {
     66        name: `business_hours_${index}`,
     67        tag: "span",
     68        classList: ["urlbarView-yelpRealtime-description-business-hours"],
     69      },
     70      {
     71        tag: "span",
     72        classList: ["urlbarView-realtime-description-separator-dot"],
     73      },
     74      {
     75        tag: "span",
     76        classList: ["urlbarView-yelpRealtime-description-popularity-star"],
     77      },
     78      {
     79        name: `popularity_${index}`,
     80        tag: "span",
     81        classList: ["urlbarView-yelpRealtime-description-popularity"],
     82      },
     83    ];
     84  }
     85 
     86  getViewUpdateForPayloadItem(item, index) {
     87    return {
     88      [`item_${index}`]: {
     89        attributes: {
     90          state: item.business_hours[0].is_open_now ? "open" : "closed",
     91        },
     92      },
     93      [`image_${index}`]: {
     94        attributes: {
     95          src: item.image_url,
     96        },
     97      },
     98      [`title_${index}`]: {
     99        textContent: item.name,
    100      },
    101      [`address_${index}`]: {
    102        textContent: item.address,
    103      },
    104      [`pricing_${index}`]: {
    105        textContent: item.pricing,
    106      },
    107      [`business_hours_${index}`]: {
    108        l10n: {
    109          id: item.business_hours[0].is_open_now
    110            ? "urlbar-result-yelp-realtime-business-hours-open"
    111            : "urlbar-result-yelp-realtime-business-hours-closed",
    112          args: {
    113            // TODO: Need to pass "time until keeping the status" after resolving
    114            // the timezone issue.
    115            timeUntil: new Intl.DateTimeFormat(undefined, {
    116              hour: "numeric",
    117            }).format(new Date()),
    118          },
    119          parseMarkup: true,
    120        },
    121      },
    122      [`popularity_${index}`]: {
    123        l10n: {
    124          id: "urlbar-result-yelp-realtime-popularity",
    125          args: {
    126            rating: item.rating,
    127            review_count: item.review_count,
    128          },
    129        },
    130      },
    131    };
    132  }
    133 }