My javascript code below works fine but produces errors should i add more javascript code. I need help in debugging the problem

I have coded the javascript for my google maps as shown below. The code works perfectly fine but if I happen to add any other javascript code relating to something different it ceases to work and produces errors. I need assistance to debug what the problem is

// Initialize and add the map
window.initMap = initMap;
// Initialize and add the map
        var map;
        var InforObj = [];
        var centerCords = {
            lat: 37.78345,
            lng: -122.45792
            
        };
        var markersOnMap = [{
                placeName: "Vigor XF in Financial District",
                address: "QHVX+JW Financial District, San Francisco,<br> CA, USA",
                LatLng: [{
                    lat: 37.79412182661146, 
                    lng: -122.40019568708203
                }]
            },
            {
                placeName: "Vigor XF in Lower Haight",
                address: "QHCC+GG Lower Haight, San Francisco,<br> CA, USA",
                LatLng: [{
                    lat: 37.771363364156834, 
                    lng: -122.42870896060947
                }]
            },
            {
                placeName: "Vigor XF in Outer Richmond",
                address: "40406 Balboa St., San Francisco,<br> CA, 94121 USA",
               
                LatLng: [{
                    lat: 37.775897080821615, 
                    lng: -122.49445723177357
                }]
            }
        ];

        window.onload = function () {
            initMap();
        };

        function addMarkerInfo() {
            for (var i = 0; i < markersOnMap.length; i++) {
                var contentString = '<div id="content"><b><h6>' + markersOnMap[i].placeName +
                    '</h6><p>'+ markersOnMap[i].address +'</p><p> <table > <tr><th style="font-weight: normal;">MON - THU</th><td style="padding-left:10px;">05:30-20:00</td></tr> <tr><th style="font-weight: normal;">FRI</th><td style="padding-left:10px;">05:30-18:00</td></tr> <tr><th style="font-weight: normal;">SAT</th><td style="padding-left:10px;">07:00-14:30</td></tr> <tr><th style="font-weight: normal;">SUN</th><td style="padding-left:10px;">10:00-13:00</td></tr> </table> </p> <img style="margin-right:10px" height="75px" width="75px" src="img/1@2x (2).png"><img style="margin-right:10px" height="75px" width="75px" src="img/2 (2).png"><img style="margin-right:10px" height="75px" width="75px" src="img/3 (2).png"><img style="margin-right:10px" height="75px" width="75px" src="img/4 (2).png"></div>';
                
                const image =
                    "img/Pin.png";
                const beachMarker = new google.maps.Marker({
                
                    position: markersOnMap[i].LatLng[0],
                    map,
                    icon: image,

                });

                const infowindow = new google.maps.InfoWindow({
                    content: contentString,
                    maxWidth: 400
                    
                });

                beachMarker.addListener('click', function () {
                    closeOtherInfo();
                    beachMarker.setIcon("img/Selected.png");                                    
                    infowindow.open(beachMarker.get('map'), beachMarker);
                    InforObj[0] = infowindow;
                });
                beachMarker.addListener('mouseover', function () {
                    beachMarker.setIcon("img/Selected.png"); 
                 });
                beachMarker.addListener('mouseout', function () {
                    beachMarker.setIcon("img/Pin.png");                                    
                 });
            }
        }

        function closeOtherInfo() {
            if (InforObj.length > 0) {
                /* detach the info-window from the marker ... undocumented in the API docs */
                InforObj[0].set("marker", null);
                /* and close it */
                InforObj[0].close();
                /* blank the array */
                InforObj.length = 0;
            }
        }

        function initMap() {
            map = new google.maps.Map(document.getElementById('map'), {
              zoom: 13.75,
              scrollwheel: false,
              draggable: false,
              panControl: true,
              zoomControl: true,
              mapTypeControl: true,
              scaleControl: true,
              streetViewControl: true,
              overviewMapControl: true,
              rotateControl: true,
              center: centerCords
            });
            addMarkerInfo();
        }

Or anyone who can hel me to write code to produce such a map as shown below.
Google map

What is the different between react component and function as component in react

I’m been confusing since learning react.
For example i have very sample react component

export default function Foo(){
    return(
        <div>
            <div>some text</div>
       
        </div>
    )
}

And i want to add a child component:

export default function Foo(){

    const Bar  = ()=>{
        return (
            <input placeholder="some input"/>
        )
    }
    return(
        <div>
            <div>some text</div>
        </div>
    )
}

And as i know, i can use this component by two ways:

1. Use as function

return(
        <div>
            <div>some text</div>
            {Bar()}
        </div>
    )

2. use as component:

 return(
        <div>
            <div>some text</div>
            <Bar/>
        </div>
    )

What exactly different between these two? I thought it was same, until i have some problem with input, that if i use component as <Bar/>, it will not foucus on input after i input one word

Demo here: https://codesandbox.io/s/gifted-archimedes-l7bce7?file=/src/App.js

So what is the exact problem here? I code as component all the time, as my understand <Bar/> will equal Bar() when it return react component

Is am right or not?

React how to combine data from multiple API and render it

I need to fetch the data from the multiple API and need to render it. I have wrote the code to fetch the data from multiple API am getting the data as expected. The data I am getting is in nested array format. I can’t able to populate the data by interpolating the state. Since the data is in nested format I need to map it, since I am having multiple API call, I’m struggling to combine and map all the data from the API. How to combine all the data and perform map and render the data. Any body can guide me what I have to do to achieve this. Thanks in advance. I have wrote down the API call and data format I am getting.

   API Call:
    
     const [nanOne, setNanOne] = useState([]);
      const [nanTwo, setNanTwo] = useState([]);
      //   const [batch, setBatch] = useState([]);
    
      const fetchData = () => {
        const UserAPI = "https://reqres.in/api/users/2";
        const AirlineAPI = "https://reqres.in/api/users/2";
    
        const getUserData = axios.get(UserAPI);
        const AirlineData = axios.get(AirlineAPI);
    
        axios.all([getUserData, AirlineData]).then(
          axios.spread((...allData) => {
            console.log("data", allData.data);
            const allUserList = allData[0].data.first_name;
            console.log(allUserList);
            const allAirlineData = allData[1].data.last_name;
            // const allBatch = allData[2].data.id;
    
            setNanOne(allUserList);
            setNanTwo(allAirlineData);
            // setBatch(allBatch);
          })
        );
      };
    
    
      useEffect(() => {
        fetchData();
      }, []);
    
      return (
    
      <div class="col-md-8">
              <div
                class="artcileData"
                style={{ marginRight: "85px", height: "80%" }}
              >
                <div Container="container-fluid" class="border">
    
                  <div class="card" style={{ textAlign: "Left" }}>
                    <div class="card-body">
                      <h5 class="card-title">Special title treatment</h5>
                      <p class="card-text">
                        <Badge
                          bg="info"
                          style={{
                            position: "absolute",
                            right: "20px",
                            top: "15px",
                          }}
                        >
                          {/* {batch} */}
                        </Badge>
                       {nanOne} --------> This is not working since I need to map it
                       {nanTwo}
                      </p>
    
                      {/* <a href="#" class="btn btn-primary">Go somewhere</a> */}
                    </div>
                  </div>
                </div>
              </div>
            </div>

Data Format:

data 
(2) [{…}, {…}]
0:
config: {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …}
data:
data: {id: 2, email: '[email protected]', first_name: 'Janet', last_name: 'Weaver', avatar: 'https://reqres.in/img/faces/2-image.jpg'}
support: {url: 'https://reqres.in/#support-heading', text: 'To keep ReqRes free, contributions towards server costs are appreciated!'}

Frontend integration on React 18.1.0

I’m not able to write the code inside the index.js file. I wrote the code as per the code sandbox section of cube docs. It sends a console warning that my app may work as React 17. When I followed 18.1.0 conventions the page was shown loading and never stopped. Any solution to this?
It’s written like this currently and I’ve added CubeProvider to access cubejsapi at app.js file while setting up routes, which is working fine.

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { AuthProvider } from './context/AuthProvider';
import reportWebVitals from './reportWebVitals';
import 'bootstrap/dist/css/bootstrap.min.css';

ReactDOM.render(
  <React.StrictMode>
  <AuthProvider>
      <App /> 
  </AuthProvider>
  </React.StrictMode>,
  document.getElementById('root')
);

How to add a custom plugin in TinyMCE React for form elements with actions?

I would like to create a form with some buttons,checkbox and other form elements. When the button is clicked some action need to happen.
I tried to add actions in this way,

  function handleChange(){
    alert("Ok")
  }
  function checkBox() {
     return '<input type="checkbox" onchange='+ handleChange() + '> Hello </input>';
  }
  editor.ui.registry.addMenuItem("checkbox", {
    text: 'checkBox',
    onAction: function () {
      let html = checkBox();
      editor.insertContent(html);
    }
  })
})```

In such cases the action is called before and not at the onChange of the element. How to achieve this and have control over the element inside the tinyMCE React editor.

Progressively add types for a 3rd party javascript module

I’ve just been tasked with converting a fairly large project from Javascript to Typescript. One of the difficulties is that one of the 3rd-party modules we are using is also in Javascript, but ideally we’d like to add the types for that as well. This 3rd-party module is used extensively throughout the codebase, so we’d like to add the types progressively.

So, let’s say we have two components like this:

// -----| FirstComponentConsumer.tsx |-------------------------
import { FirstComponent } from 'third-party';

export const FirstComponentConsumer = () => {
  return (
    <FirstComponent name="pants" />
  );
};

// -----| SecondComponentConsumer.tsx |------------------------
import { SecondComponent } from 'third-party';

export const SecondComponentConsumer = () => {
  return (
    <SecondComponent type="text" />
  );
};

Now, I’d like to add the types for FirstComponent but not SecondComponent YET – I’ll add these later (in reality there are hundreds of exports that will need to be typed). So I can create my types file, something like:

// types.d.ts 
import type { ReactNode } from 'react';

declare module 'third-party' {
  export type FirstComponentProps = {
    name?: string;
  }

  export const FirstComponent = (props: FirstComponentProps) => ReactNode;
}

This works as expected – FirstComponent is now typed! But, it breaks SecondComponentConsumer because I haven’t said that the third-party module exports a SecondComponent. Of course this makes perfect sense, but can I turn off this checking for “undeclared types”? Or is that trying to have my cake and eat it too?

Move series legends below x-axis in highcharts

I am using highcharts in my angular app. I am using line charts. Chart is as follows:

line_charts

Fiddle is as follows:

https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/line-basic

Code is as follows:

Highcharts.chart('container', {

  title: {
    text: 'Solar Employment Growth by Sector, 2010-2016'
  },

  subtitle: {
    text: 'Source: thesolarfoundation.com'
  },

  yAxis: {
    title: {
      text: 'Number of Employees'
    }
  },

  xAxis: {
    accessibility: {
      rangeDescription: 'Range: 2010 to 2017'
    }
  },

  legend: {
    layout: 'vertical',
    align: 'right',
    verticalAlign: 'middle'
  },

  plotOptions: {
    series: {
      label: {
        connectorAllowed: false
      },
      pointStart: 2010
    }
  },

  series: [{
    name: 'Installation',
    data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
  }, {
    name: 'Manufacturing',
    data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
  }, {
    name: 'Sales & Distribution',
    data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
  }, {
    name: 'Project Development',
    data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227]
  }, {
    name: 'Other',
    data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
  }],

  responsive: {
    rules: [{
      condition: {
        maxWidth: 500
      },
      chartOptions: {
        legend: {
          layout: 'horizontal',
          align: 'center',
          verticalAlign: 'bottom'
        }
      }
    }]
  }

});

Code is working fine but I want the legends which I marked in red circle in image attached to come below x-axis. How can I dot that?

Script Convert local date time to unix timestamp with time difference of -4 before and 12 hours after in JAVASCRIPT

I am currently writing a script where it will parse the xml script into json format. I have some requirements that need to be filled in order for the json data to be populated correctly. However I am rather new with javascript writing. I am trying to convert local time into unix timestamp, with 4 hours before and 12 hours after due to time difference. I found out that to convert from datetime to unix timestamp I did but that doesnt cover the case of time difference. Also is that the correct way to print the timestamp of now with AM/PM in the end?

var data = JSON.stringify({'aData': json{"Table"]["Topic"]});
data=data.replace(/{"null}/g, """"); // here replace the value if blank as 0. (boolean false)
data=data.replace(Math.round(new Date().getTime()/1000).toString(), """"); //convert to unix timestamp
data = data.replace(formatAmOrPm(new Date), """");

context.setVariable("response.content", data);
if(json['entities].length != 0.0) {
  constructResponse(json['entities'][0];
} else {
  setErrorResponse("404");
}

function formatAmOrPm(date) {
 var hrs = date.getHours();
 var min = date.getMinutes();
 var ampm = hrs >= 12 ? 'pm' : 'am';
 hrs = hrs : 12;
 min = min < 10 ? '0'+min : min;
 var time = hrs + ':' + min + ' ' +ampm;
 return time;
}

Also if anyone can answer the following will be greatly appreciate:

  1. is there a way to only allow integer type value?
  2. Reference the same value from another field for example if A=1, can I also have B=1 exact same answer as A?
  3. Allow only value accept ‘A’ or ‘B’ and no other characters
  4. If the value is filled how do we ignore the value
  5. How to have a maximum character length
  6. Is there a way to follow a specific format, for example a Number than the string?

React-Router v6 and Material-UI Tab: An absolute child route path must start with the combined path of all its parent routes

I have a homepage where I need the links for the different pages.

<li>
          The tabs are located here - <Link to="/demo">Demo</Link>
        </li>
        <li>
          <Link to="/page1">Page1</Link>
        </li>
        <li>
          <Link to="/page2">Pge2</Link>
        </li>
        <li>
          <Link to="/page3">Pge3</Link>
        </li>

Under the Demo page are the tabs as well. Now, I’m trying to keep the current tab even when refreshed. However, I have encountered this problem:

codesandbox: https://codesandbox.io/s/basictabs-demo-material-ui-forked-kgrsgd?file=/demo.js:1045-2777

Absolute route path “/page1” nested under path “/demo” is not valid.
An absolute child route path must start with the combined path of all
its parent routes.

Routes

  <Routes>
    <Route path="/" element={<Homepage />} />
    <Route path="/demo" element={<Demo />}>
      <Route path="/page1" element={<Page1 />} />
      <Route path="/page2" element={<Page2 />} />
      <Route path="/page3" element={<Page3 />} />
    </Route>
  </Routes>

Demo.js

export default function BasicTabs() {

  const [value, setValue] = React.useState(0);

  const handleChange = (event, newValue) => {
    setValue(newValue);
  };

  useEffect(() => {
    let path = window.location.pathname;
    console.log(path);
    if (path === "/page1" && value !== 0) setValue(0);
    else if (path === "/page2" && value !== 1) setValue(1);
    else if (path === "/page3" && value !== 2) setValue(2);
  }, [value]);

  return (
    <Box sx={{ width: "100%" }}>
      <Box sx={{ borderBottom: 1, borderColor: "divider" }}>
        <h1>Some text here</h1>
        <Tabs
          value={value}
          onChange={handleChange}
          aria-label="basic tabs example"
        >
          <Tab
            label="Item One"
            {...a11yProps(0)}
            to="/page1"
            component={Link}
          />
          <Tab
            label="Item Two"
            {...a11yProps(1)}
            to="/page2"
            component={Link}
          />
          <Tab
            label="Item Three"
            {...a11yProps(2)}
            to="/page3"
            component={Link}
          />
        </Tabs>
      </Box>
      {value === 0 && (
        <TabPanel value={value} index={0}>
          <Page1 />
        </TabPanel>
      )}

      {value === 1 && (
        <TabPanel value={value} index={1}>
          <Page2 />
        </TabPanel>
      )}
      {value === 2 && (
        <TabPanel value={value} index={2}>
          <Page3 />
        </TabPanel>
      )}
    </Box>
  );
}

How to make a button that creates a button when clicked (in HTML and JavaScript)?

Basically the question. My code (below) is quite lengthy and probably terrible as I am very new to coding. I am aware that I should put the JavaScript and HTML in different documents, but I prefer it like such. What I’d like to do is create a table, that, when users enter a column, a button appears next to the column giving them the option to delete it had they made a mistake.

document.getElementById("add").onclick = function() {

  var node = document.createElement("Tr");
  document.getElementById("list").appendChild(node);

  var node = document.createElement("Td");
  var text = document.getElementById("w").value;
  var textnode = document.createTextNode(text);
  node.appendChild(textnode);
  document.getElementById("list").appendChild(node);

  var node = document.createElement("Td");
  var text = document.getElementById("m").value;
  var textnode = document.createTextNode(text);
  node.appendChild(textnode);
  document.getElementById("list").appendChild(node);

  var node = document.createElement("Td");
  var text = document.getElementById("p").value;
  var textnode = document.createTextNode(text);
  node.appendChild(textnode);
  document.getElementById("list").appendChild(node);
}
<table id="list">
  <tr>
    <th scope="col">Word</th>
    <th scope="col">English</th>
    <th scope="col">Pronunciation</th>
  </tr>
  <tfoot>
    <tr>
      <div class="boxy_bois">
        <td><input type="text" id="w" class="w" required/></td>
        <td><input type="text" id="m" class="m" required/></td>
        <td><input type="text" id="p" class="p" /></td>
      </div>
    </tr>
  </tfoot>
</table>
<div class="button_boi">
  <button class="button_boi" id="add">Enter</button>
</div>

making an image customizing app with javascript canvas

I am trying to create a similar application like hockerty.com with javascript canvas, especially the custom design section.
The most difficult part is having an image dissected into different part and making those different parts customizable to diffent colors or . here is a link to an example of the exact functionality i am talking about.
here is a link to an image of sections that i want to be customizable.

Please i would like suggestions of how do achieve this either with plugins, libararies or code samples of how to do this.
Thank you