<commit_before>"use strict";

import React from "react";

export class DownloadButton extends React.PureComponent {
  constructor(props) {
    super(props);

    this.state = {
      isPopupVisible: false,
      isDownloadInProgress: false,
      errorMessage: "",
      fileName: "js-130",
    };

    this.togglePopup = this.togglePopup.bind(this);
    this.setFileName = this.setFileName.bind(this);
    this.beginExport = this.beginExport.bind(this);
    this.downloadCompleteCallback = this.downloadCompleteCallback.bind(this);
  };

  togglePopup(e) {
    this.setState((prevState, props) => ({
      isPopupVisible: !prevState.isPopupVisible,
    }));
  };

  setFileName(e) {
    this.setState({ fileName: e.target.value });
  };

  beginExport(e) {
    if (this.state.fileName === "") {
      this.setState({ errorMessage: "Please give a file name", });
      return;
    }

    this.setState({
      errorMessage: "",
      isDownloadInProgress: true,
    });
    this.props.onRequestDownload(this.downloadCompleteCallback);
  };

  downloadCompleteCallback(blob) {
    let url = window.URL.createObjectURL(blob);

    this.hiddenDownloadLink.href = url;
    this.hiddenDownloadLink.click();

    window.URL.revokeObjectURL(blob);

    this.setState({isDownloadInProgress: false});
  };

  render() {
    let bodyContent;

    if (this.props.isEnabled === true) {
      bodyContent = <span>
        <label className="block">File Name:</label>
        <span className="flex"><commit_msg>Showing message if error occurs during *.wav download<commit_after>"use strict";

import React from "react";

export class DownloadButton extends React.PureComponent {
  constructor(props) {
    super(props);

    this.state = {
      isPopupVisible: false,
      isDownloadInProgress: false,
      errorMessage: "",
      fileName: "js-130",
    };

    this.togglePopup = this.togglePopup.bind(this);
    this.setFileName = this.setFileName.bind(this);
    this.beginExport = this.beginExport.bind(this);
    this.downloadCompleteCallback = this.downloadCompleteCallback.bind(this);
    this.onDownloadError = this.onDownloadError.bind(this);
  };

  togglePopup(e) {
    this.setState((prevState, props) => ({
      isPopupVisible: !prevState.isPopupVisible,
    }));
  };

  setFileName(e) {
    this.setState({ fileName: e.target.value });
  };

  beginExport(e) {
    if (this.state.fileName === "") {
      this.setState({ errorMessage: "Please give a file name", });
      return;
    }

    this.setState({
      errorMessage: "",
      isDownloadInProgress: true,
    });

    try {
      this.props.onRequestDownload(this.downloadCompleteCallback);
    }
    catch(e) {
      this.onDownloadError();
    }
  };

  downloadCompleteCallback(blob) {
    let url = window.URL.createObjectURL(blob);

    this.hiddenDownloadLink.href = url;
    this.hiddenDownloadLink.click();

    window.URL.revokeObjectURL(blob);

    this.setState({isDownloadInProgress: false});
  };

  onDownloadError() {
    this.setState({
      errorMessage: "An error occurred",
      isDownloadInProgress: false,
    });
  };

  render() {
    let bodyContent;

    if (this.props.isEnabled === true) {
      bodyContent = <span>
        <label className="block">File Name:</label>
        <span className="flex">
{'fraction_non_alphanumeric': 0.1366120218579235, 'fraction_numerical': 0.0018214936247723133, 'mean_word_length': 3.165613147914033, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1666252', 'n_tokens_mistral': 998, 'n_tokens_neox': 997, 'n_words': 173}