react-router-sitemap giving ERROR Failed at the [email protected] sitemap script

I have a React router-based Single-Page-App and I’m trying to generate the sitemap links using react-router-sitemap version:^1.2.0 but I’m getting the same error again. And giving me Errors in the CSS files. I’m trying different techniques for 6 hours. Please suggest some solution.

Routes.js

import React from 'react';
import { Route, Routes } from "react-router-dom"

import GameComponent from './GameComponent';
import PlayGame from './PlayGame';
import PrivacyPolicy from './PrivacyPolicy';
import TermsConditions from './TermsConditions';

function Routesdef(props) {
    return (

        <Routes>
            <Route exact path="/" element={<GameComponent suggested__Games={props.suggested__Games} games={props.ALL__GAMES} key="all" />} />
            <Route exact path="/gamecomponent/:category" element={<GameComponent suggested__Games={props.suggested__Games} games={props.ALL__GAMES} key="categoryWise" />} />
            <Route path="/playgame/:gamename/:title/:gameSource/:category/:index" element={<PlayGame games={props.ALL__GAMES} suggested__Games={props.suggested__Games} key="playing" />} />
            <Route exact path="/privacypolicy" element={<PrivacyPolicy />} />
            <Route exact path="/termsconditions" element={<TermsConditions />} />
        </Routes>

    )
}
export default Routesdef

sitemap-generator.js

require("babel-register")({
  presets: ["es2015", "react"]
});

const router = require('./Routes.js').default;
const Sitemap = require('react-router-sitemap').default;

(
  new Sitemap(router)
    .build('https://www.onlineplaygames.online')
    .save('./public/sitemap.xml')
);

Scripts in Package.json

  "scripts": {
    "build:staging": "env-cmd -f .env.staging npm run build",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "sitemap": "babel-node src/sitemap-generator.js"
  },

Please Suggest some solution…????

Making a React component more general to handle realtime database collections

I am working on some javascrit code, handling a firebase realtime database and using React to manage the user interface. I want to have a generic class where I can provide the name of a collection to use, as a prop.

For example, this:

<MediaInput type='movies'/>

would make a component to use the movies collection.

This:

<MediaInput type='books'/>

would make a component to use the books collection.

And so on with:

<MediaInput type='tapes'/>

or

<MediaInput type='films'/>

…etc…

Below is my current code, the problem is that it only works with the books collection.

I have tried replacing ‘books’ by ‘dbCln’ in a few ways but it did not work. Does anyone know how I need to modify the code (I assume changing the lines containing ‘books’ by lines containing ‘dbCln’ in some way) to get the result I want.

import React from 'react';
import firebase from './initFirebase';
import './MediaInput.css';
import AppDB from './AppDB.js';

class MediaInput extends React.Component {
  constructor(props) {
    super(props);
    this.appDatabase = new AppDB();

    this.state = {
      books: [],
      dbCln: {
        [props.type]: []
      }
    };
  }


  componentDidMount() {
    this.getUserData();
  }


  componentDidUpdate(prevProps, prevState) {
    if (prevState !== this.state) {
      this.writeUserData();
    }
  }


  writeUserData = () => {
    this.appDatabase.addCollection(this.state);
  };


  getUserData = () => {
    let ref = firebase.database().ref("/");
    ref.on("value", snapshot => {
      const state = snapshot.val();
      this.setState(state);
    });
  };


  handleSubmit = event => {
    event.preventDefault();
    let name = this.refs.name.value;
    let price = this.refs.price.value;
    let uid = this.refs.uid.value;

    if (uid && name && price) {
      const { books } = this.state;
      const devIndex = books.findIndex(data => {
        return data.uid === uid;
      });
      books[devIndex].name = name;
      books[devIndex].price = price;
      this.setState({ books });
    } else if (name && price) {
      //const uid = new Date().getTime().toString();
      let uid = new Date().getTime().toString();
      const { books } = this.state;
      books.push({ uid, name, price });
      this.setState({ books });
    }

    this.refs.name.value = "";
    this.refs.price.value = "";
    this.refs.uid.value = "";
  };


  render() {
    return (
        <React.Fragment>
            <div className="inp-block">
            <form onSubmit={this.handleSubmit}>
              <div className="form-row">
                <input type="hidden" ref="uid" />
                <div className="form-group col-md-6">
                  <label className='inp-lbl'>Name</label>
                  <div className='inp-name'>
                    <input
                      type="text"
                      ref="name"
                      placeholder=""
                    />
                  </div>
                </div>
                <div className="form-group col-md-6">
                  <label className='inp-lbl'>Price</label>
                  <div className='inp-price'>
                    <input
                      type="text"
                      ref="price"
                      placeholder=""
                    />
                  </div>
                </div>
              </div>
              <div className="btn">
                <button type="submit" className="btn-primary">
                  Save
                </button>
              </div>
            </form>
            </div>
        </React.Fragment>
    )
  }
}

export default MediaInput;

Cors error while rendering FB Chat plugin for whitelisted domains

I am trying to add the Messenger Live Customer Chat Plugin dynamically to a site by first whitelisting the domain via the API and then injecting the script tag to the whitelisted domain site.

Now, after injecting the script to the whitelisted site it fails with CORS error. But, if I manually whitelist the URL via the Facebook app using the UI it works fine. I dont understand why does whitelisting via API does not work when the docs clearly say it should work.

  1. Successfully whitelisting a domain for a FB page via the API
curl 'https://graph.facebook.com/v12.0/me/messenger_profile?access_token=EAxxxxxxxPr' 
  -H 'authority: graph.facebook.com' 
  -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"' 
  -H 'accept: application/json, text/plain, */*' 
  -H 'content-type: application/json' 
  -H 'sec-ch-ua-mobile: ?0' 
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36' 
  -H 'sec-ch-ua-platform: "macOS"' 
  -H 'origin: https://livechat.frangout.com' 
  -H 'sec-fetch-site: cross-site' 
  -H 'sec-fetch-mode: cors' 
  -H 'sec-fetch-dest: empty' 
  -H 'referer: https://livechat.frangout.com/' 
  -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' 
  --data-raw '{"whitelisted_domains":["https://my-domain.com"]}' 
  --compressed

Result: {success: true } and I can also GET the whitelisted_domains and see it is already whitelisted

  1. Injecting script dynamically to the whitelisted site so that it loads the Messenger Live Chat Plugin
        var fbCustomerChat = document.createElement('div');
        fbCustomerChat.id = "fb-customerchat";
        fbCustomerChat.classList.add("fb-customerchat");
        fbCustomerChat.setAttribute('page_id', 'xxx')
        document.body.appendChild(fbCustomerChat);

        window.fbAsyncInit = function() {
            FB.init({
              appId            : 'xxx',
              autoLogAppEvents : true,
              xfbml            : true,
              version          : 'v12.0'
            });
        };

        (function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
  1. Browser Logs

Access to XMLHttpRequest at 'https://www.facebook.com/plugins/customer_chat/facade_gating/?page_id=106040728582517&suppress_http_code=1' from origin 'https://sid-s-school-12f2.thinkific.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr-patch.js:87 GET https://www.facebook.com/plugins/customer_chat/facade_gating/?page_id=106040728582517&suppress_http_code=1 net::ERR_FAILED 200

Access to XMLHttpRequest at 'https://www.facebook.com/plugins/customer_chat/SDK/trucnated co

Refused to frame 'https://www.facebook.com/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors https://www.facebook.com".

Create a node.js cpu process list

Node.js tried to make json a process that uses cpu a lot and distribute it. But I don’t know how to get cpu’s information. What should I do?

Currently, cpu information is agreed to be brought only from No. 1 to No. 5 in the process that is used a lot.

How to get state of children from parent in class component

I’m trying to display the state of child component in parent component, but somehow the text “abcde” still not show, here is the sample code

import React from 'react';
import {SafeAreaView, StyleSheet, Text} from 'react-native';
import {TouchableOpacity} from 'react-native-ui-lib';

class ChidComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      text: '',
    };
  }
  render() {
    return (
      <SafeAreaView>
        <TouchableOpacity
          onPress={() => {
            this.props.getText(this.state.text);
          }}>
          <Text>Get Text</Text>
        </TouchableOpacity>
        <TouchableOpacity
          onPress={() => {
            this.setState({text: 'abcde'});
          }}>
          <Text>set ramdom text</Text>
        </TouchableOpacity>
      </SafeAreaView>
    );
  }
}

const style = StyleSheet.create({
  text: {
    fontWeight: 'bold',
    fontSize: 40,
  },
});
class ParentComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      show: false,
      text: '',
    };
  }
  getTextFromChild(value) {
    this.setState({text: value});
  }
  render() {
    return (
      <SafeAreaView>
        <Text>{this.state.text}</Text>
        <ChidComponent
          getText={this.getTextFromChild.bind(this)}
          show={this.state.show}
          press={() => this.setState({show: !this.state.show})}
          textStyle={style.text}
        />
      </SafeAreaView>
    );
  }
}
export default ParentComponent;

But somehow the screen still empty, the ‘abcde’ still not show, come from functional component so i don’t know what going on, please help, thank you a lots

Memory leak in getImageData and passing to worker

In my main page it has a timer(1 second) to pass data to worker. The code is attached, the worker does nothing.

The memory in task manager keeps increasing very fast, how to avoid the memory leak?

let canvas = document.getElementById('mycanvas');
let video = this.runtime.ioDevices.video.provider.video;
canvas.getContext('2d').drawImage(video, 0, 0, 640, 480);
let canvas_data = canvas.getContext('2d').getImageData(0, 0, 640, 480).data
window.myWorker.postMessage({ type: "test", file: file, data: canvas_data });

Get the content of an input? [duplicate]

I have a question:

How do I get the exact content of an input. I have two inputs: type number. Now I want to get the numbers out of the two inputs and check which one is higher. I know how to check which one is higher. I just need to get the content of the inputs. Please tell me an easy way.

Why does the javascript variable name only print once in this html? [duplicate]

When I execute the following code, why does the variable name which is assigned to output only print the first time I use it…not every time I used it?

 <!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script>
window.onload = function(){
    var name = prompt("What's your name?");
    var lengthOfName = name.length

    document.getElementById('output').innerHTML = name;
};
</script>

</body>
</head>
<body>

<h1>My First Heading</h1> <p id="output" </p>
<p>My first paragraph.</p> <p id="output" </p>
<p>My second paragraph.</p>
<p id="output" </p>

</body>
</html>

when i run it…this is the what it looks like

My First Heading dodo bird

My first paragraph.

My second paragraph.

I would expect it to look like this

My First Heading dodo bird

My first paragraph. dodo bird

My second paragraph. dodo bird

creating an object with hours through the user interface

I am having trouble creating the right object. I have a calendar that stores the hours. He wants timeTable to hold such an object, for example

"timeTable":{
    "0": [{"from":"08:00","to":"12:00"}, {"from":"14:00","to":"18:00"}],
    "1": [{"from":"08:00","to":"16:00"}]
  }

How, after clicking the save button, send such an object to:

 timeTable: Map<number, Array<HourScheduleDefinitionModel>>;

interface:

interface HourScheduleDefinitionModel {
  from: string;
  to: string;
}

https://stackblitz.com/edit/angular-ivy-e92ezv?file=src%2Fapp%2Fapp.component.ts

Mongoose cast failed

Does anyone see what might be the problem ?

I feel like I am respecting each entries type, what’s wrong ?

{
  "message": "Product validation failed: subcategory.0: Cast to [string] 
failed for value ... (type string) at path "subcategory.0""
}

data.js

Understand DOM javascript?

I have this piece of code but I dont understand the presence of:” subTotal = subTotalElement.textContent “

function updateSubtotal(product) {
  console.log('Calculating subtotal, yey!');
  // const price
  // const quantity
  const price = product.querySelector('.price span');
  const quantity = product.querySelector('.quantity input');
  const subTotalElement = product.querySelector('.subtotal span'); //HTML element

   

  const subTotal = price.textContent * quantity.value; //input work with  input.value

 subTotal = subTotalElement.textContent ; //to change the HTML
  return subTotal;
}