PWA install Icon not appearing on Windows but Android is fine

On Windows, I defer the Install prompt for my Brotkrumen PWA but when I invoke event.prompt() later, I see a black square with the letter “B” in it and not my Ginger Bread House icon. This also happens if I click the Chrome/Edge/Opera/Firefox native install buttons directly.

If I say yes to install, then I also only get the white B on black background on homescree or Apps folder.

On my Android phone, everything works with the gingerbreadhouse.png icon appearing in both the install-confirm prompt and in the App folder. Edge/Firefox/Opera browsers are “branded” or badged on top of icon. Chrome and Samsung are not.

I’ve cleared all Caches and seen that my debug/applicatio/manifest has the images displayed and my Fetch API handler serves up the image when the confirm prompt appears but no house is forthcoming.

The code is not minimized but all source can be found in GitHub

Thanks.

PS. Slight nit: – Chrome webkit says “Added to home screen” when it isn’t. It’s Added to the Apps folder.

Youtube Iframe API Svelte document.create error

I am trying to use Youtube videos using Youtube Iframe API in my Svelte application. I get a variable is. not defined error. Here is my code

<script context="module">
    import { onMount } from 'svelte';
    // 2. This code loads the IFrame Player API code asynchronously.

    onMount(() => {
    var tag = document.createElement('script');

    });

    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

     
    // 3. This function creates an <iframe> (and YouTube player)
    //    after the API code downloads.

    window.onYouTubeIframeAPIReady = function () {
        console.log('hello')
      }

</script>


<script>
    export let videoId
</script>
<div>
    YT-Component VID: {videoId}
</div>

My error is: tag is not defined ReferenceError: tag is not defined at Youtube.svelte:10:4 at async instantiateModule (/Users/emrahgunel/Desktop/NAZ-BRAND-MichelobUltra/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:50286:9)

How can I fix this error. Thanks

how to pass input from html to java script function

}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form>
  <div id="main"></div>
  num: <input type="number" name="a" id="num"><br>
  <button id="add">Add</button>
  
</form>
<script>
const main = document.querySelector("#main");
var count = 1;
const addButton = document.querySelector("#add");
addButton.addEventListener("click", (e) => {
  e.preventDefault();
  var num = parseInt(document.getElementById('num').value);
  for (i = 1; i <= num; i++) {
    count++
    main.innerHTML += '<div class="row"><div class="col-md-4"><div class="form-group label-floating"><label class="control-label">Title</label><input type="text" class="form-control" v-model="act"></div></div></div>'
  }
});
</script>
<br>
<button> submit </button>

In this code you can enter a number into the input field then select the add button to get you that number of input fields. I am using this html code in a flask app and would like to get the initial input to python as well as each submission in the generated input forms, but im not sure how to go about that

Discord.js Exception embed author name has to be a string only accurse on Heroku

Hello Im having an utterly bizzare issue

Basically im currently trying to make an embed

        const error_embed = new Discord.MessageEmbed()
        .setColor('#c00be0')
        .setTitle("To use this command please mention a user")
        .setAuthor({ name: msg.author.tag + ' ', iconURL: msg.author.avatarURL() })

This is my current code

Now something utterly bizzare happens

Whenever im testing this code on my local machine it works perfectly without an issue

However whenever I deploy the code on Heroku it for some reason fails with the exception

MessageEmbed author name must be a string

If you dont know a lot about heroku please note that

Heroku uses the same node engine that I am using

Heroku uses the same discord.js version I am using

I have tried a few things to troubleshoot the issue

I first attempted to make the name a normal non variable string

this failed again

I also attempted to convert the content of the variable to string via the string.toString() method

Please note that this issue is for some reason exclusive to heroku

The code is the same

The modules are the same

The node version is the same

and it works perfectly on my pc

Could not find the language ‘cpp’, did you forget to load/include a language module?

I want to use highlight.js in my website.But it doesn’t work.
I use unpkg CDN and I import it like that:

<link rel="stylesheet" href="https://unpkg.com/@highlightjs/[email protected]/styles/rainbow.min.css">
<script src="//unpkg.com/@highlightjs/[email protected]/highlight.min.js"></script>

and I also use <script>hljs.highlightAll();</script> in the end of my file.
I couldn’t find anything wrong, but it still report a warning like that:
screenshot

Can any one help me?
Thanks!

TFN validation code with rendering parts not working – ReactJS

So I need to make a straight Reactjs TFN validator and because I’m very new to Javascript, I’m having a lot of trouble. I’ve tried countless fixes but none have worked with the integration standards that I need to abide by. I’m sure I’ve just made a dumb mistake but I can’t see it. If anyone wants to spend 10 minutes looking at what I’ve written and giving feedback, I’d really appreciate it and if someone does figure out how to get it working, I’m sure anyone else who could use this will appreciate. Thanks!

import React, {useState} from 'react'


export function TfnForm(props) {
    
    const [tfnvalue,settfnvalue] = useState("");
    const [success, setsuccess] = useState(false)
    var tfnconf = false;
    var sum = 0;
    console.log(tfnconf,"initiate")


    const handleValidation = validate => {
        setsuccess(current => !current)
    }


///return statements for render
    var doSuccess = function(message) {
        
        ('#result').addClass('bg-success').text(message).show();
    };
    var doError = function(message) {
        
        ('#result').addClass('bg-danger').text(message).show();
    };

///validation algorithm
    const validate = () => {
        
        if (tfnvalue.length === 9);
            sum = (tfnvalue[0]*1)
                    + (tfnvalue[1]*4)
                    + (tfnvalue[2]*3)
                    + (tfnvalue[3]*7)
                    + (tfnvalue[4]*5)
                    + (tfnvalue[5]*8)
                    + (tfnvalue[6]*6)
                    + (tfnvalue[7]*9)
                    + (tfnvalue[8]*10);
            sum = sum%11
            if (sum === 0) {
                return (
                    doSuccess("Valid Tax File Number")
                )
            }
            return (
                doError("Invalid TFN, check the digits.")
                )
            }
            
        
    
///rendering html
    return (
        
        <div className="container">
            <form id="tfn_validator">
                <h2>TFN Validator</h2>
                    <div className={success ? 'has-success':'has-error'}>
                        <label htmlFor="tfn" className="sr-only">TFN</label>
                        <input type="text" id="tfn" size="40" className="form-control input-lg" placeholder="Enter the TFN" autoComplete="off" onChange={v=>settfnvalue(v.currentTarget.value)} required autoFocus />
                 </div>
                    <br />
                <button className="btn btn-lg btn-primary btn-block" type="button" onClick={validate}>Validate</button>
                <br />
                
            </form>
            <br />
        </div>
    )}

The Center in a MapContainer in React-Leaflet-js Won’t Update

I’ve started to use React.js lately and was working on a project using React-Leaflet-js. My problem is that my MapContainer doesn’t change the center of the page whenever the position variable in the following code is updated:

...
  render() {
    const position = [this.state.location.lat, this.state.location.lng];
    return (
      <MapContainer
      className="map"
      center={position}
      zoom={this.state.zoom}
      scrollWheelZoom={true}>
...

For reference, the state variable that is being updated looks like this:

    state = {
    location: {
      lat: 40.7128,
      lng: -74.0060,
    },
    haveUsersLocation: false,
    zoom: 13,
  }

What’s weird is that a marker with a position set to {position} will automatically update when the position variable changes but not the center of the MapContainer. I’m not sure why the map doesn’t respond and adjust its center.

Note: I tried looking at this but it didn’t answer my question. Please help.

Not getting values using subscribe

I am trying to get data from subscribe and it seems to go past that step. I would like to know what am I doing here ?

this.store.dispatch(new PrimaryActions.CreateData(this.Id)).subscribe(
  result => {
    console.log('Response',result); // not getting the data
    this.saved.emit(result);
    this.onDialogClose();
  });

@Action(PrimaryActions.CreateData)
    createData(context: StateContext<PrimaryStateModel>, action: PrimaryActions.CreateData) {
    return this.dataService.createData(action.id).pipe(
        tap((result: Modal) => {
            console.log('response', result); // getting the right data here
            this.store.dispatch(new PrimaryActions.LoadData());
        })
    );
    }

React. Adding onClick event to causes a page reload

I’m using react router to create an SPA. However, I am dynamically creating blog posts that, when clicked, directs the page to the post. I want to store the key of the blog clicked so that I can render its’ contents on the new page, but when I add an onClick event it causes the page to reload and, presumably, deletes any state I’ve set. I really don’t want the page reloading at all, but I’m not sure how to fix it.

import { Link } from 'react-router-dom';
import Card from '../../shared/components/UIElements/Card';

import { useBlog } from '../../shared/hooks/blog-hook';

const BlogContainer = () => {
  const { getBlogIDHandler, blogs } = useBlog();
  const displayBlogs = blogs.map((blog) => {
    return (
      <Link to={`/${blog.key}`} onClick={getBlogIDHandler} key={blog.key}>
        <Card className="mapped">
          <h2>{blog.title}</h2>
          <h4>{blog.description}</h4>
        </Card>
      </Link>
    );
  });
  return <div className="blog-container">{displayBlogs}</div>;
};

export default BlogContainer;

I’ve tried adding event.preventDefault() to the getBlogIDHandler but that didn’t work either. I assume this is some weird React technicality I don’t understand, because if I remove the onClick event it renders the new page without a reload. I’d prefer a clean workaround but I’d understand if I have to do something jank.

Javascript Why are let and const sometimes not mandatory? [duplicate]

For learning purposes, I decided not to systematically add “let” or “const” before a variable/constant when initialized and add them only when an error message is thrown.
This way, I realized that let and const are almost always mandatory except in some circumstances like event listeners.

Indeed, when I type this:

canvas.addEventListener('mousemove', function (e) {
    e.preventDefault();e.stopPropagation();
    mousePosX = parseInt(e.clientX) - canvas.offsetLeft;
    mousePosY = parseInt(e.clientY) - canvas.offsetTop;
})

I can retrieve these 2 variables (or any other within the listener) from anywhere in my code and no message is thrown.

Same thing with some functions:
Here, “stdCanvasW”, “stdCanvasH” and “grid” are fine as they are. “stdCanvasW”, “stdCanvasH” are called from inside the grid constructor without any error.

function init() {
    stdCanvasW = document.body.clientWidth - 2 * (canvas.offsetLeft);
    stdCanvasH = stdCanvasW/1.77;
    canvas.width  = stdCanvasW;
    canvas.height = stdCanvasH;
    ...
    grid = new Grid();
    ...
    ...
}

But then, I have a method inside a class with variables that aren’t used outside their own brackets and if I don’t use let/const with them, I get errors:

setHorizontalLines(i) {
    const margin = ((this.cellBlock*this.cellSize)-this.height)/2
    const y = this.cellSize * i - margin;
    ...
}

Can someone explain to me how to make sense out of this?

I read many articles about the variable scope but it’s most of the time about the good practices rather than about what javascript actually allows and why.

Any insight would be appreciated.

The `survey-react` gives an error with `this.addEvent`

I inherited a react project and I can’t figure out how to use survey-react module. I keep getting this error at http://localhost:3000/

Uncaught TypeError: this.addEvent is not a function
node_modules/survey-react/survey.react.js:2582

  2579 |  * options.newValue - new value.
  2580 |  */
  2581 | 
> 2582 | this.onPropertyChanged = this.addEvent();
       | ^  2583 | /**
  2584 |  * Event that raised on changing property of the ItemValue object.
  2585 |  * sender - the object that owns the property

I simplified my project to just 3 files, which are:

This is my src/index.js.

import React from 'react';
import ReactDOM from 'react-dom';
import * as Survey from 'survey-react';
const questions = {
  elements:[{"type":"comment","name":"If you could enhance one thing about this product, what would it be?","isRequired":true}]
};
const srv = Survey.Model(questions);
srv.data = {"If you could enhance one thing about this product, what would it be?":"I like it as is, no changes needed."};
ReactDOM.render(<Survey.Survey model={srv} />, document.getElementById('root'));

This is my package.json

{
  "name": "testingthis",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "babel-jest": "^23.6.0",
    "react": "^16.6.1",
    "react-dom": "^16.4.2",
    "react-scripts": "^2.1.8",
    "survey-react": "1.9.33"
  },
  "scripts": {
    "start": "react-scripts start"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

This is my public/index.html

<!DOCTYPE html>
<html lang="en">
  <body>
    <div id="root"></div>
  </body>
</html

What am I doing wrong?

Organizing and modify json file with javascript [closed]

I have a json file that look something like this,

[
  {
    "Company": "Nike",
    "Name": "Air Force 1"
  },
  {
    "Company": "Nike",
    "Name": "Air Force 1"
  },
  {
    "Company": "Adidas",
    "Name": "Pureboost 21"
  },
  {
    "Company": "Adidas",
    "Name": "Pureboost 21"
  },
  {
    "Company": "New Balance",
    "Name": "990 v5"
  },
  {
    "Company": "New Balance",
    "Name": "990 v5"
  },
  {
    "Company": "New Balance",
    "Name": "990 v5"
  },
  {
    "Company": "Nike",
    "Name": "Air Jordan"
  },
  {
    "Company": "Nike",
    "Name": "Air Jordan"
  },
  {
    "Company": "Nike",
    "Name": "Air Jordan"
  },
  {
    "Company": "New Balance",
    "Name": "574"
  },
  {
    "Company": "Nike",
    "Name": "SB Dunk"
  },
  {
    "Company": "Nike",
    "Name": "SB Dunk"
  }
]

Since it was a mess and there is a lot of duplicate i want to organize it so i can use it for my app picker, what i need is to modify that json file into new file that look like this

{
    "Nike": [
        {
            "label": "Air Force 1",
            "value": "Air Force 1"
        },
        {
            "label": "Air Jordan",
            "value": "Air Jordan"
        },
        {
            "label": "SB Dunk",
            "value": "SB Dunk"
        }],
    "Adidas":[
        {
            "label": "Pureboost 21",
            "value": "Pureboost 21"
        }],
   "New Balance":[
        {
            "label": "990 v5",
            "value": "990 v5"
        },
        {
            "label": "574",
            "value": "574"
        }]
}

i tried to do it in python using dictionary and stuff but i still can get the result so i thought it should be easier to be done in javascript but i lack of knowledge in js, is it possible? if possible what kind of approach that i could do in js?

Can I change the value of a property inside a redux state using a value passed in during the action call by the user?

I am trying to change the redux state, which is an object, but the property of the object that needs to be changed depends upon what the user wants to change. The state has properties in it that represent different rows in a table, and since there are a lot, I cant have a specific case for each one. So for example, instead of saying I want to change row1, I want to change action.row.

Here’s some code of how it would be normally:

case 'CHANGE_STATE': {
      return {
        ...state, row1: action.payload
      }
    }

And here’s an example of how I want it to work

case 'CHANGE_STATE': {
      return {
        ...state, action.row: action.payload
      }
    }

Where action.row is provided when calling the redux action.

How do I connect this script to one of my buttons? [duplicate]

<button class="ordercolor" onclick="ordercolor()">Order Color</button>
This is the button on HTML

var color = 
  ["#222f3e", "#dd260e", "#0ae196c", "#0ae127", "#0a7ce1", "#a60ae1", "#808000", "#00FF00", "#00FFFF", "#008080", "#FF5733"];
  var i = 0;
  addEventListener("click",
  function () {
  i = i < color.length ? ++i : 0;
  document.querySelector("body").style.background = color[i];

This is the script on Java.

That script applies on every button I got on HTML and I want it specific in one button.
Can you help me apply it to the specific button ? Or maybe you have another script for changing colors in order on click, like green after red after blue (always the same) ?