tor-browser

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

SectionContextMenu.jsx (1730B)


      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 https://mozilla.org/MPL/2.0/. */
      4 
      5 import React, { useState } from "react";
      6 import { LinkMenu } from "../../LinkMenu/LinkMenu";
      7 
      8 /**
      9 * A context menu for blocking, following and unfollowing sections.
     10 *
     11 * @param props
     12 * @returns {React.FunctionComponent}
     13 */
     14 export function SectionContextMenu({
     15  type = "DISCOVERY_STREAM",
     16  title,
     17  source,
     18  index,
     19  dispatch,
     20  sectionKey,
     21  following,
     22  sectionPersonalization,
     23  sectionPosition,
     24 }) {
     25  // Initial context menu options: block this section only.
     26  const SECTIONS_CONTEXT_MENU_OPTIONS = ["SectionBlock"];
     27  const [showContextMenu, setShowContextMenu] = useState(false);
     28 
     29  if (following) {
     30    SECTIONS_CONTEXT_MENU_OPTIONS.push("SectionUnfollow");
     31  }
     32 
     33  const onClick = e => {
     34    e.preventDefault();
     35    setShowContextMenu(!showContextMenu);
     36  };
     37 
     38  const onUpdate = () => {
     39    setShowContextMenu(!showContextMenu);
     40  };
     41 
     42  return (
     43    <div className="section-context-menu">
     44      <moz-button
     45        type="icon"
     46        size="default"
     47        iconsrc="chrome://global/skin/icons/more.svg"
     48        title={title || source}
     49        onClick={onClick}
     50      />
     51      {showContextMenu && (
     52        <LinkMenu
     53          onUpdate={onUpdate}
     54          dispatch={dispatch}
     55          index={index}
     56          source={type.toUpperCase()}
     57          options={SECTIONS_CONTEXT_MENU_OPTIONS}
     58          shouldSendImpressionStats={true}
     59          site={{
     60            sectionPersonalization,
     61            sectionKey,
     62            sectionPosition,
     63            title,
     64          }}
     65        />
     66      )}
     67    </div>
     68  );
     69 }