Angular 11 – HostListener event click and get value object

I am using the HostListener directive, to listen for the click event on elements of the DOM.

@HostListener('click', ['$event.target']) onClick(e) {
  console.log("event", e)
}

When I click on a button tag, the “e” object has the following:

<button _ngcontent-abr-c111 type="button" class="close ng-tns-c111-3">x</button>

If I loop through the object, it shows the following:

  const objectList = Object.keys(e).map(k => (
    console.log("key", k)
  ));

// result = key __zone_symbol__clickfalse

But what I would like to ask in my code is, if the button element has the “close” class, if it does, I will do one thing and if not another.

How could I do it? Thanks,”

D3, Using variable as filepath, Throws up Unexpected Token < Error

I get this error, “Unexpected token < in JSON at position 0” when I set my filepath as a variable. I’ve set it as a variable because the filepath is dynamic. When I click on the error, It opens up the Index.html page and since that isn’t in JSON format, it throws up this error. The file path change works properly and the new data gets loaded in, It just that, it throws up this error in the console. If I don’t set the filepath as a variable and mention it as it is, It doesn’t throw up this error.

This throws the error

var file = "data/data.json"

d3.json(file).then(data => {
    data.forEach(d => {
        d.value1 = d.value1
        d.value2 = d.value2
    })
})

This doesn’t

d3.json("data/data.json").then(data => {
    data.forEach(d => {
        d.value1 = d.value1
        d.value2 = d.value2
    })
})

I even tried this, but the error still shows up

var file = "data/data.json"

fetch(file).then(res=>res.json()).then(data => {
    data.forEach(d => {
        d.value1 = d.value1
        d.value2 = d.value2
    })
})

Make a button disable at clicked but enable until countdown isn’t zero

function counter2(){
var counter =10;
var on=document.getElementById("bet");
setInterval(function(){
counter--;
if(counter==9){
    on.innerHTML = "";
    
    }
if(counter>=0){
    id=document.getElementById("res");
    var bet=document.getElementById("pts");
        
        var beth=document.getElementById("beth");
        var betv=document.getElementById("betv");
    id.innerHTML="Bet within&nbsp;" +counter + "&nbsp;seconds";;
    beth.disabled = false; //Beth is both Function and button //
    beth.style.backgroundColor = "#4CAF50";
    betv.disabled = false;
    betv.style.backgroundColor = "#008CBA";
    beth.style.cursor = 'pointer'; 
    betv.style.cursor = 'pointer'; 
    
    
    }
    if(counter==0){
        counter1();
        
        
        }

}, 1000);

}

I am making a function where a button will be disabled after clicked but the above counter automatically enables the buttons but i want both of them to be executed i. E. Disable a button after clicked and also disable if the timer is going on and also to enable the buttons if the button is not clicked

App wide RTK query loading & fetching indicator

In my React app, I am using RTK query to fetch data. I have 10+ API endpoints and a route for each one of the endpoints.

I want to show a horizontal line at the top of the page to indicate that the data fethcing is going on.

At the moment, I have done this.

const ArticlePage = () => {
  const { id} = useParams();
  const { data, isFetching, isLoading } = useFetchArticleByIdQuery(id);

  return (
    <Layout>
      {(isFetching || isLoading) && <LinearProgressIndicator />}
      <PageHead />
      {data && <ArticleContent article={data} />}
    </Layout>
  );
};

I have also tried this.

const ArticlePage = () => {
  const { id} = useParams();
  const { data, isFetching, isLoading } = useFetchArticleByIdQuery(id);

  return (
    <Layout>
      <LinearProgressIndicator shouldDisplay={(isFetching || isLoading)} />
      <PageHead />
      {data && <ArticleContent article={data} />}
    </Layout>
  );
};

It is cumbersome ot use the same thing on all the 10+ routes. So is there any way to show <LinearProgressIndicator /> once for all the 10+ endpoints?

Identifier ‘DoubleCenterException’ has already been declared – Angular

I have a custom JS file in my Angular project. I have included it under scripts in angular.json

! function(r) {
    "use strict";
    var a = {
        init: () => {
            a.stickyHeader()
        },
        stickyHeader: () => {
            r(".navbar").length && new Headhesive(".navbar", {
                offset: 350,
                offsetSide: "top",
                classes: {
                    clone: "banner--clone fixed ",
                    stick: "banner--stick",
                    unstick: "banner--unstick"
                },
                onStick: function() {
                    r(r.SmartMenus.Bootstrap.init), r(".navbar:not(.fixed) .language-select .dropdown-menu").removeClass("show")
                },
                AonUnstick: function() {
                    r(".navbar.fixed .language-select .dropdown-menu").removeClass("show")
                }
            })
        },
    };
    a.init()
}(jQuery);

But when the angular app reloads, i get an error:

Uncaught SyntaxError: Identifier 'DoubleCenterException' has already been declared srcassetssitejstheme.js:1

What could be the problem at line 1?

Is Split Task functionality available in React Version of Dhtmlx Gantt Chart?

The problem i am facing is displaying more than one task in a same row.
But the default structure of Gantt Chart is to show task in individual rows infront of task name. We have customize the structure and replaced task names ( left Columns of the Gantt Chart ) with the workers name. Tasks assigned to each Worker should displayed in the same row as the the worker name.

There is a functionality available in Js version of Gantt chart but not sure about the react version of it. In js one can access the instance of gantt chart and but in react you have to do everything with help of props.

As soon as I put in a “data-client-token”, the PayPal button refuses draw. Any idea why?

In my page I have

<script src="https://www.paypal.com/sdk/js?client-id=REDACTED&enable-funding=venmo&currency=AUD" data-sdk-integration-source="button-factory"></script>

As soon as I put in a data-client-token, e.g.

<script src="https://www.paypal.com/sdk/js?client-id=REDACTED&enable-funding=venmo&currency=AUD" data-client-token="DEPOSIT" data-sdk-integration-source="button-factory"></script>

the button refuses to draw. Any clues as to why? According to the documentation, this additional markup is permitted.

Synchronize leaflet map on two different browser tab

I am using leaflet, javascript, and react. The leaflet has a plugin called Leaflet sync.
This plugin sync two or more map demo. I want to synchronize the map in two different browsers’ tabs. Here is my code so far Code Link.

How can I use mapA.sync(mapB) to sync maps in two different browsers’ tabs. I think I cannot since both are isolated from each other.

How can I achieve the same functionality as in leaflet sync but with different browser tabs?

Vue js : Multiple instance VS Single instance but template from HTML, what is the best practice for performances

I have seen some questions in stackoverflow about that subject, but they never really mentioned performances.

Let’s say that I have HTML page with a list of Shop,
this HTML list is generated by the server in the page HTML.

I would like for each Shop HTML “block” to display a Vue JS <Calendar /> component

HTML :

<div class="list">
  <div class="shop">
    <div>
      <div>
        <div>
          <div>
           <div class="component-placeholder" data-shop-id="x"></div>
    ....
  </div>
  <div class="shop">
    <div>
      <div>
        <div>
          <div>
           <div class="component-placeholder" data-shop-id="x"></div>
    ....
  </div>
  ...
</div>

For JS there is 2 possibility.

Option 1 :

document.querySelectorAll('.component-placeholder').forEach((item) => {
  const shopId = item.getAttribute('data-shop-id');
  new Vue({
    render: (h) => h(Calendar, {
      props: {
        shopId,
      },
    }),
  }).$mount(item);
});

Option 2 :

const elem = document.querySelector('.list');
new Vue({
  el: elem,
  components: {
    Calendar
  },
});

// for this I would replace the component-placeholder with <Calendar shop-id="x" /> in the HTML

My question is, what is the best practice when focusing on performance ?

If the list has 30 Shop, Option 1 would create 30 instance of Vue living together,
but Option 2 would also need to add and create all the HTML elements inside its shadow DOM when the component is first loading no ?

I want to change the first order of the tab menu every time the tab menu is clicked

I want to change the first order of the tab menu every time the tab menu is clicked.

I am currently studying using an open source called jui.

Below is the tab menu source code.

HTML

<ul id="header-tab-menu" class="tab">
  <li><a href="#menu1">menu1</a></li>
  <li><a href="#menu2">menu2</a></li>
  <li><a href="#menu3">menu3</a></li>
</ul>

<div id="tab_left_contents">
  <div id="menu1"></div>
  <div id="menu2"></div>
  <div id="menu3"></div>
</div>

<div id="tab_right_contents">
  <div id="menu1"></div>
  <div id="menu2"></div>
  <div id="menu3"></div>
</div>

JS

jui.ready([ "ui.tab" ], function(tab) {
  header_tab_menu = tab("#header-tab-menu", {
    target: "#tab_left_contents, #tab_right_contents",
    index: 0
  });
});

In the JS source code, index: 0 indicates the first order of the tab menu.

Can’t get Qty to show in Increment and Decrement Component

I’m pretty new to react, and I am trying to make an Increment and decrement component in in my product screen. The issue that I’m having is that I would like it to only be able to increment if the there are that many items in stock, but when I try to do this the component stops showing the number associated with amount of the item chosen. I would really appreciate any help or guidance on how to do this.
Thank you!

ProductScreen.js

import React, { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { detailsProduct } from '../actions/productActions';
import LoadingBox from '../components/LoadingBox';
import MessageBox from '../components/MessageBox';
import { IconContext } from 'react-icons';
import { FiPlus, FiMinus } from 'react-icons/fi';


export default function ProductScreen(props) {
    const dispatch = useDispatch();
    const productId = props.match.params.id;
    const [qty, setQty] = useState(1);

  
  
    const productDetails = useSelector((state) => state.productDetails);
    const { loading, error, product } = productDetails;


    const handleQuantity = (type) => {
      if (type === "dec") {
        qty > 1 && setQty(qty - 1);
      }else if(product.countInStock >= product.qty){
        setQty(qty + 1);
      }
    };


    return (
        <div>
            {loading ? (
                <LoadingBox></LoadingBox>
            ) : error ? (
                <MessageBox variant="danger">{error}</MessageBox>
            ) : (
                <div>
                    <Link to="/body">Back to result</Link>
                    <div className="row top">
                     
                                     <div className="col-1">
                            <div className="card card-body">
                                <ul>
                                  
                                    <li>
                                        <div className="row">
                                            <div>Status</div>
                                            <div>
                                                {product.countInStock > 0 ? (
                                                    <span className="success">In Stock</span>
                                                ) : (
                                                    <span className="danger">Unavailable</span>
                                                )}
                                            </div>
                                        </div>
                                    </li>
                                    {product.countInStock > 0 && (
                                        <>
                                            <li>
                                                <div className="row">
                                                    <div>Qty</div>
                                                    <div className="AddContainer">
                                                      <div className="AmountContainer">
                                                        <FiMinus onClick={() => handleQuantity("dec")}/>
                                                        <div className="Amount">{product.qty}</div>
                                                         <FiPlus onClick={() => handleQuantity("inc")}/>
                                                      </div>
                                                    </div>


                                                 <div>
                                                  
                                                  
                                                  </div>
                                                </div>
                                            </li>
                                       
                                        </>
                                    )}
                                </ul>
                            </div>
                            
                        </div>
                    
                                    
                                
                               
                                 </div>
                                </li>
                            </ul>
                        </div>
                       </div>
                   
        </div>
      );
}


Unable to query using date timestamp in mongodb atlas data api

Unable to query using date while passing through mongo data api. I would like to query the database to find fetch all entries at the time

await superagent.post(`${url}/action/${body.action}`)
       .send({
        dataSource: 'Cluster0',
        database:'testDB',
        collection: body.collection,       
        filter: body.filter,
        sort: body.sort,        
      });


const config = {
  action: 'find',
  collection: 'testCollection',
  filter: {
    sensorId: '1231541',
    sensorTimestamp: {
      $gte:  new Date('2022-01-28T20:14:26.223+00:00'),
      $lt: new Date('2022-01-28T20:33:16.324+00:00'),
    },
  },
  sort: {
    name: 1,
  },
};

How can I import runtime config in Nuxt without using useContext

I’m trying to import a public $config file without using useContext hook in nuxt composition API.

According to Nuxt3 official document, we are able to import config file without using useContext hook. You can read this document.

Like this:

import config from '#config'

Just wondering, is that possible in Nuxt2?

nuxt version: 2.14.9

@nuxtjs/composition-api version: ^0.29.0