Appended childs innerHTML is set to a message that involves keeping count of number of times button was clicked

So I am working with a DOM challenge to improve my skills. I have reached the deliverable but would like to additionally only have 1 instance of each logged number run with the count increasing in that single string.

With what I have so far below, for each time my heart button is clicked during whichever count is present it will record and append that count as an li to my ul.likes.

How would I post only one li for each individual count and update the button click count within said specific li?

JS

const counter = document.querySelector("#counter");
const likes = document.querySelector(".likes");

function startCounter() {
  setInterval(() => {
    counter.textContent++;
  }, 1000);
}

const minus = document.querySelector("#minus");
minus.addEventListener("click", () => {
  counter.textContent--;
});

const plus = document.querySelector("#plus");
plus.addEventListener("click", () => {
  counter.textContent++;
});

let lookup = {};

function buttonClicked() {
  let li = document.createElement("li");

  let activeCount = counter.textContent;
  let likeList = document.querySelector("li");

  if (lookup[activeCount]) {
    lookup[activeCount]++;
  } else lookup[activeCount] = 1;

  li.innerHTML = `${activeCount} has been liked ${lookup[activeCount]} times!`;

  likes.appendChild(li);
  console.log(likes);
}

const heart = document.querySelector("#heart");
heart.addEventListener("click", () => {
  buttonClicked();
});

const pause = document.querySelector("#pause");

startCounter();

HTML

<html>

<head>
  <meta charset="UTF-8">
  <title>Dom Challenge</title>
  <style>
    #counter {
      background-color: black;
      color: white;
      display: table;
      padding: 10px;
    }
  </style>
</head>

<body>
  <h1>
    Welcome to the DOM Challenge
  </h1>
  <h1 id='counter'>
    0
  </h1>
  <button id='minus'> ➖ </button>
  <button id='plus'> ➕ </button>
  <button id='heart'> ❤️ </button>
  <button id='pause'> pause </button>

  <ul class='likes'></ul>

  <div>
    <h3>Comments</h3>
    <div id='list' class='comments'></div>

    <h3>Leave a comment</h3>

    <form id="comment-form" action="">
      <input type='text' name="comment" id="comment-input" cols="30" rows="10">
      </br>
      <button id='submit'>submit</button>
    </form>

  </div>

  <!--<script src="js/index.min.js"></script>-->
  <script src="js/challenge.js"></script>
</body>

</html>

django-ckeditor modal form does not change data on POST

I have a django project using django-ckeditor. I use HTMX to create a bootstrap modal to show my edit form. It renders correctly (I did add the ckeditor.js files at the end of the body in base.html). If I call my form by going to localhost/1/update, change the RTF value, and click save, it works fine. But rendering it in the modal form and clicking save, the form.has_changed() returns false. If I edit another field and it saves, the value of RTF does NOT change. It seems like the POST does not include the changed value for the CKEditor field.

I’ve tried to reduce the code below to make it as short as possible.

My model:

class MyModel(models.Model):    
    name = models.CharField(max_length=50)
    description = models.CharField(max_length=150)
    comment = RichTextField(blank=True, null=True)

    def __str__(self):
        return f'{self.name} - {self.description}'

My form:

class MyForm(forms.ModelForm):
    class Meta:
        model = MyModel
        fields = (
            'name',
            'description',
            'comment',
        )

My View

def update_data(request, pk):
    model = MyModel.objects.get(id=pk)
    form = MyForm(request.POST or None, instance=model)

    if request.method == "POST":
        if form.is_valid():
            print(form.has_changed())
            form.save()
            return redirect("detail-form", pk=model.id)

My HTML#1 – I click on the update button to open the modal

{% extends "layouts/base.html" %}

{% load static %}

{% block content %}
<main>
    <div class="section section-md pt-4">
        <div class="container">
            <table class="table">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Description</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody id="myforms">
                    {% for entry in entries %}

                    <tr id="entryform_{{entry.id}}">
                        <td>
                            <h4 class="h5">{{ entry.name }}</h4>
                        </td>
                        <td>
                            <h4 class="h5">{{ entry.description }}</h4>
                        </td>
                        <td style="width: 200px">
                            <button hx-get="{% url 'update-entry' entry.id %}" hx-swap="outerHTML"
                            class="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-indigo-700 bg-indigo-100 hover:bg-indigo-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                                Update
                            </button>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    <div id="modals-here"></div>
</main>

{% endblock content %}

{% block javascripts %}
<script>
function closeModal() {
    var container = document.getElementById("modals-here")
    var backdrop = document.getElementById("modal-backdrop")
    var modal = document.getElementById("modal")

    modal.classList.remove("show")
    backdrop.classList.remove("show")

    setTimeout(function() {
        container.removeChild(backdrop)
        container.removeChild(modal)
    }, 200)
}
</script>
{% endblock javascripts %}

and then the last html, the model form. Notice that I did add the {{ form.media }}

<div id="modal-backdrop" class="modal-backdrop fade show" style="display:block;">    </div>
<div id="modal" class="modal fade show" tabindex="-1" style="display:block;">
    <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content">
        <div class="modal-body">
            <form method="post">
                {% csrf_token %}
        
                {{ form.media }}
                {{ form.as_p|safe }}
                <button type="submit" hx-post="{% url 'update-data' entry.id %}" hx-target="#entryform_{{entry.id}}" hx-swap="outerHTML"
                    class="btn btn-primary" onclick="closeModal()">
                    Submit
                </button>
            </form>
        </div>
      </div>
    </div>
  </div>

Any advice? My gut feel says it has something to do with the fact that the editor only gets loaded after the page has already loaded. If I recall I had a similar issue years ago with a JS date picker. I can’t recall for the life of me how I fixed it then.

Threat Assessment Javascript User-controlled Variable Names on Window

I have a requirement to support some external integration to a 3rd party vendor on our site (which is a SaaS site with multiple tenant logins). The vendor requires a script and a global variable to be available which the script reads to get some extra info. In this case, the vendor’s script will run on the page, add some “help” content in the corner of the screen which helps the user. This vendor only has a few different URL patterns it would need, and there is one uuid variable in the script JS file that targets the tenant (e.g. the company) that is integrated with this vendor.

One option for us is to very specifically target this vendor, add an admin screen called “Configure X” (where X is the vendor name) and then ask the admin to select which environment (prod/preview) and enter the uuid and that’s it. This would be quick, easy, and probably safest to do this way.

However, suppose we offered even more flexibility – this could be used for this Vendor and as well as other similar Vendors too. The Admin page could be called “Configure Integrations” (or similar) and gives Admin flexibility to add as many Global Variables or Scripts URLs they want – with some restrictions:

  1. only users with special admin permission can modify the settings for the tenant
  2. global variable names have a black list, you cannot specify global variable names that match particular patterns
  3. global variable values must be defined as a JSON string, so cannot be functions or something else
  4. script URLs will have a white list of base URLs, base URLs will start with https:// and end with / — the script URLs must start with one of these base URLs, for now the white list will only include this one vendor

With this new flexible approach – is there any thing I’m not thinking about that a malicious actor with permissions to modify this set of globals/scripts could do?

The code behind the startup script might look like this

const {globals, scripts} = /* JSON config object persisted by Admin user. */
globals.forEach(({name,value}) => { window[name] = JSON.parse(value); });
scripts.forEach(({url}) => { /* create <script> with src=url, then add to body */ });

My first thoughts here are that the scripts here are white listed to only a set of origins – but the path after the domain part is not restricted – so that might go to somewhere bad (but I guess it would be from the vendor… though, right?)

Then the globals – what if they put something weird there like overwrite something some other script would try to inject scripts from or something – so I’d really need to do research into the black list.

Is there anything else here I should consider, is this a really bad idea?

“error Object { message: “The provided API key is not valid.”, type: “authentication_error” }”

I’m doing the youtube tutorial “ECommerce Web Shop – Build & Deploy an Amazing App | React.js, Commerce.js, Stripe” and this error appeared when I was sending a new product object from the Commerce.js. (minute 45:50)
I have the corresponding code:

import React, {useState, useEffect } from 'react';
import { commerce } from './lib/commerce'
import {Products, Navbar } from './components'

// to create a full function web shell app, we need a
// full api that is stored on commerce import
const App = () => {
  //new state
  const [products, setProducts] = useState([]);

  // fetch data from the commerce instance
  // fetch the products immediatelly on the aplication load
  const fetchProducts = async () => {
    // this is going to return a promise that we have to 
    // await to see what is inside of that promise
    const { data } = await commerce.products.list();
    // now the products are going to be populated
    setProducts(data);
  }
  

  /* this is to call the fetch product function and set
     products to the state, the empty list means that it's
     only going to render at the start */
  useEffect(() => {
    fetchProducts();
  },[]);

  console.log(products);

  return (
    <div>
      <Navbar/>
      <Products/>
    </div>
  );
}

export default App;

[It should have printed the object on the console, but instead I have the error]

(Error)
https://i.stack.imgur.com/Symbp.png

useEffect in next.js run twices [duplicate]

i’m tring to build a web app using next.js and react.

when i’m using useEffect hook for fetching data from un api, the callback in the hook runs twice. i tried in function components and class componenet and it append in both cases.

my code is like this:

const Test = () => {
    useEffect(() => {
        console.log("something")
    }, [])
    return "text"
}

and when i open the console, i see “someting” two times.
anyone can explain what am i doing wrong, please?

Using ES6 Module Libraries in Angular Applications : Cannot find module

I have a JavaScript library I’m trying use within an Angular 8 application. The JS library written with ES6 syntax and exports itself as a module. I hosted the bundled module on a local dev server at port 8080.

import widgetLib from './lib/widget.js';
export default widgetLib;

Now when trying to import the module using the http link, I’m getting the module not found error

import * as Widget from "http://localhost.finra.org:8080/widgetLib.js";
ERROR in app/Component1/Component1.component.ts:8:33 - error TS2307: Cannot find module 'http://localhost.finra.org:8080/widgetLib.js'.

I tried adding it to the scripts in angular.json file and it didn’t help. This is my ts.config.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "baseUrl": "./",
    "downlevelIteration": true,
    "importHelpers": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": false,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "target": "es2019",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2020",
      "dom"
    ],
    "skipLibCheck": true
  }
}

Can anyone help me with importing the exposed ES6 module using a http URL?

about finding the password [closed]

what is the decode of this
I tried all kinds of decryptors but it does not decrypt

var _0x37cfa5=_0x5a39;(function(_0x43781f,_0x59a7e0){var _0x17895c=_0x5a39,_0x161f4c=_0x43781f();while(!![])

(I don’t know variable values)
are vanilla javascript codes

Using regex to place dashes at specific indexes of a string containing numbers and letters

So the formatted code needs looks like this:

"US-XXX-12-12345"

So that’s two letters, followed by 3 letters/numbers, followed by 2 numbers, then followed by 5 letters/numbers.
I was able to get it to work using only numbers with the following:

return testString
  .replace(/(d{2})(d)/, '$1-$2')
  .replace(/(d{3})(d)/, '$1-$2')
  .replace(/(d{2})(d{2})/, '$1-$2')
  .replace(/(d{4})(d{2})/, '$1-$2')

This returns:

"12-345-67-89012" 

I tried switching the lowercase d’s for uppercase ones (representing letters) and it adds all sorts of extra dashes and does not let me backspace. Any and all help is much appreciated!

Trying to display animation on click….not working (js, html, css)

I have a loading element that I want to display on the click of a certain button. I have tried various methods including updating the visibility and display, as well as adding a “show” classList to the div onclick (current code). Nothing has worked so far and I am desperate. I would really appreciate any help. Thanks 🙂

HTML:

<div class="footer">
    <div class="loader">
      <div class="loader-inner">
        <div class="loader-line-wrap">
          <div class="loader-line"></div>
        </div>
        <div class="loader-line-wrap">
          <div class="loader-line"></div>
        </div>
        <div class="loader-line-wrap">
          <div class="loader-line"></div>
        </div>
        <div class="loader-line-wrap">
          <div class="loader-line"></div>
        </div>
        <div class="loader-line-wrap">
          <div class="loader-line"></div>
        </div>
      </div>
  </div>

CSS:

.loader {
    opacity: 0;
    background: #ffffff;
    /* background: radial-gradient(#222, #000); */
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    /* z-index: 99999; */
    -webkit-transform:scale(0.4);
    -moz-transform:scale(0.4);
    -ms-transform:scale(0.4);
    transform:scale(0.4);
  }

  .loader.show {
    background: #ffffff;
    /* background: radial-gradient(#222, #000); */
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    /* z-index: 99999; */
    -webkit-transform:scale(0.4);
    -moz-transform:scale(0.4);
    -ms-transform:scale(0.4);
    transform:scale(0.4);
    display: none;
  }

  .loader-inner {
      bottom: 0;
      height: auto;
      left: 0;
      margin: auto;
      position: relative;
      right: 0;
      top: 0;
      width: 100px;
      padding: 8px;
  }

  .loader-line-wrap {
      animation: 
      spin 2000ms cubic-bezier(.175, .885, .32, 1.275) infinite
    ;
      box-sizing: border-box;
      height: 50px;
      left: 0;
      overflow: hidden;
      position: absolute;
      top: 0;
      transform-origin: 50% 100%;
      width: 100px;
  }
  .loader-line {
      border: 4px solid transparent;
      border-radius: 100%;
      box-sizing: border-box;
      height: 100px;
      left: 0;
      margin: 0 auto;
      position: absolute;
      right: 0;
      top: 0;
      width: 100px;
  }
  .loader-line-wrap:nth-child(1) { animation-delay: -50ms; }
  .loader-line-wrap:nth-child(2) { animation-delay: -100ms; }
  .loader-line-wrap:nth-child(3) { animation-delay: -150ms; }
  .loader-line-wrap:nth-child(4) { animation-delay: -200ms; }
  .loader-line-wrap:nth-child(5) { animation-delay: -250ms; }

  .loader-line-wrap:nth-child(1) .loader-line {
      border-color: #EB6A6F;
      height: 90px;
      width: 90px;
      top: 7px;
  }
  .loader-line-wrap:nth-child(2) .loader-line {
      border-color: #F6BA48;
      height: 76px;
      width: 76px;
      top: 14px;
  }
  .loader-line-wrap:nth-child(3) .loader-line {
      border-color: #B5D643;
      height: 62px;
      width: 62px;
      top: 21px;
  }
  .loader-line-wrap:nth-child(4) .loader-line {
      border-color: #50CFD4;
      height: 48px;
      width: 48px;
      top: 28px;
  }
  .loader-line-wrap:nth-child(5) .loader-line {
      border-color: #9665D4;
      height: 34px;
      width: 34px;
      top: 35px;
  }

  @keyframes spin {
      0%, 15% {
      transform: rotate(0);
    }
    100% {
      transform: rotate(360deg);
    }
  }

JS:

document.getElementById('text-generate-button').onclick = () => {
  parent.postMessage({ pluginMessage: { type: 'placeholder-frame'} }, '*')
  const loader = document.getElementById('loader');
  loader.classList.add("show")
}

Array declared in global scope in JavaScript is getting overridden when new element is being pushed through function call [duplicate]

I am working on a client-side rendered website using HTML, CSS and Vanilla JS. I have declared an array in global scope in a script.js file. e.g.:

let testArr = new Array("Test");

Now I have multiple html files calling same script file but different functions. Whenever I am calling a function and pushing a new element to the array, the process is successful. But consecutive function calls are overriding existing values. Eg:

    function f1() {
       testArr.push("TestF1");
       console.log(testArr.length);
       console.log(testArr);
    }
    
    function f2() {
       testArr.push("TestF2");
       console.log(testArr.length);
       console.log(testArr);
    }

Now, if I call f1() from a.html file I get in console:
2
[‘Test’, ‘TestF1’]

After that, if I call f2() from b.html file I get in console:
2
[‘Test’, ‘TestF2’]

I am unable to understand why existing element is getting replaced while I try to push a new input to the array. I have tried different ways to access the array within function, including using window object. Is the global array getting initialized every time the script is called from a html file?

Making Caser Cipher Case sensitive in JavaScript?

    <body>

  <div class="container">
   <div class="row">
     <h1 class="mx-auto">Secured Data Cypher</h1>
   </div>
   <div class="row">
     <h5 class="mx-auto desc"><br><br>Enter Your Desired Message which you want Encrypted <br><br> For example: ****_***123 </h5>
   </div>
      <div class="row">
        <div class="col-sm-4">
          <div class="form-group">
            <h4>Plain Text</h4>
            <textarea class="form-control" id="plain-text" rows="7"></textarea>
          </div>
          <div class="input-group mb-3">
            <input type="number" min="0" max="25" class="form-control" id="my-key" placeholder="Key (Digits Only)">
            <div class="input-group-append">
              <button class="btn btn-outline-success" type="button" onclick="encrypt()">Encrypt</button>
            </div>
          </div>
        </div>
        <div class="col-sm-4">
          <div class="form-group">
            <h4>Cipher Text</h4>
            <textarea readonly class="form-control" id="cipher-text" rows="7"></textarea>
          </div>
          <button type="button" class="btn btn-outline-danger" onclick="decrypt()">Decrypt</button>
        </div>
        <div class="col-sm-4">
          <div class="form-group">
            <h4>Original Text</h4>
            <textarea readonly class="form-control" id="original-text" rows="7"></textarea>
          </div>
        </div>
      </div>
  </div>

</body>


<!- JS for Cypher Starts here ->
<script>
function encrypt() {

  // Empty Original Text
  document.getElementById("original-text").value = "";

  var k = document.getElementById("my-key").value;
  var p = document.getElementById("plain-text").value;

  if (!(k >= 0 && k < 26)) {
    alert("Key should be between 0 and 25");
    return;
  }

  if (p.length === 0) {
    alert("Plain Text is empty");
  }

  p = p.toLowerCase();
  var cipher = "";
  var alphabet = "abcdefghijklmnopqrstuvwxyz";

  for (var i = 0; i < p.length; i++) {
    var current = p.charAt(i);

    if (!isLetter(current)) {
      cipher += current;
      continue;
    }

    var index = 0;
    index = alphabet.indexOf(current);
    var shifted = (parseInt(index) + parseInt(k)) % 26;
    cipher += alphabet.charAt(shifted);
  }

  document.getElementById("cipher-text").value = cipher;
}

function decrypt() {
  var k = document.getElementById("my-key").value;
  var cipher = document.getElementById("cipher-text").value;

  if (!(k >= 0 && k < 26)) {
    alert("Key should be between 0 and 25");
    return;
  }

  var original = "";
  var alphabet = "abcdefghijklmnopqrstuvwxyz";

  for (var i = 0; i < cipher.length; i++) {
    var current = cipher.charAt(i);

    if (!isLetter(current)) {
      original += current;
      continue;
    }

    var index = 0;
    index = alphabet.indexOf(current);
    var num = parseInt(index) - parseInt(k);
    var shifted = (num + 26) % 26;
    original += alphabet.charAt(shifted);
  }

  document.getElementById("original-text").value = original;
}

function isLetter(str) {
  return str.length === 1 && str.match(/[a-z]/i);
}

</script>
<!- JS for Cypher Ends here ->

This code above only encrypts texts in lowercase

For example:
Result: Leo_123 -(with shift number of 2)-> ngq_123 -(after decryption)-> leo_123

but my expected result is:
Leo_123 -(with shift number of 2)-> Ngq_123 -(after decryption)-> Leo_123

the first part of the code is from my body tag and I am using bootstrap to make this happen
The javascript code follows the main principal but I want to modify it to get the expected results.

Content Security Policy directive: “default-src ‘none'”. Note that ‘img-src’ was not explicitly set, so ‘default-src’ is used as a fallback

so im building app using node and JavaScript. one of the feature that you can upload images.
after i deployed to Heroku i could not upload any images.
all images goes to this folder Images
app.use(‘/Images’, express.static(‘./Images’));
im using multer to upload and this is the action

trying to save the image path int the schema.
I tried everything but not working even helmet.. still getting the same error

Loading Screen for a Form

I am trying to make a loading screen when submitting a form. When I submit a form the page starts to load until the backend responds by downloading an excel file. The idea is to have the effect of “load screen” only until the file manages to download.

html:

<form action="{% url 'downloadStatusPickingCustomerByCollection' %}" method="POST">{% csrf_token %}
        <div class="pnl-collection">

            <div>
                <div class="tituloPnl">
                    <h3>Estado Ordenes de Venta por Colección</h3>
                </div>
                <div class="btnExport">
                    <button onclick="loadDisplay()" class="btn btn-light" type="submit">Exportar</button>
                </div>
            </div>
            <div class="filtro">
                <div>
                    <div class="title-select"><span>Colección</span></div>
                </div>
                <div>
                    <select class="form-select form-select-sm form-down-report" name="collection-StatusCustomer-name" id="" required>
                        <option value="">- SELECCIONE COLECCIÓN -</option>
                        {% if collections %}
                        {% for collection in collections%}
                        <option value="{{collection.Name}}">{{collection.Name}}</option>
                        {% endfor %}
                        {% endif %}
                    </select>
                </div>
            </div>
        </div>
    </form>

javascript:

function loadDisplay() {
    if (document.querySelector(".form-down-report").value != "") {
        document.getElementById("preloader-camion").style.display = 'block';
        jquery(window).load(
            function () { 
                document.getElementById("preloader-camion").style.display = 'none';
            });
    }
}

I have the bakcend developed in django so in the form route you can see a django “url tag”.

get multiple docs from firestore by id in single transaction

I have list of firestore documents ids stored in players. Now I want to get all the documents with those ids.

I can use query and in operator, but this is limited to 10 separate values and I expect cases with more than 10. stackoverflow

const colRef = collection(db, "Products");
const q = query(colRef, where(documentId(), 'in', players));

getDocs(q).then((snap) => {
  console.log(snap.docs.map(d => ({ id: d.id, ...d.data() }))
})

I stumbled upon this question where they are using getAll, but this function is not available in firestore 9 AFAIK.

async getUsers({userIds}) {
    const refs = userIds.map(id => this.firestore.doc(`users/${id}`))
    const users = await this.firestore.getAll(...refs)
    console.log(users.map(doc => doc.data()))
}

I could create a list of doc reference and using Promise.all get the data, but this will run the request in parallel, which comes with additional cost as firestore gets billed per request and not per data volume as it is in realtime database.

File reader ignoring columns from CSV file

I have been working on a CSV project. I have been downloading CSV data and importing the data as CSV too.
Right now it was working fine, but I got an issue with the data being edit by hand on the file. Whenever I download the data normally, the FileReader reads the data like:

id,admin,email_address,ogs.id,created_by.email,stf,identities
80,group,nilton.updated,[email protected],22,[email protected],"[email protected],[email protected]","13,14,27,247"

Which is what I wish it read all the time.

But when I edit the data by hand and save the content (in excel), the FileReader reads the data wrong, like the following:

id,admin,email_address,ogs.id,created_by.email,stf,identities
80,group,nilton.updated,[email protected],22,[email protected],[email protected],[email protected],13,14,27,247

Removing the quotes makes my app crash. How can I get a work around to this FileReader issue.

This are the function to read the content:

readFileContent = file => {
    const reader = new FileReader();
    return new Promise((resolve, reject) => {
      reader.onload = event => resolve(event.target.result);
      reader.onerror = reject;
      reader.readAsText(file);
    });
  };

  

  clickAnalyzeUploadFile = async () => {
    const { file, options } = this.state;
    const oldData = file && (await this.readFileContent(file));
    const data = oldData.replace(/;/g, ',')    
    console.log(data);
    data &&
      this.props.onRequestAnalysis({
        source: "upload",
        type: file.type,
        options,
        data
      });
  };

This is the hole code:

class UploadFileForm extends Component {
  state = {
    file: null,
    type: null,
    options: {
      filename: null
    },
    isDragging: false
  };

  onChangeImportFile = file => {
    file &&
      this.setState({
        file,
        type: file.type,
        options: { ...this.state.options, filename: file.name }
      });
  };

  handleDragEnter = () => this.setState({ isDragging: true }); 

  handleDragLeave = () => this.setState({ isDragging: false }); 

  handleDrop = e => { 
    e.preventDefault();
    this.setState({ isDragging: false });
    const file = e.dataTransfer.files[0];
    this.onChangeImportFile(file);
  };

  readFileContent = file => {
    const reader = new FileReader();
    return new Promise((resolve, reject) => {
      reader.onload = event => resolve(event.target.result);
      reader.onerror = reject;
      reader.readAsText(file);
    });
  };

  

  clickAnalyzeUploadFile = async () => {
    const { file, options } = this.state;
    const oldData = file && (await this.readFileContent(file));
    const data = oldData.replace(/;/g, ',')    
    console.log('fileL', data);
    data &&
      this.props.onRequestAnalysis({
        source: "upload",
        type: file.type,
        options,
        oldData
      });
  };

  render() {
    return (
      <div className={"col-12"}>
        <Row className={"row"}>