How come I am unable to track the total number of uploaded images while fetching them?

Within my vuejs2 app, I am facing an issue with uploading images selected in a modal form. The goal is to close the modal form only after all images have been successfully saved, triggering the self.hidePhotosUploadingModal() method.

To keep track of the successful upload count, I have set a variable called uploaded_count and incremented it whenever an upload is successful. However, upon checking the value of uploaded_count, I am encountering the value NaN.

savePhotosUploadingModal() {
    let uploaded_count = 0;
    let self = this;
    this.imagePhotosUploadingFiles.map((nextImagePhotosUploadingFile, index) => {

        fetch(nextImagePhotosUploadingFile.blob).then(function (response) {
            if (response.ok) {
                return response.blob().then(function (imageBlob) {
                    let imageUploadData = new FormData()
                    imageUploadData.append('image', imageBlob)
                    imageUploadData.append('image_filename', nextImagePhotosUploadingFile.name)

                    Window.axios.post('/profile/upload_photo', imageUploadData).then(({data}) => {
                        // self.uploaded_count++ // IF TO UNCOMMENT THIS LINE THAT DOES NOT WORK ANYWAY
                        self.uploaded_count = self.uploaded_count + 1;
                        console.log('self.uploaded_count::'); // I SEE NaN IN BROWSER'S CONSOLE
                        console.log(self.uploaded_count);

                        if (self.uploaded_count === self.imagePhotosUploadingFiles.length) {
                            self.hidePhotosUploadingModal();
                        }
                        self.loadLoggedInactivePhotos();
                    }).catch((error) => {
                        console.error(error);
                    });
                });
            } else {
                return response.json().then(function (jsonError) {
                    console.error(jsonError);
                });
            }
        }).catch(function (error) {
            console.error(error);
        }); // fetch(nextImagePhotosUploadingFile.blob).then(function (response) {

    }); // this.imagePhotosUploadingFiles.map((nextImagePhotosUploadingFile, index) => {

}, // savePhotosUploadingModal

How can this issue be resolved?

Appreciate any help on this matter!

Answer №1

Consider modifying the self.uploaded_count to only uploaded_count

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Prevent regex from matching leading and trailing white spaces when validating email addresses with JavaScript

In my current setup, I utilize the following regular expression for email validation: /^[a-zA-Z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/ My attempt to validate the email is shown below: if (!event.target.value.match(/^[a-zA-Z0-9._%+-]+@[a-z0-9.-]+\. ...

What is the best method to retrieve the minimum and maximum values of a range slider in PHP and

I've successfully implemented a custom range slider using the code snippet below: HTML: <input type="text" class="salary" id="salary" name="salary" style="border:0; color:#f6931f; font-weight:bold;&qu ...

The power of Ng-show and filtering

What I am aiming for is to display a complete list of cities as soon as the page is loaded. Once a user clicks on a checkbox next to a city, my goal is to utilize ng-show/ng-hide in order to display the results specific to that city while hiding those of ...

What is the best way to use jQuery's get function to load multiple files at once?

I am attempting to use jQuery's get function to load multiple files. Here is a basic example of what I am trying to achieve: <!doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/ ...

Step by step guide on adding content to a div by clicking a button, even after the page has already loaded

I have scoured the depths of the internet and forums but have yet to find a satisfactory solution to my problem. Hopefully, someone reading this can offer some help in resolving my issue. I manage a website that showcases concerts for various music groups. ...

Error: The Rollup module is unable to locate the 'jquery' file

I've been facing an issue while trying to bundle a vuejs single file component using rollup. The error message that keeps popping up is Module not found: Error: Can't resolve 'jquery'. Despite spending countless hours on this problem, I ...

"Executing the command 'npm run dev' is successful, however, the command 'next dev' does not yield the expected result

Trying out Next for the first time using npx create-next-app, but running into issues with the scripts. While npm run dev works without any problems, executing next dev gives me an error saying zsh: command not found: next. Any idea why this is happening? ...

Issues with visuals in jQuery.animate

I have nearly finished implementing a slide down drawer using jQuery. The functionality I am working on involves expanding the drawer downwards to reveal its content when the handle labeled "show" is clicked, and then sliding the drawer back up when the ha ...

Storing a collection of strings in a MongoDB database: A step-by-step guide

I have come across a few similar questions on stack overflow like this one: How to store an array of Strings in Node MongoDB Mongoose - Save array of strings However, I am unable to understand why my method is not working. I am attempting to save the str ...

Utilizing Django Data for Dynamic Google Charts

Observation: def view_page(request, template = 'home.html'): if request.user.is_authenticated(): data = [['jan'],[12],[-12]] context = { 'data' : data, } return render( request, te ...

Prevent the Icon in Material UI from simultaneously changing

I'm working on a table where clicking one icon changes all icons in the list to a different icon. However, I want to prevent them from changing simultaneously. Any suggestions on how to tackle this issue? Code: import React from 'react'; im ...

Go to a different page section using MUI 5

I am currently working on a React application and I want to implement a functionality where pressing a button on my Nav Bar will navigate to a specific section on the first page. To achieve this, I have created an onClick function for my button: const onNa ...

Discover additional Atom extensions

I am exploring the possibility of implementing a feature in my Atom package where it can automatically detect whether specific third-party packages have been installed. Currently, my package adds configuration for one such third-party package, but I want t ...

Rendering an element in React Router Dom based on specific conditions

Starting a new project with the latest version of react-router-dom and following their recommendation to use createBrowserRouter. The goal is to display a different header based on the path parameters. Currently, I have set up an optional path parameter: ...

Having difficulty retaining the value of a variable following the retrieval of JSON data

For my current project, I am utilizing the highstocks charting library in combination with JQuery. My goal is to create a single chart divided into three sections, each displaying different data sets. To import the data, I have referenced the sample code p ...

Update data dynamically on a div element using AngularJS controller and ng-repeat

I am currently navigating my way through Angular JS and expanding my knowledge on it. I have a div set up to load data from a JSON file upon startup using a controller with the following code, but now I am looking to refresh it whenever the JSON object cha ...

Updating a Vuetify 3 Theme on the Fly

I am looking to dynamically switch themes. I have defined a lightTheme and darkTheme. export default createVuetify({ theme: { defaultTheme: "lightTheme", themes: { lightTheme: { dark: false, colors: { pri ...

"Automatically close the fancybox once the form is confirmed in the AJAX success

Having an issue with closing my fancybox after submitting the registration form on my website. I am using the CMS Pro system.... Here is how I display the fancybox with the form: submitHandler: function(form) { var str = $("#subscriber_application"). ...

Converting axios response containing an array of arrays into a TypeScript interface

When working with an API, I encountered a response in the following format: [ [ 1636765200000, 254.46, 248.07, 254.78, 248.05, 2074.9316693 ], [ 1636761600000, 251.14, 254.29, 255.73, 251.14, 5965.53873045 ], [ 1636758000000, 251.25, 251.15, 252.97, ...

What leads to the inability to utilize environment variables in this TypeScript app built with Vue 3?

Currently, I am developing a single page application utilizing Vue 3 and TypeScript. The main purpose of this app is to interact with an API. All the necessary information including the API's URL and key are stored in the 'src\env.js' f ...