/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// eslint-disable-next-line no-unused-vars
import React, { useEffect, useRef, useState } from "react";
import { useSelector } from "react-redux";
import { actionCreators as ac, actionTypes as at } from "common/Actions.mjs";
// Stream URLs come from an untrusted backend, so only allow http(s) through to
// the href; anything else (e.g. javascript:) renders as a non-navigating link.
function safeStreamUrl(url) {
try {
return ["http:", "https:"].includes(new URL(url).protocol) ? url : "";
} catch (e) {
return "";
}
}
// Map known backend entitlement strings to localized tag IDs. Anything not in
// this map falls back to the raw string from `stream.entitlement`.
const ENTITLEMENT_L10N_IDS = {
free: "newtab-sports-widget-watch-stream-free",
"free trial": "newtab-sports-widget-watch-stream-free-trial",
"free and paid": "newtab-sports-widget-watch-stream-free-paid",
paid: "newtab-sports-widget-watch-stream-paid",
"select games only": "newtab-sports-widget-watch-stream-select-games-only",
};
const WIDGET_NAME = "sports";
const WIDGET_SOURCE = "widget";
const USER_ACTION_TYPES = {
OPEN: "open",
DISMISS: "dismiss",
STREAM_CLICK: "stream_click",
};
function StreamRow({ stream, dispatch, widgetSize }) {
const entitlementL10nId =
ENTITLEMENT_L10N_IDS[stream.entitlement?.toLowerCase()];
const handleClick = () => {
dispatch(
ac.OnlyToMain({
type: at.WIDGETS_USER_EVENT,
data: {
widget_name: WIDGET_NAME,
widget_source: WIDGET_SOURCE,
user_action: USER_ACTION_TYPES.STREAM_CLICK,
widget_size: widgetSize,
action_value: stream.product_name,
},
})
);
};
return (