bug in vscode styled tabs using MUI

I am trying to recreate vscode styled tabs in my React app.

I have used 3 libraries:

  • mui v5 for design
  • react-beautiful-dnd for drag/drop
  • simplebar-react for a scrollbar that appears on hover and on top of content

Link to sandbox – https://codesandbox.io/p/sandbox/vscode-tabs-8j7scj

enter image description here

I am facing 2 bugs that I’m finding difficult to fix:

  1. when I try to scroll using the thin scrollbar, it also interferes with the drag and drop. How can I prevent this default action?
  2. Without the scroll library, it works fine, but with the scroll library, when adding several tabs and I try to drag a tab all the way to the end, it doesnt allow me as it goes beyond the width of the drag/drop box.
    • The scroll library is adding a width somewhere and Im not sure where and this doesnt allow me to drag and drop all the way to the end

The three components to focus on are:

/components/VscodeTabs/index.tsx – just a wrapper of the entire tabs component

/components/VscodeTabs/tabsList.tsx – a wrapper for the tabs itself (without the home and action buttons)

/components/VscodeTabs/tabItem.tsx – individual tab items

Where to start?

I am a 2nd year I.T student and I am here to gain more idea especially tips coming from my senior programmers. I am open to learn every aspect to become a programmer, to help and guide me on finding my specialization.

I have basic knowledge about Front and Back end development after learning HTML and CSS, C++, Java, and JavaScript. At the moment, I am confident with my Web Developing skills (HTML and CSS) but I lack functionality. I want to master JavaScript but I don’t know where start. I hope to get guidance from everyone especially to JavaScript Masters, Thank you!

Using innerHTML within onclick function [duplicate]

Trying to make a button that, when clicked, creates HTML elements beside it with different numbers.
The onclick function only runs once when clicked. I need to be able to click the button and fire the function multiple times. Here’s my code:

HTML

var saveHTML = document.getElementById('save');
var saveContainerHTML = document.getElementById("save-container");
var counter = 0;

saveHTML.onclick = function() {
  counter++;
  console.log("Save pressed");
  saveContainerHTML.innerHTML += (counter);
};
<div id="save-container">
  <button id="save"> save </button>
</div>

Here’s a JSFiddle: https://jsfiddle.net/g381ubfL/

Note that removing saveContainerHTML.innerHTML += (counter); allows the function to fire multiple times as intended, whereas leaving it in only allows it to fire once.

The function works when using onclick="myFunction()" within the HTML itself, but that is not an option for the project I’m working on. I’m also not using jQuery, and I would like to keep it that way if possible.

Uncaught (in promise) TypeError: signInWithGoogle is not a function

`Hello good evening, I was developing an app with react.js and I ended up encountering this error
Uncaught (in promise) TypeError: signInWithGoogle is not a function
Can anyone tell me what happened, code below

app.tsx

home.tsx

enter image description here

Home.tsx:18 Uncaught (in promise) TypeError: signInWithGoogle is not a function
line 18 col 27

I’m grateful to anyone who helps me, this class is available until the 16th of this month`

Understandinf Resource Hinting

We all understand the concept of preload, preconnect, prefetch. But what I don’t essentially understand is the use case of them.
Can someone please help me in understanding when to use what?
For all the next probable resouce we might want to use any one of them, but which is suitable under what scenario is my question.

Country picker in React Native

I am trying to create a country picker input, so I am using the library ‘react-native-country-picker-modal’ and it’s supposed to work like this:

enter image description here

but when i follow the documentation i got a bad result

The dropdown list works fine, I can choose the country, but the flag does not appear after I select it.

Here is the code I wrote:

export const CountrySelect = () => {
    const [country, setCountry] = useState("")

    return (
        <View style={styles.container}>
            <CountryPicker
                withFilter
                withFlag
                withCountryNameButton
                withAlphaFilter
                withCallingCode
                withEmoji
                onSelect={(country) => setCountry(country)} />
        </View>

    );
};

and i got this result, as you see, the flag refuse to appear

enter image description here:

How can I make my javascript event fire in this scenario

I have this code for making a button programatically

function makeButton(text, classList, parent, onClick){
    let button = document.createElement('button')
    button.classList = classList
    button.innerHTML = text
    button.onclick = onClick
    parent.appendChild(button)
    return button
}

it has functioned fine so far in situations like this where I’m adding a button to a DOM element that has already been instantiated

let diag = new PopupModal()

makeButton('CANCEL', 'btn btn-sm btn-secondary', diag.footer, function() {
     diag.closeFunc()
})

however I’d like to use it in a new way where the button’s function is added during the constructor of the class for example

function makeElement(type, classList, parent){
    let el = document.createElement(type)
    el.classList = classList
    parent.appendChild(el)
    return el
}

class complexForm_newProductWithType{
    constructor(doc){
        this.container = document.createElement('div')
        this.container.classList = 'container'
        this.doc = doc

        this.identifiers = makeElement('div', 'row', this.container)
        this.descriptors = makeElement('div', 'row', this.container)
        this.options = makeElement('div', 'row', this.container)
        this.buttons = makeElement('div', 'row', this.container)
        ...
        this.button_save = makeButton('SAVE', 'btn btn-sm btn-success', this.buttons, function() {
            console.log('save')
        })
        this.button_cancel = makeButton('CANCEL', 'btn btn-sm btn-secondary', this.buttons, function() {
            console.log('cancel')
        })
    }
}
function addForm(doc){
    form = new complexForm_newProductWithType(doc)
    document.getElementById("doc-selection").innerHTML = form.container.outerHTML
}

in this scenario the button is created with the correct style and text but the event does not fire. I’ve tried changing the line onclick = onClick to button.addEventListener('click', onClick, false) with no effect

How to do a class method that is not a function?

class Library {
    constructor(a){
    this.total = a;
    }
            
        add(...a){
            for (const arg of a) {
                  this.total += arg;
            }
            return this;
        }
        
        subtract(...b){
            for (const args of b) {
              this.total -= b;
            }
            return this;
            }
            
   
        result() {
            console.log(this.total);
            return this.total
            }
            
       
            


}

    $ = new Library(10); // inititliaize the base as 10

// var x = $.add(3,5).add(5,10).subtract(10).result;    
// x should be 10+3+5+5+10-10 or basically 23
// var y = $.add(3,5).add(5,10).subtract(10,3,5).result to return 15

The problem requires the exact line.

var x = $.add(3,5).add(5,10).subtract(10).result; 

The problem requires to chain a method “result” that is not a function I tried

  result = function(){
    return this.total;
  };

Is there a way to return a value in a class without using a function?

Adding npm reference into a custom node in NodeRed

For the first time, I’m creating a custom node in NodeRed. I’m also pretty new to the NodeJs/npm world, so I may be asking for something trivial, but I could not find an answer.

I’m following the official doc for creating a doc (Creating your first node), and everything works as expected until my code is straightforward:

module.exports = function(RED) {
    function NewNode(config) {
        RED.nodes.createNode(this, config);

        var node = this;
        node.on('input', function (msg) {

            // My silly custom code
            this.warn("Something happened you should know about");

            var msg = { payload: "whatever" }
            node.send(msg);

        });
    }
    RED.nodes.registerType("custom-node", NewNode);
}

but now I would like this node to do more, like using the Axios library to make an HTTP call.

I tried to import it initially or inside the function, but it errors.
Where should I “add references” to use the object inside my logic?

I tried to do the following:

const axios = require('axios');

module.exports = function(RED) {
    function NewNode(config) {
        RED.nodes.createNode(this, config);
.....

or

module.exports = function(RED) {
    function NewNode(config) {
        RED.nodes.createNode(this, config);

        var node = this;
        node.on('input', function (msg) {
             const axios = require('axios');
.....

In all cases, it errors out the moment I bring my custom node in the Flow.

Where should I import the required package?

Thanks!

Making an iframe draggable?

I’m attempting to make a chat widget draggable, which I’ve successfully managed to do via react-draggable. However, this chat widget is also consumed by an iframe, which is entirely created via HTML. So I would need the iframe to also be draggable, but this package doesn’t work with react-draggable. Are there any pure JS solutions to make this type behavior work?

The skeleton of my iframe example roughly looks like:

<div class="iframe-container">
  <iframe class="iframe">
     #shadowRoot \ all the react code 
  </iframe>
</div>

Contact form not clearing after submit and going to junk

i have a contact form that is not clearing after submit and not hitting the proper email address on top of the fact that the headers are coming in from secureserver.net
my from looks like this:

<!-- Contact Form -->
   <form id="contact_form" name="contact_form" class="" action="includes/sendmail-without-phpmailer.php" method="post">


      <div class="row">
         <div class="col-sm-6">
            <div class="form-group">
               <div class="input-outer">

                  <input id="form_name" name="form_name" class="form-control" type="text" placeholder="Your Name" required="">
                  <span class="icon fa fa-user"></span>
               </div>
            </div>
         </div>



         <div class="col-sm-6">
            <div class="form-group">
               <div class="input-outer">
                  <input id="form_phone" name="form_phone" class="form-control" type="text" placeholder="Phone Number">
                  <span class="icon fa fa-phone"></span>
               </div>
            </div>
         </div>
      </div>


      <div class="row">
         <div class="col-lg-12">
            <div class="form-group">
               <div class="input-outer">
                  <input id="form_email" name="form_email" class="form-control required email" type="email" placeholder="Your Email">
                  <span class="icon fa fa-envelope"></span>
               </div>
            </div>
         </div>
      </div>

      <div class="row">
         <div class="col-lg-12">
            <div class="form-group">
               <div class="input-outer">

                  <input id="form_subject" name="form_subject" class="form-control required" type="text" placeholder="Subject">
                  <span class="icon fa fa-question-circle"></span>
               </div>
            </div>
         </div>

      </div>

      <div class="form-group">
         <div class="input-outer">

            <textarea id="form_message" name="form_message" class="form-control required" rows="5" placeholder="Message"></textarea>
            <span class="icon fa fa-paper-plane"></span>
         </div>
      </div>
      <div class="form-group">
         <input id="form_botcheck" name="form_botcheck" class="form-control" type="hidden" value="" />
         <button type="submit" class="theme-btn btn-style-one" data-loading-text="Please wait..."><span class="btn-title">Submit Now</span></button>
         <button type="reset" class="btn btn-default btn-flat btn-theme-colored">Reset</button>
      </div>
   </form>
</div>
<!--End Contact Form -->


validation looks like this:
<!-- form submit -->
<script src="js/jquery.validate.min.js"></script>
<script src="js/jquery.form.min.js"></script>
<script>
    (function($) {
        $("#contact_form").validate({
            submitHandler: function(form) {
                var form_btn = $(form).find('button[type="submit"]');
                var form_result_div = '#form-result';
                $(form_result_div).remove();
                form_btn.before('<div id="form-result" class="alert alert-success" role="alert" style="display: none;"></div>');
                var form_btn_old_msg = form_btn.html();
                form_btn.html(form_btn.prop('disabled', true).data("loading-text"));
                $(form).ajaxSubmit({
                    dataType:  'json',
                    success: function(data) {
                        if( data.status == 'true' ) {
                            $(form).find('.form-control').val('');
                        }
                        form_btn.prop('disabled', false).html(form_btn_old_msg);
                        $(form_result_div).html(data.message).fadeIn('slow');
                        setTimeout(function(){ $(form_result_div).fadeOut('slow') }, 800);
                    }
                });
            }
        });
    })(jQuery);
</script>
<!-- form submit -->
<script src="js/jquery.validate.min.js"></script>
<script src="js/jquery.form.min.js"></script>
<script>
    (function($) {
        $("#contact_form").validate({
            submitHandler: function(form) {
                var form_btn = $(form).find('button[type="submit"]');
                var form_result_div = '#form-result';
                $(form_result_div).remove();
                form_btn.before('<div id="form-result" class="alert alert-success" role="alert" style="display: none;"></div>');
                var form_btn_old_msg = form_btn.html();
                form_btn.html(form_btn.prop('disabled', true).data("loading-text"));
                $(form).ajaxSubmit({
                    dataType:  'json',
                    success: function(data) {
                        if( data.status == 'true' ) {
                            $(form).find('.form-control').val('');
                        }
                        form_btn.prop('disabled', false).html(form_btn_old_msg);
                        $(form_result_div).html(data.message).fadeIn('slow');
                        setTimeout(function(){ $(form_result_div).fadeOut('slow') }, 800);
                    }
                });
            }
        });
    })(jQuery);
</script>



php mailer looks like this:


?php

if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
  // Multiple recipients
  $to = 'someemail.com';


  $name = $_POST['form_name'];
  $email = $_POST['form_email'];
  $subject = $_POST['form_subject'];
  $phone = $_POST['form_phone'];
  $message = $_POST['form_message'];

  $referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';


  $name = isset($name) ? "Name: $name<br><br>" : '';
  $email = isset($email) ? "Email: $email<br><br>" : '';
  $phone = isset($phone) ? "Phone: $phone<br><br>" : '';
  $message = isset($message) ? "Message: $message<br><br>" : '';
  $subject = isset($subject) ? $subject : 'New Message | Contact Form';

  $from =  $email ;

  // Message
  $message = "$name $email $phone $message $referrer";

  // To send HTML mail, the Content-type header must be set
  $headers[] = 'MIME-Version: 1.0';
  $headers[] = 'Content-type: text/html; charset=iso-8859-1';
  $headers[] = "From: $from";

  // Mail it
  mail($to, $subject, $message, implode("rn", $headers));
}
?>

i got the email to submit while testing to my personal email but it hits junk folder and comes from secureserver.net and the from submit just says “please wait…”

Problems accessing store actions in pinia and vue3

I have a store in which I placed an action with a single method and I am trying to access that method but it did not work, I checked the documentation and everything is correct.

I know it doesn’t work because the console.log() is never printed

This is my store

import { defineStore } from 'pinia';

export const useFormStore = defineStore('form', {
    state: () => {

        const fields = [ 'title', 'purpose', 'importance', 'obtain', 'provide', 'resume', 'request', 'complement', 'propose', 'agreements', 'tracing', 'lead', 'clarify', 'recognize', 'share'
        ];

        const stateObject = {};

        fields.forEach(field => {
            stateObject[field] = '';
        });

        return {
            ...stateObject,
            wasCompleted : false
        }
    },
    actions:{
        updatedStatus(){
            console.log( 'hola mundo')
            if (
                Object.values(this.$state).every(value => value !== '')
            ) {
                this.wasCompleted = true;
            }
        }
    }

})

And this is my component


<template>
    <div>
        <FormContainer>
            <template v-slot:title-section> Proceso de Interacción </template>
            <template v-slot:main-section>
                <div class="w-full my-4">
                    <label for="first_name" class="block mb-2 text-lg font-medium text-gray-900 font-semibold lg:text-2xl">Escriba el nombre del proceso:</label>
                    <input 
                        type="text" 
                        id="first_name" 
                        class="border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-cdg-yellow focus:border-cdg-yellow block w-full p-2.5" 
                        placeholder="Ejemplo: Importancia de la puntualidad"
                        v-model="inputTitle"
                        @input="updatedForm"
                        required
                    />
                </div>
            </template>
            <template v-slot:button-section>
                <ButtonCdg 
                    v-show="!wasCompleted"
                    @click="$emit('showSection', 'start-section')"
                >
                    <template v-slot:content>
                        Regresar
                    </template>
                </ButtonCdg>

                <ButtonCdg 
                    v-show="!wasCompleted"
                    :disabled="isDisabled"
                    :class="[ { 'opacity-50 hover:scale-100': isDisabled} ]"
                    @click="$emit('showSection', 'home-section')"
                    >
                    <template v-slot:content>
                        Siguiente
                    </template>
                </ButtonCdg>

                <ButtonCdg
                    v-show="wasCompleted"
                >
                    <template v-slot:content>
                        Ir a resultados
                    </template>
                </ButtonCdg>
            </template>
        </FormContainer>
    </div>
</template>

<script type="module">
    import FormContainer from '../FormContainer.vue';
    import ButtonCdg from '../template/ButtonCdg.vue';

    import { mapWritableState, mapActions } from 'pinia'
    import { useFormStore } from '../../stores/form'

    export default {
        components:{
            FormContainer,
            ButtonCdg
        },
        data(){
            return {
                inputTitle : '',
            }
        },
        computed : {
            ...mapWritableState( useFormStore, [ 'title', 'wasCompleted' ] ),
            isDisabled(){
                return !(this.inputTitle ?? false);
            }
        },
        methods: {
            ...mapActions( useFormStore, [ 'updatedStatus' ] ),
            updatedForm(){
                this.updatedStatus()
                console.log( this.wasCompleted )
            }
            
        },
    }
</script>

Know what I’m doing wrong

Firefox throws cross-origin error on iframe with same-origin PDF

I have an iframe that’s set to display a PDF loaded from the same origin.

<iframe id="pdfIframe" src="/example.pdf"></iframe>

When I run this JS to check if the iframe is loaded yet, I get a SecurityError or DOMException in Firefox:

iframeReady(document.getElementById('pdfIframe'), () => {
  console.log('iframe loaded')
))

/**
 * Execute callback when iframe is *actually* loaded. Ignores load events for
 * the "dummy" document that's loaded when an iframe is added to the DOM, and
 * before the src is loaded.
 *
 * Adapted from an answer on StackOverflow:
 * https://stackoverflow.com/a/24603642/877574
 */
function iframeReady(iframe, fn) {
  checkLoaded()

  function checkLoaded() {
    const doc = iframe.contentDocument || iframe.contentWindow?.document
    // We can tell if there is a dummy document installed because the dummy document
    // will have an URL that starts with "about:".  The real document will not have that URL
    if (doc && doc.URL.indexOf("about:") !== 0) {
      // set event listener for DOMContentLoaded on the new document
      doc.addEventListener("DOMContentLoaded", fn)
    } else {
      // still same old original document, so keep looking for content or new document
      setTimeout(checkLoaded, 1)
    }
  }
}

I know one may think perhaps the error is occurring because the JS runs while the iframe has loaded about:blank. But I’ve verified that’s not the case. After the iframe has loaded the PDF I can run this and it triggers the exception:

pdfIframe.contentDocument // null
pdfIframe.contentWindow.document // triggers exception

The same code works in Chrome.

Form to send parameters and close

I need to pass the form fields to the action url and then close or a success message appears and I don’t know what I can do in the script.

<form id="myForm" action="https://exemple.com/clicktocall.php?call_prefix=0&number=NUMBER&name=NAME&city=CITY" method="POST">
    Number: <input type="text" name="number"/><br/>
    Name: <input type="text" name="name"/><br/>
    City: <input type="text" name="city"/><br/>
    <button type="submit" id="btnTest"> Submit</button>
</form>
<script>
window.onunload = refreshParent;
    function refreshParent() {
        window.opener.location.reload();
        window.close();
    }
</script>

I tried some other ways and even had success, but I opened the page with the action return in another tab.

Sticking a button on the bottom right

Picture of app

I’m making this project for my bootcamp, I’m struggling with moving this + button to the bottom right of this container, my project has this container to “simulate” a phone screen, I have a sub-content box for it and everything, but I’m struggling on having the button on the bottom right above the footer, sticking to it, at the moment its always stuck to each “mission” I create.

.bottom-right-button {
position: absolute;
bottom: 0; /
right: 0;
}

I’ve tried this, but doing it, makes the button be on the bottom right of the actual page, not the “simulation” of the phone screen