How to Use Third Party Apps in the Shopify Dawn Theme Without Overriding the Original Functionality…?

I am using the dawn theme. My third-party app will override the original Add to Cart button of the Dawn theme. However, the app won’t update the increment icon of the cart sign, the pop-up of the cart notification won’t show as well. In the code of the product-form.js file, the icon and notification are rendered after a response is passed. Anyone can give me some hints to modify my code to keep the original feature available?

please look in the code

if (!customElements.get('product-form')) {
customElements.define('product-form', class ProductForm extends HTMLElement {
constructor() {
  super();
  this.form.addEventListener('submit', this.onSubmitHandler.bind(this)); 
  this.cart = document.querySelector('cart-notification');
}

onSubmitHandler(evt) {
  evt.preventDefault();
  const config = fetchConfig('javascript');
  config.headers['X-Requested-With'] = 'XMLHttpRequest';
  delete config.headers['Content-Type'];
  const formData = new FormData(this.form);
  fetch(`${routes.cart_add_url}`, config)
    .then((response) => response.json())
    .then((response) => {
        this.cart.renderContents(response);     //when item add //to cart, the 
                                                 //renderContents() will be called to 
                                               //show cart notification
       }
    }
  }
}

bootstrap 5 hide collapsed navbar on link click

I want to know how to hide the navbar after clicking a link.
this is HTML code

<header class="header-nav" id="home">
      <nav class="navbar navbar-expand-lg custom-nav fixed-top">
        <div class="container-fluid">
          <a id="brand" href="#"><span>C</span> Solutions</a>
          <button
            class="navbtn"
            type="button"
            data-bs-toggle="collapse"
            data-bs-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent"
            aria-expanded="false"
            aria-label="Toggle navigation"
          >
            <span><i class="fas fa-bars burger-menu"></i></span>
          </button>
          <div
            class="collapse navbar-collapse justify-content-between"
            id="navbarSupportedContent"
          >
            <ul class="navbar-nav m-auto mb-2 mb-lg-0 text-center">
              <li class="nav-item">
                <a class="nav-link active" aria-current="page" href="#home"
                  >Home</a
                >
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">about us</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#services">services</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">why choose us</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">careers</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">portfolio</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#our-clients">our clients</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">contact us</a>
              </li>
            </ul>
            <ul class="navbar-nav ml-auto">
              <button class="btn btn-primary">request a quote</button>
            </ul>
          </div>
        </div>
      </nav>
    </header>

I already used the javascript method after answering the same question here before but it is not working

const navLinks = document.querySelectorAll('.nav-item')
const menuToggle = document.getElementById('navbarSupportedContent')
const bsCollapse = new bootstrap.Collapse(menuToggle)
navLinks.forEach((l) => {
    l.addEventListener('click', () => { bsCollapse.toggle() })
})

I also tried the bootstrap way to Use the data-bs-toggle and data-bs-target data attributes in the markup on each link to toggle the Collapse navbar, but what happened is when clicking on a link it closes the navbar but does not go to the section clicked.
can anyone help?

Where can I find more information for my project? [closed]

I’m working on a project where I’m planning on building a website that will house a database. The database will get its information from an excel spreadsheet on my computer, and organize it into objects that will be displayed in a specific way. I have some experience coding, but this is my first time attempting something like this. I’m a little lost on where to start.

From what I’ve read, I’ll use mostly html, CSS, and JavaScript to create the actual website, but I’m wondering what language I can use to incorporate the database part (pulling info from the excel spreadsheets and organizing it into specific objects). If anyone has done something similar, I’d appreciate some guidance or being pointed in some direction for further reading. Thanks.

How to create a refresh button with 4 different data end points in React?

I created a table on(table.js) with 4 different endpoints(app.js) I would like to add a refresh button that will refresh the data when clicked on. How would I do that with 4 different endpoints? I did try the interval but it refreshed the whole page.
This is my App.file where the data was fetched from.

  function App() {
  const [feed, setFeed] = useState([]);
  const [feedol, setFeedol] = useState([]);
  const [jsonData, setJsonData] = useState([]);
  const [azureData, setAzureData] = useState([]);

  useEffect(() => {
  fetch("/feed").then((response) =>
   response.json().then((data) => {
     setFeed(data);
   })
   );
  }, []);
   useEffect(() => {
   fetch("/feed_ol").then((response) =>
   response.json().then((data) => {
      setFeedol(data);
    })
   );
  }, []);

  useEffect(() => {
  fetch("/json_data").then((response) =>
    response.json().then((data) => {
    setJsonData(data["archive"][0]);
    })
  );
  }, []);

    useEffect(() => {
    fetch("/azure_data").then((response) =>
    response.json().then((data) => {
    setAzureData(data);
    })
  );
 }, []);

   
  Table.js

  import React from "react";
  import { Card, Container } from "react-bootstrap";
  import { BsArrowClockwise } from "react-icons/bs";
  import Cards from "./Cards";

  import "./tables.css";
   export const Tables = ({ feed, feedol, jsonData, azureData, refresh 
 }) => {
   return (
    <Container>
    <Cards />
     <Card className="table-card">
      <Card.Header>
         {" "}
        <button type="button" className=" refresh-button" onClick= 
        {}>
        {" "}
        <BsArrowClockwise />
       </button>{" "}
       OneLogin Outages{" "}
       </Card.Header>
       <Card.Body>
        <table className="table table-bordered">
           <thead>
           <tr>
            <th>Title</th>
            <th>Link</th>
            <th>Date</th>
          </tr>
          </thead>
          <tbody>
            <tr>
             <td>{feedol.title}</td>
             <td>{feedol.link}</td>
             <td>{feedol.updated}</td>
             </tr>
            <tr>
            <td>{}</td>
            <td>{}</td>
            <td>{}</td>
            </tr>
            <tr>
            <td>{jsonData.service_name}</td>
            <td>{jsonData.summary}</td>
            <td>{jsonData.date}</td>
          </tr>
          </tbody>
        </table>
       </Card.Body>
       </Card>
      <Cards />
      <Card className="table-card">
       <Card.Header> Unifi Outages </Card.Header>
       <Card.Body>
         <table className="table table-bordered">
           <thead>
             <tr>
            <th>Title</th>
            <th>Link</th>
            <th>Date</th>
          </tr>
          </thead>
          <tbody>
          <tr>
            <td>{feed.title}</td>
            <td>{feed.link}</td>
            <td>{feed.updated}</td>
          </tr>
          <tr>
            <td>{}</td>
            <td>{}</td>
            <td>{}</td>
          </tr>
          <tr>
            <td>{azureData.title}</td>
            <td>{azureData.link}</td>
            <td>{azureData.updated}</td>
            </tr>
           </tbody>
         </table>
        </Card.Body>
        </Card>
       </Container>
           );
            };

Svelte & Electron: ‘default’ is not exported by node_modulesfirebaseappdistindex.esm.js

<script>
    import firebase from "firebase/app";
</script>

I got the following error when trying to import a the firebase app node module in a svelte component.. how do I make it work..?
I couldn’t find literally anything online apart from this: https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module. I’ve tried doing mostly everything it says to do on how to import a module but nothing worked.. so I’m completely stuck.

[!] Error: 'default' is not exported by node_modulesfirebaseappdistindex.esm.js

Here’s my rollup.config.js file:

import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';

const production = !process.env.ROLLUP_WATCH;

export default {
    input: 'src/svelte.js',
    output: {
        sourcemap: true,
        format: 'iife',
        name: 'app',
        file: 'public/build/bundle.js'
    },
    plugins: [
        svelte({
            dev: !production,
            css: css => { css.write('public/build/bundle.css'); }
        }),

        resolve({
            browser: true,
            dedupe: ['svelte'],
        }),
        commonjs(),

        !production && serve(),

        !production && livereload('public'),

        production && terser()
    ],
    watch: {
        clearScreen: false
    }
};

function serve() {
    let started = false;

    return {
        writeBundle() {
            if (!started) {
                started = true;

                require('child_process').spawn('npm', ['run', 'svelte-start', '--', '--dev'], {
                    stdio: ['ignore', 'inherit', 'inherit'],
                    shell: true
                });
            }
        }
    };
}

Jest – unable to absolute import for image

I tried to test for the component ContactListItem.test.tsx.
ContactListItem.test.tsx

import React from "react";
import { render, screen, RenderResult } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

import ContactListItem from "./index";

import { CONTACTS } from "../../constants/contacts";

const CONTACT_PERSON = CONTACTS[0];

describe("Testing ContactListItem component", () => {
  it("tests the image src and alt;", async () => {
    render(<ContactListItem contact={CONTACT_PERSON} />);
    const img = screen.getByRole("img");
    expect((img as HTMLImageElement).src).toContain(CONTACT_PERSON.iconSrc);
  });
});

contacts.ts

import Avatar_Cat from "src/assets/icons/avatar_cat.jpeg";

export const CONTACTS = [
  {
    id: 3,
    name: "Cat",
    iconSrc: Avatar_Cat,
    iconAlt: "Cat's icon",
    lastMessage: {
      id: 3999,
      time: "2022-01-03",
      message: "Hello World I am Cat"
    }
  }
];

But it shows an error when I run rpm test

 FAIL  src/components/ContactListItem/ContactListItem.test.tsx
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /Users/CCCC/Desktop/SourceTree/my-app/src/assets/icons/avatar_cat.jpeg:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){����
                                                                                      

    SyntaxError: Invalid or unexpected token

    > 1 | import Avatar_Cat from "src/assets/icons/avatar_cat.jpeg";
        | ^


      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)
      at Object.<anonymous> (src/constants/contacts.ts:1:1)

CodeSandbox
https://codesandbox.io/s/react-typescript-forked-222qbn?file=/src/components/ContactListItem/ContactListItem.test.tsx:0-574

Return in function gives undefined but with console log it shows the result [closed]

When I put return to the value of the calculateHeight function, it gives me undefined, but with console.log it does show me the value that it should be. Could someone correct my code, I’m learning 🙂 The function that I execute in the console is HeightTriangle, which changes the values in the calculateHeight function, according to certain conditions

function calcularAltura(lado,base) {
    const altura = Math.sqrt((lado**2)-((base**2)/4));
    return altura;
}

function alturaTriangulo(lado1,lado2,lado3) {
    const alerta = document.getElementById("resultadoAlerta");

    if(lado1+lado2 <= lado3 || lado1+lado3 <= lado2 || lado2+lado3 <= lado1){
        alerta.innerText = "Este triángulo no existe, introduce otros valores"
    }else{
       switch (true) {
        case lado1 === lado2 && lado1 != lado3:
            calcularAltura(lado1,lado3)
        break;
        case lado1 === lado3 && lado1 != lado2:
            calcularAltura(lado3,lado2)
        break;
        case lado2 === lado3 && lado2 != lado1:
            calcularAltura(lado2,lado1)
        break;
        case lado1 === lado2 && lado2 === lado3:
            alerta.innerText = "Este es un triángulo equilatero";
            calcularAltura(lado2,lado1)
        break;
        default: 
            alerta.innerText = "Este no es un triángulo isósceles";
        break;
       }
    }
};

change Leaflet circleMarker ,to any custom icon (large data)

enter image description here
I load about 10K L.circleMarker on the leaflet map and its works great.
I try to change the icon of the circle to anything but I cant
I know that I can change the icon in the regular marker but I don’t, know how can I change the L.circleMarker.

can’t find any doc about changing circle markers:
https://leafletjs.com/reference.html#circlemarker

I want to get a result something like this but with different shapes of circle markers:
enter image description here

ill be thankful if you have any experience to share

Compare the Two array in JS [duplicate]

In this problem, I square all the component inside the first array, then I sort both of the array to compare it. However, the result is False even both of the array after the process is the same. And I really don’t know why? pls help me out. Thanks

function comp(array1, array2){
  //your code here 
  let square = [ ]; 
  
//   let str = array1.join("")
  for(let i=0; i<array1.length; i++){
    square.push(array1[i] * array1[i])
  }
   array1 = square.sort((a,b) => a-b);
   array2 = array2.sort((a,b) => a-b);

  console.log(array2)
  console.log(array1)
  console.log(array1 === array2)

}
comp([121, 144, 19, 161, 19, 144, 19, 11],[121, 14641, 20736, 361, 25921, 361, 20736, 361])

how to insert active class in tabs dynamically (like in bootstrap tabs)

im trying to display data from database in tabs form.

Page title in tab title and when user click on tab title it display its corresponding content in tab-content

<!-- tab-title -->
<ul class="page-title">
    <?php
        //getting parent page title from database
        //Query by id

        //defining $i for data-bs-target for id target in tab-content
        $i = 1; 
        //fetching data with while loop and getting primary key (id)
        $parent_id = $rows->id;
    ?>
    <li class="dropdown">
        <!-- data-bs-target to link tab title with tab-conten id -->
        <a class="menu-link main-link" data-bs-target="<?php echo $i; ?>">
            <!-- display parent-title  -->
            <?php echo $rows->page_title;?>
        </a>
        
        <!-- displaying child page title -->
        <ul class="sub-menu list-unstyled px-3 py-2">
            <?php
                //displaying child page title only foreign key in child table match with id from parent table
                //query where child page foreign id match with parent page primary key
                //fetching data with while loop
            ?>      
            <li class="menu-item">
                <!-- data-bs-target to link tab title with tab-conten id -->
                <a  class="menu-link" data-bs-target="<?php echo $i; ?>">
                    //displaying child title in match of foreign key with primay key of parent page
                    <?php echo $child_rows->child_title;?>
                </a>
            </li>
            <!-- while loop for child page ends -->
        </ul>
    </li>
    <!-- while loop ends for parent page     -->
</ul>

Tab-content

<!-- tab-content -->
<div class="content-wrap py-0">
    <?php
        $child_data = $conn->prepare("SELECT * FROM children_page WHERE parent_id = :parent");
        $child_data->bindParam(':parent', $parent_id);

        //parent table
        $data = $conn->query("SELECT * FROM parent_page ORDER BY id DESC");
        $p=1;
        while($rows = $data->fetch(PDO::FETCH_OBJ) ):
            $parent_id = $rows->id;
    ?>
       <!--active class should added to page-section -->
        <div  class="page-section" id="<?php echo $p; ?>">
            <?php 
                //chlidren table
                $child_data->execute();
                if ($child_data->rowCount()) {
                    // parent has children
                    while($child_rows = $child_data->fetch(PDO::FETCH_OBJ) ): 
                    echo $child_rows->child_content;
            ?>

            <?php endwhile;
                }else{
                    echo $rows->page_content;
                }
            ?>
        </div>
    <?php $p++; endwhile;?>
</div>
    

Now Js for tab-title and Tab-content to interlink and work on click

$(".menu-link").on("click",function(){
        var dataValue= $(this).attr("data-bs-target");
        var dataValueArr = dataValue.split("#");
        var dataValuePosition= dataValueArr[1];
        
        $(".page-section").removeClass("active")
        
        $('.page-section').each(function() {
            aa = this.id;
            if(aa.match(dataValuePosition)){        
            if($i==0){          
                $(`#${dataValuePosition}`).addClass("active")
                }
                var headerHeight = $(".onzlogo").height();
                var sliderHeight = $(".slider-element").height()
                var totalHeight = headerHeight+sliderHeight;
                window.scrollTo({
                        top: totalHeight,
                        left: 0,
                        behavior: 'smooth'
                });
            }
          })
    })

menu-link is tab-title and page-section is tab-content
when user click on menu-link (tab-title) active class should be add to page-section(tab-content)

Above js code work fine with static code but with mysqli code im unable to insert active class.

how can i insert active class dynamically in loop to selected page-section(tab-content) only.

Make “a” tags, whenever it is clicked, add inner text inside it, but remove when another “a” tag (same class) is clicked

I’m making a Color Change function for my project.
This is my html:
click to see it

As title, I want to create some tags which have the same class like this: <a class="dropdown-item" onclick...></a>

And whenever a user click on 1 of those tags, that tag the user clicked will have an extra text [current] like this: Sky [current]. But when another tag is clicked, the text [current] will move to the new tag (with the same class) which the user just clicked.

Typescript ES2022 function call [duplicate]

Out of curiosity I checked the generated javascript with typescript target configured to ES2022 and I saw something like this:

function leFormat(a) { console.log(`yes`, a) }
(0, leFormat)(new Date())

Why typescript chooses to do this?
Why not just?:

leFormat(new Date())

Also, between parentheses values separated by comma will return the last one

a = (0, 1, '', null, console.log, undefined) // a === undefined
typeof (0, 1, '', null, console.log, undefined) === 'object'
(0, 1, '', null, console.log, undefined).toString() // TypeError: undefined has no properties

Is there a use for this, or is it just a quirk of the language?

how to fix npm run build failed to compile react js?

Creating an optimized production build…
Failed to compile.

Module not found: Error: Can’t resolve ‘./App’ in ‘/Users/qadeer/Desktop/Khazan/guardman/src’
Did you mean ‘App.js’?
BREAKING CHANGE: The request ‘./App’ failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a ‘.mjs’ file, or a ‘.js’ file where the package.json contains ‘”type”: “module”‘).
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
this is the issue i am getting

react state not updating properly for file uploader

I am trying to make a drag and drop feature with some files. I want to make it so that when a user drags and drops multiple files, those files are all added to a list. However, only one of the files that are dragged end up being added to the list and I am not sure why. here is how I am updating the state for the list of files:

   files.forEach(element => {
    onFileAdded({
        file_list: [
            ...file_list,
            element
        ]
        
    })
   });

Files is essentially what the user drags and when I log it, it looks something like this:
enter image description here

In my head I would assume that each file in files would be iterated through and added to file_list.

onFileAdded is the method im using to update the state for file_list. If I drag and drop multiple files however, I notice that instead of all of the files being added to the file_list, only one of them is. I have a feeling this has something to do with how im using the spread operator but I am not 100% sure. Any insights would be helpful.