<commit_before>//@flow
import * as React from 'react';
import { memo, useContext, useMemo, useState } from 'react';

import GAProvider from '../ga-provider.jsx';

import { gettext } from '../l10n.js';
import type { DocumentData } from '../document.jsx';

type Props = {
    document?: ?DocumentData,
    locale: string
};

// To avoid problems with flow and React.memo(), define the component
// in this plain way first. See bottom of file for the final memo() and export.
const _MainMenu = ({ document, locale }: Props) => {
    // The CSS that supports this is sufficiently smart to understand
    // hovering over the top-level menu items and stuff. But for mobile,
    // there's no mouse hover so for that we use a piece of state to
    // record onTouchStart events.
    const [showSubMenu, setShowSubMenu] = useState(null);
    const ga = useContext(GAProvider.context);

    /**
     * Send a signal to GA when there is an interaction on one
     * of the main menu items.
     * @param {Object} event - The event object that was triggered
     */
    function sendMenuItemInteraction(event) {
        // What could happen is that this is a click and right before the
        // click there was a mouseover on the same target. If that's the
        // case bail early.
        if (previousMouseover && event.target === previousMouseover) {
            return;
        }

        const label = event.target.href || event.target.textContent;

        ga('send', {
            hitType: 'event',
            eventCategory: 'Wiki',
            eventAction: 'MainNav',
            eventLabel: label
        });
    }

    /**
     * Selectively pass on a trigger to sendMenuItemInteraction() because
     * onMouseOver is tricky. Not only might you trigger an onMouseover on
     * an element that isn't the actual button, if you mousever, mouseout,
     * and then mouseover the same thing again, it should only count once.
     * @param {Object} event - the event object that was triggered
     */
    function menuMouseoverHandler(event) {
        // Only the buttons that have this count.
        if (event.target.getAttribute('aria-haspopup') === 'true') {
            if (event.target !== previousMouseover) {
                sendMenuItemInteraction(event);
                previousMouseover = event.target;
            }
        }
    }
    // In-component memory of which DOM element was mouseover'ed last time
    let previousMouseover = null;

    // The menus array includes objects that define the set of<commit_msg>Correct small typo in event name within comment (#6542)<commit_after>//@flow
import * as React from 'react';
import { memo, useContext, useMemo, useState } from 'react';

import GAProvider from '../ga-provider.jsx';

import { gettext } from '../l10n.js';
import type { DocumentData } from '../document.jsx';

type Props = {
    document?: ?DocumentData,
    locale: string
};

// To avoid problems with flow and React.memo(), define the component
// in this plain way first. See bottom of file for the final memo() and export.
const _MainMenu = ({ document, locale }: Props) => {
    // The CSS that supports this is sufficiently smart to understand
    // hovering over the top-level menu items and stuff. But for mobile,
    // there's no mouse hover so for that we use a piece of state to
    // record onTouchStart events.
    const [showSubMenu, setShowSubMenu] = useState(null);
    const ga = useContext(GAProvider.context);

    /**
     * Send a signal to GA when there is an interaction on one
     * of the main menu items.
     * @param {Object} event - The event object that was triggered
     */
    function sendMenuItemInteraction(event) {
        // What could happen is that this is a click and right before the
        // click there was a mouseover on the same target. If that's the
        // case bail early.
        if (previousMouseover && event.target === previousMouseover) {
            return;
        }

        const label = event.target.href || event.target.textContent;

        ga('send', {
            hitType: 'event',
            eventCategory: 'Wiki',
            eventAction: 'MainNav',
            eventLabel: label
        });
    }

    /**
     * Selectively pass on a trigger to sendMenuItemInteraction() because
     * onMouseOver is tricky. Not only might you trigger an onMouseover on
     * an element that isn't the actual button, if you mouseover, mouseout,
     * and then mouseover the same thing again, it should only count once.
     * @param {Object} event - the event object that was triggered
     */
    function menuMouseoverHandler(event) {
        // Only the buttons that have this count.
        if (event.target.getAttribute('aria-haspopup') === 'true') {
            if (event.target !== previousMouseover) {
                sendMenuItemInteraction(event);
                previousMouseover = event.target;
            }
        }
    }
    // In-component memory of which DOM element was mouseover'ed last time
    let previousMouseover = null;

    // The menus array includes objects that define the set of
{'fraction_non_alphanumeric': 0.09229864785420341, 'fraction_numerical': 0.0015677052714089751, 'mean_word_length': 2.450980392156863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6875020', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1319, 'n_words': 553}