<commit_before>import React, { useState, useEffect } from 'react';
import WatchlistCard from '../watchlist-card/WatchlistCard';
import Components from 'stockflux-components';
import { StockFluxHooks, OpenfinApiHelpers, Launchers } from 'stockflux-core';
import * as fdc3 from 'openfin-fdc3';
import {
  useInterApplicationBusSubscribe,
  useOptions
} from 'openfin-react-hooks';
import {
  onDragStart,
  onDragOver,
  resetDragState,
  onDrop
} from '../watchlist-card/WatchlistCard.Dragging';
import { useNotification } from 'openfin-react-hooks';
import './Watchlist.css';

let latestListener;

const NOTIFICATION_OPTIONS = {
  cssUrl: './notification.css',
  parentDocument: document,
  shouldInheritCss: true
};

const getDistinctElementArray = array => [...new Set(array)];

const Watchlist = () => {
  const [dragOverIndex, setDragOverIndex] = useState(null);
  const [unwatchedSymbol, setUnwatchedSymbol] = useState(null);
  const [displayPreview, setDisplayPreview] = useState(false);
  const [previewDetails, setPreviewDetails] = useState({
    options: null,
    position: { top: 0, left: 0 },
    size: { height: 300, width: 300 }
  });
  const [watchlist, setWatchlist] = StockFluxHooks.useLocalStorage(
    'watchlist',
    ['AAPL', 'AAP', 'CC', 'MS', 'JPS']
  );

  const [options] = useOptions();
  const notification = useNotification(NOTIFICATION_OPTIONS);

  const displayNotification = newSymbol => {
    const alreadyInWatchlist = watchlist.includes(newSymbol);
    if (notification) {
      notification.launch({
        url: 'notification.html',
        timeout: 'never'
      });
      notification.populate(
        <>
          <div className="notification-icon">
            <img
              id="icon"
              className={alreadyInWatchlist ? 'arrow-up' : 'card-icon'}
              src={alreadyInWatchlist ? 'ArrowUp.png' : 'CardIcon.png'}
              alt="Notification Icon"
            />
          </div>
          <div id="notification-content">
            <p id="title">WATCHLIST UPDATED</p>
            <hr />
            <p id="info">
              <span id="symbol">{newSymbol}</span>
              <span id="message">{`${
                alreadyInWatchlist ? ' moved' : ' added'
              } to the top`}</span>
            </p>
          </div>
        </>
      );
    }
  };

  const addToWatchlist = symbol => {
    setWatchlist(getDistinctElementArray([symbol, ...watchlist]));
    displayNotification(symbol);
  };

  const { data } = useInterApplicationBusSubscribe(
    { uuid: options ? options.uuid : '*' },
    'stockflux-watchlist'
  );

  useEffect(() => {
    if (data && data.message) {
      if (data.message.symbol) {
        addToWatchlist(data.message.symbol);<commit_msg>Temporary workaround the bug<commit_after>import React, { useState, useEffect } from 'react';
import WatchlistCard from '../watchlist-card/WatchlistCard';
import Components from 'stockflux-components';
import { StockFluxHooks, OpenfinApiHelpers, Launchers } from 'stockflux-core';
import * as fdc3 from 'openfin-fdc3';
import {
  useInterApplicationBusSubscribe,
  useOptions
} from 'openfin-react-hooks';
import {
  onDragStart,
  onDragOver,
  resetDragState,
  onDrop
} from '../watchlist-card/WatchlistCard.Dragging';
import { useNotification } from 'openfin-react-hooks';
import './Watchlist.css';

let latestListener;

const NOTIFICATION_OPTIONS = {
  cssUrl: './notification.css',
  parentDocument: document,
  shouldInheritCss: true
};

const getDistinctElementArray = array => [...new Set(array)];

const Watchlist = () => {
  const [dragOverIndex, setDragOverIndex] = useState(null);
  const [unwatchedSymbol, setUnwatchedSymbol] = useState(null);
  const [displayPreview, setDisplayPreview] = useState(false);
  const [newSymbol, setNewSymbol] = useState(null);
  const [previewDetails, setPreviewDetails] = useState({
    options: null,
    position: { top: 0, left: 0 },
    size: { height: 300, width: 300 }
  });
  const [watchlist, setWatchlist] = StockFluxHooks.useLocalStorage(
    'watchlist',
    ['AAPL', 'AAP', 'CC', 'MS', 'JPS']
  );

  const [options] = useOptions();
  const notification = useNotification(NOTIFICATION_OPTIONS);

  const displayNotification = newSymbol => {
    setNewSymbol(newSymbol);
    if (notification) {
      notification.launch({
        url: 'notification.html',
        timeout: 'never'
      });
    }
  };

  const addToWatchlist = symbol => {
    setWatchlist(getDistinctElementArray([symbol, ...watchlist]));
    displayNotification(symbol);
  };

  const { data } = useInterApplicationBusSubscribe(
    { uuid: options ? options.uuid : '*' },
    'stockflux-watchlist'
  );

  useEffect(() => {
    if (notification.state === 'LAUNCHED') {
      const alreadyInWatchlist = watchlist.includes(newSymbol);
      notification.populate(
        <>
          <div className="notification-icon">
            <img
              id="icon"
              className={alreadyInWatchlist ? 'arrow-up' : 'card-icon'}
              src={alreadyInWatchlist ? 'ArrowUp.png' : 'CardIcon.png'}
              alt="Notification Icon"
            />
          </div>
          <div id="notification-content">
            <p id="title">WATCHLIST UPDATED</p>
            <hr />
            <p id="info">
              <span id="symbol">{newSymbol}</span>
              <span id="message">{`${
                alreadyInWatchlist ? ' moved' : ' added'
              } to the top`}</span>
            </p>
          </div>
        </>
      );
    }
  });
  useEffect(() => {
    if (data && data.message) {
      if (data.message.symbol) {
        addToWatchlist(data.message.symbol);
{'fraction_non_alphanumeric': 0.14018030758352484, 'fraction_numerical': 0.00353544281421248, 'mean_word_length': 2.888659793814433, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 46, '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': '7391849', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1698, 'n_words': 353}