How to focus a text field when the page gets loaded in React using createRef()?

I’m able to achieve this functionality only when i invoke my function manually. Used componentDidMount() in my case to bring focus on the input element when the page loads, but no luck. Sharing my code –

import React, { Component } from 'react'

export class RefsDemo2 extends Component {
  constructor(props) {
    super(props)
    this.textInput = React.createRef();
    // this.focusTextInput = this.focusTextInput.bind(this);
  }

  focusTextInput(){
      this.textInput.current.focus();
  }

  componentDidMount(){
    this.textInput.current.focus();
  }

  render() {
    return (
      <div>
          <input type="text" ref={this.textInput}></input>
          {/* <input type="button" onClick={this.focusTextInput} value="Focus this input"/> */}
          {/* <input type="button" ref={this.focusTextInput} value="Focus this input"/> */}
      </div>
    )
  }
}

export default RefsDemo2

React Native: Attempt to invoke virtual method ‘boolean.java.lang.String.equals(java.lang.Object)’ on a null reference object

I have been using react-native-image-picker on my app for a while without problems but suddenly I’m getting the error on the title, afaik I haven’t changed anything in my code so I’m not sure why it’s giving me this error…

The modal for choosing gallery/camera doesn’t even opens now!

https://github.com/react-native-image-picker/react-native-image-picker

"react-native": "0.64.0",
"react-native-image-picker": "^3.1.3",
const launchImgLibrary = async (index) =>
    {
        //Alert.alert('kaka');
        let options = 
        {
            storageOptions: 
            {
                skipBackup: true,
                path: 'images' 
            },
        };
        
        launchImageLibrary(options, (response) => 
        {
            //console.log('Response = ', response);
            if(response.didCancel) 
            {
                console.log('User cancelled image picker');
            }
            else if (response.error) 
            {
                console.log('ImagePicker Error: ', response.error);
            }
            else 
            {
                let file = { uri:response.uri, name:response.fileName, type:response.type, title:'image' };
                
            }
        });
    };

Calling function to refresh data after form save is causing toasts/snackbar to render twice

In my submit form function below, the refreshGuestList() function is causing the snack bar to render twice.

If I remove the refreshGuestList it stops happening.

This function refreshes the data by calling a function in the parent function, then passing the data down as props to this form.

How can I stop this re-rendering of the snackbar/toast happening?

   if (inviteResponse.ok) {
                if (data.email) {
                    setSnackbarText(portalSettings.notifications.invite_sent);
                    setSnackbarOpen(true);
                }
                refreshGuestList();
            } 

How to show the complete text in the browser tab title

HTML

<!DOCTYPE html>
<html>
  <head>
  <title>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here,</title>
  </head>
  <body>
    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f4/Honeycrisp.jpg/800px-Honeycrisp.jpg" title = "사과입니다.!!!" width="250px;">
  </body>
</html>

The above simple html file contains title tag with some paragraph as text. When run the page, the title is getting truncated and showing ellipsis as …
How to show the complete text in the browser tab title?

I am using the angular 13 to set the title from the component as:
https://angular.io/guide/set-document-title

Unable to display an image using React JS

I’m starting out with React JS with a code to display a picture, a header tag and an ordered list. Here’s the JS code:

import React from 'react'
import ReactDOM from "react-dom"
const test = (
    <div>
        <img src="./balloons.png" width="100px" alt=""/>
        <h1>Names</h1>
        <ol>
            <li>A</li>
            <li>B</li>
            <li>C</li>
            <li>D</li>
        </ol>
    </div>
)

ReactDOM.render(test,document.getElementById("root"))

Here’s the index.html part :

<html>
    <head>
        <link rel="stylesheet" href="index.css">
    </head>
    <body>
        <div id = "root"></div>
        <script src = "index.pack.js"></script>
    </body>
</html>

Now, the code runs and displays an output like this in the react app. I can’t see the pic I uploaded.Output screen

Here is the folder arrangement in VS Code if it would help:

Folders

Thanks in advance!

Play sound periodically on web

I’m making a website, which must ring a bell 5 min before an event.

The code usually works, but sometimes (for some devices?), it fails to ring the bell and rings it only when page is reloaded.

The code you can find below, as you can see, the same function is run right after reload and every 1 minute, so it’s weird that it doesn’t ring automatically but rings after page reload.

...

ring_bell: function()
{
        if (<.. Time check is here ..>)
        {
            new Audio('media/bell.mp3').play();
        }
}

...

schedule.ring_bell();
setInterval(() => 
{
    schedule.update_timers();// updates time values on the web page
    schedule.ring_bell();
}, 60*1000);

Happened on MacBook, in Google Chrome.
Other facts to consider:

a) update_timers gets executed along side with the bell, which updates how the page looks like and the data on page was up to date, despite the fact that the bell sound hasn’t been heard.
Thereby one can conclude that timer is not the problem

b) The sound is known to be played successfully when tab is inactive.

I wonder, can something OS related intervene? Is there a way to grantee that the sound is played even if user doesn’t touch his device for a long time?
I don’t need precise timings. +/-1 minute is more than enough.

P.S. I open this question again after it has been instantly closed as a duplicate to How can I make setInterval also work when a tab is inactive in Chrome?, I hope new facts make it clear that it is a different problem and the answer to that question can not help me in the slightest.

Serve http responses whenever it arrives

Pretty new to web dev so my apologies if it’s not very clear.
I have an image processor in my backend that takes varied amount of time to process an image depending on its size, type etc. The number of images that can be sent is anything. I am trying to send multiple images into their api calls from my front end so that all images can be processed in parallel.

Now on my front end side I don’t want to wait for the final response, but instead serve any response that my backend sends back (let’s say backend got 5 images and processes the 4th image first. I want to show the 4th image anyway and continue showing images as and when they arrive)

I have tried promise.all() but i still have to wait until all images have been processed. Is there any other method that can help?

discord bot is not sending welcome massage

I want to send a welcome message to a new user but the code doesn’t work. I tried defiant articles and video tutorials and already asked questions for help but it’s not working. I already checked ( Privileged Gateway Intents > PRESENCE INTENT ) and ( Privileged Gateway Intents > SERVER MEMBERS INTENT )

here’s my code

const channelId = "969129834682929212";
  const rulesChannel = "969129988299304960";
  client.on("guildMemberAdd", (member) => {
    console.log(member);

    const message = `Welcome <@${
      member.id
    }> to our server! Be sure to check out our ${member.guild.channels.cache
      .get(rulesChannel)
      .toString()}`;

    const channel = member.guild.channels.cache.get(channelId);
    channel.send(message);
  });

Am5 chart circle add tooltip

I`m trying to add a tooltip to my chart but it doesn’t work. I’ve added it both to bullet and to series as well.

There is no enough info in docs about how to add tooltip in this case.

When I add tooltip to series in which graphic is based everything works perfectly

Can you help?

“Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.”

am5.ready(function() {

  // Create root element
  // https://www.amcharts.com/docs/v5/getting-started/#Root_element
  var root = am5.Root.new("chartdiv");

  // Set themes
  // https://www.amcharts.com/docs/v5/concepts/themes/
  root.setThemes([
    am5themes_Animated.new(root)
  ]);

  // Create chart
  // https://www.amcharts.com/docs/v5/charts/xy-chart/
  var chart = root.container.children.push(am5xy.XYChart.new(root, {
    panX: true,
    panY: true,
    wheelY: "zoomXY",
    pinchZoomX: true,
    pinchZoomY: true
  }));

  chart.get("colors").set("step", 2);

  // Create axes
  // https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
  var xAxis = chart.xAxes.push(am5xy.ValueAxis.new(root, {
    renderer: am5xy.AxisRendererX.new(root, {}),
    maxDeviation: 0.3,
  }));

  var yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
    renderer: am5xy.AxisRendererY.new(root, {}),
    maxDeviation: 0.3,
  }));

  var tooltip = am5.Tooltip.new(root, {
    labelText: "MCaPos: {valueY}nRN: ${valueY}",
    getFillFromSprite: false,
    getStrokeFromSprite: false,
    autoTextColor: false,
    getLabelFillFromSprite: false,
  });

  tooltip.get('background').setAll({
    fill: am5.color('#ffffff'),
    strokeWidth: 0,
  })

  tooltip.label.setAll({
    fill: am5.color('#000000')
  });

  console.log(tooltip)

  // Create series
  // https://www.amcharts.com/docs/v5/charts/xy-chart/series/
  var series0 = chart.series.push(am5xy.LineSeries.new(root, {
    calculateAggregates: true,
    xAxis: xAxis,
    yAxis: yAxis,
    valueYField: "y",
    valueXField: "x",
    valueField: "value",
    tooltip: am5.Tooltip.new(root, {
      labelText: "{valueY}"
    })
  }));

  // Create series
  // https://www.amcharts.com/docs/v5/charts/xy-chart/series/
  var series = chart.series.push(am5xy.LineSeries.new(root, {
    name: "Series 1",
    xAxis,
    yAxis,
    valueYField: "y",
    valueXField: "x",
    tooltip: am5.Tooltip.new(root, {
      labelText: "{valueY}"
    })
  }));
  series.strokes.template.setAll({
    strokeWidth: 2,
    strokeDasharray: [3, 3]
  });

  series.data.setAll([{
    "x": 0.01,
    "y": 1409090.91
  }, {
    "x": 0.06,
    "y": 1589743.59
  }, {
    "x": 0.11,
    "y": 1823529.41
  }, {
    "x": 0.16,
    "y": 2137931.03
  }, {
    "x": 0.21,
    "y": 2583333.33
  }, {
    "x": 0.26,
    "y": 3263157.89
  }, {
    "x": 0.31,
    "y": 4428571.43
  }, {
    "x": 0.36,
    "y": 6888888.89
  }, {
    "x": 0.41,
    "y": 15500000
  }]);

  var circleTemplate = am5.Template.new({});

  series0.bullets.push(function() {
    var graphics = am5.Circle.new(root, {
      fill: am5.color('#31DB42'),
    }, circleTemplate);
    return am5.Bullet.new(root, {
      sprite: graphics,
      radius: 1
    });
  });

  // Add heat rule
  // https://www.amcharts.com/docs/v5/concepts/settings/heat-rules/
  series0.set("heatRules", [{
    target: circleTemplate,
    min: 3,
    max: 35,
    dataField: "value",
    key: "radius"
  }]);

  // Add bullet
  // https://www.amcharts.com/docs/v5/charts/xy-chart/series/#Bullets
  var starTemplate = am5.Template.new({});

  series0.strokes.template.set("strokeOpacity", 0);
  series0.set('tooltip', tooltip);

  // Add cursor
  // https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
  chart.set("cursor", am5xy.XYCursor.new(root, {
    xAxis,
    yAxis,
    snapToSeries: [series0, series]
  }));
  series0.data.setAll([{
    "x": 0.09271021903999942,
    "y": 2712290
  }]);
  series0.appear(1000);

  // Make stuff animate on load
  // https://www.amcharts.com/docs/v5/concepts/animations/
  series.appear(1000);
  chart.appear(1000, 100);

}); // end am5.ready()
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
<script src="https://cdn.amcharts.com/lib/5/xy.js"></script>
<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
<div id="chartdiv" class="mt-20"></div>

How to generate hierarchy of data from plain json Angular

I am trying to create data hierarchy from plain data array list:
raw JSON file data is below:
{
        [
            "Test Survey template format"
        ],
        [
            "Description",
            "Test descriptions"
        ],
        [
            "Number of Categories",
            4
        ],
        [
            "Number of Questions",
            5
        ],
        [
            "Created By",
            "Rutuja Swami"
        ],
        [
            "Created On",
            44676.9454449537
        ],
        [
            "Survey Type",
            "Agile maturity, engineer assessment, DCAM"
        ],
        [
            "Survey level maturity label",
            "SCORE RANGE (Required)",
            "LABEL (Required)",
            "INTERPRETATION (Optional)",
            "COLOR"
        ],
        [
            null,
            "0 to 20",
            "Aware",
            "Familiar, in general, with the vocabulary, issues and practices, but this knowledge is often not complete or correct.",
            ""
        ],
        [
            null,
            "21 to 40",
            "Apprentice",
            "Has reliable and reasonably complete knowledge of issues, vocabulary and practices but has never applied them in real situations, only in simulations or highly constrained conditions.",
            ""
        ],
        [
            null,
            "41 to 60",
            "Practitioner",
            "Is applying the body-of-knowledge but largely",
            ""
        ],
        [
            null,
            "61 to 80",
            "Journeyman",
            "Has internalized the body-of-knowledge",
            ""
        ],
        [
            null,
            "81 to 100",
            "Master",
            "Understands the body-of-knowledge",
            ""
        ]
    ],
    "Category 1": [
        [
            "* indicates Mandatory"
        ],
        [
            "Category 1"
        ],
        [
            "Name",
            "Test Cat"
        ],
        [
            "Description",
            "NA"
        ],
        [
            "Score",
            50
        ],
        [
            "Help Context",
            "NA"
        ],
        [
            "Tags",
            "NA"
        ],
        [
            "Category level maturity label",
            "SCORE RANGE (Required)",
            "LABEL (Required)",
            "INTERPRETATION (Optional)",
            "COLOR"
        ],
        [
            null,
            "NA",
            "NA",
            "NA",
            "NA"
        ],
        [
            "Subcategory 1.1",
            "Test Cat of Test Cat"
        ],
        [
            "Name",
            "Test Cat"
        ],
        [
            "Description",
            "NA"
        ],
        [
            "Score",
            100
        ],
        [
            "Help Context",
            "NA"
        ],
        [
            "Tags",
            "NA"
        ],
        [
            "Category level maturity label",
            "SCORE RANGE (Required)",
            "LABEL (Required)",
            "INTERPRETATION (Optional)",
            "COLOR"
        ],
        [
            null,
            "NA",
            "NA",
            "NA",
            "NA"
        ],
        [
            "Subcategory 1.1.1",
            "Test Cat of Test Cat"
        ],
        [
            "Name",
            "Test Cat"
        ],
        [
            "Description",
            "NA"
        ],
        [
            "Score",
            100
        ],
        [
            "Help Context",
            "NA"
        ],
        [
            "Tags",
            "NA"
        ],
        [
            "Category level maturity label",
            "SCORE RANGE (Required)",
            "LABEL (Required)",
            "INTERPRETATION (Optional)",
            "COLOR"
        ],
        [
            null,
            "NA",
            "NA",
            "NA",
            "NA"
        ],
        [
            "Questions"
        ],
        [
            "Name",
            "Test Q123"
        ],
        [
            "Description",
            "Question test"
        ],
        [
            "Score",
            34
        ],
        [
            "Is question mandatory",
            "No"
        ],
        [
            "Question Type",
            "Checkbox list"
        ],
        [
            "Answer Options",
            "Answers",
            null,
            null,
            "Scale"
        ],
        [
            null,
            "Yes",
            null,
            null,
            1
        ],
        [
            null,
            "No",
            null,
            null,
            0
        ],
        [
            null,
            "Question not applicable",
            null,
            null,
            "NA"
        ],
        [
            "Help Context",
            "Question description"
        ],
        [
            "Tags",
            "Tags"
        ],
        [
            "Respondent Roles",
            "Architect"
        ],
        [
            "Branching Logic",
            "NA"
        ]
    ]
}

Expected data object is like nested hierarchy. Some expert guidelines are needed to achieve this.
Any help and suggestions are appreciated

**Expected Hierarchy is like:**
 {
            "categories": [
                {
                    "name": "Test Cat",
                    "additional Details": " ",
                    "tags": [],
                    "categories": [
                        {
                            "name": "Test Cat",
                            "sub Category Count": 4,
                            "total Question Count": 12,
                            "additional Details": null,
                            "tags": [],
                            "categories": [],
                            "questions": [
                                {
                                    "id": 4179361,
                                    "hint": null,
                                    "question Text": "It is well understood that.",
                                    "score": null,
                                    "tags": [],
                                    "question Type": '',
                                    "question Choices": [
                                        {
                                            "choice Text": "Never",
                                            "score": 1,
                                            "display Order": 0
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }

Note: Expected data hierarchy is like ‘Category’ is parent and subCategory is present in side it.
And questions are part of sub category. Hierarchy will be prepared like that.

How to improve a script [closed]

I’m Giuliano, I’m Italian and I apologize for my bad English.

I wrote this script (I used it in a Google Sheet)

function coloraesito() {
const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Foglio1")
const riga = ss.getLastRow(); // cerco l'ultima riga compilata
for (r = 6; r <=riga;r++){
for (c = 16; c < 23;c=c+1){
const esito = ss.getRange(r,c)

//coloro di arancione
if (esito.getValue() == "TRAT") {
esito.setFontColor("orange")
.setFontWeight("bold")
.setBackground("white")
}

//coloro di verde
else if (esito.getValue() == "PRPA" || esito.getValue() == "PRPR") {
esito.setFontColor("green")
.setFontWeight("bold")
.setBackground("white")
}

//coloro di azzurro
else if (esito.getValue() == "PGEF" || esito.getValue() == "PGER") {
esito.setFontColor("blue")
.setFontWeight("bold")
.setBackground("white")
}

//coloro di rosso
else if (esito.getValue() == "NR.1" || esito.getValue() == "VIDN" || esito.getValue() == "ICNT" || esito.getValue() == "VIPN") {
esito.setFontColor("red")
.setFontWeight("bold")
.setBackground("white")
}

//coloro di viola
else if (esito.getValue() == "DISA") {
esito.setFontColor("violet")
.setFontWeight("bold")
.setBackground("white")
}
}
}
}

It works, but it’s very slow. Is there a way to make it faster?
thank you in advance