navigation.addListener didFocus error when saving file in react native app

I am using the code below to reload a screen when each time it’s in focus. This works fine except when I make changes to the file during development then I get the error shown below the code example. Not sure if this matters since I won’t be saving the file while people are actually using the app. Can’t see pushing this out into production though with this issue, any help would be appreciated.

this.focusListener = navigation.addListener('didFocus', () => {

    fetchData();

});

Error message when saving file in development:

TypeError: undefined is not an object (evaluating '_this.focusListener = navigation.addListener('didFocus', function () {
        fetchData();
      })')

My app completely blows up and I have to reload it. Using Expo if that matters.

how to add reove active class on up and down arrow keys in react

i am tying to implement dropdown
enter image description here

here is the image

now i want to add active class to option 1 and on keypress event like up and down i want to move between options

here is what i have tried

  useEffect(() => {
    let btns = document.getElementsByClassName("list-item");
    console.log(btns[3]);
    for (var i = 0; i < btns.length; i++) {
      btns[0].classList.add("active");
      btns[i].addEventListener("keydown", function (e) {
        if (e.key === 38 || e.key === 40) {
          var current = document.getElementsByClassName("active");
          current[0].className = current[0].className.replace("active", "");
          this.className += "active";
        }
      });
    }

  });

here is how i am rendering dropdown list

  const options = ["Option1", "Option2", "Option3", "Option4"];

 {open && (
            <ul className="list" id="lists">
              {options.map((option, i) => (
                <li
                  onClick={() => {
                    setSelected(option);
                    setOpen(false);
                  }}
                  className="list-item"
                >
                  {option}
                </li>
              ))}
            </ul>
          )}

please help me i am stuck here from 2 days.
i can add active class to first option but it is not switching on up and down key press

thanks in advance

How to make one modal work for multiple button

It’s working but only in one button here’s my code. When i click at first button it showed up but when i click on the other buttons it doesnt show up. it seems that only at the first buttons its working. I also used the class to call the modal but it seems it also doesnt work.

<!DOCTYPE HTML>
<html>
<head>
    <title>Video Records</title>
    <style type="text/css">
        *{
            margin:0;
            padding: 0;
            box-sizing: border-box;
        }
        body{
            background-image: url(wallpaper.jpg) ;
            background-repeat: no-repeat;
            background-size: cover;
            font-family: sans-serif;

        }
        .table-container{
            padding: 0 10%;
            margin: 40px auto 0;
        }
        .heading{
            font-size: 40px;
            text-align: center;
            color:#FFFFFF;
            text-shadow: -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
            margin-bottom: 40px;
        }
        .table{
            width: 100%;
            border-collapse: separate;
            border-spacing: 0;
            box-shadow: 0 0 0 2px #FFD700;
            border-radius: 6px;
        }
        .table thead{
            background-color: #FFD700;

        }
        .table thead tr th{
            font-size: 14px;
            font-weight: medium;
            letter-spacing: 0.35px;
            color: #000000;
            opacity: 1;
            padding: 12px;
            vertical-align: top;
            border: 1px solid #000000;
        }
        .table tbody tr td{
            font-size: 14px;
            letter-spacing: 0.35px;
            font-weight: normal;
            color: #000000;
            background-color: white;
            padding: 8px;
            text-align: center;
            border: 1px solid #000000; 
        }
        table tr:first-child th:first-child,
        table.table tr:first-child {
        border-top-left-radius: 6px;
        }

        table tr:first-child th:last-child,
        table.table tr:first-child {
        border-top-right-radius: 6px;
        }

        table tr:last-child td:first-child {
        border-bottom-left-radius: 6px;
        }
    
        table tr:last-child td:last-child {
        border-bottom-right-radius: 6px;
        }


        .table tbody tr td .btn{
            width: 130px;
            text-decoration: none;
            line-height: 35px;
            background-color:#ee2828;
            display: inline-block;
            font-weight: medium;
            color: #FFFFFF;
            text-align: center;
            vertical-align: middle;
            user-select: none;
            border: 1px solid transparent;
            font-size: 14px;
            opacity: 1;
            border-radius: 5px;
        }
        .table tbody tr td .btn:hover{
            font-weight: bold;
        }


    .video-container {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 999999;
        background-color: rgba(1, 1, 1, 0.7);
        display: flex;
        justify-content: center;
        align-items: center;
        opacity: 0;
        pointer-events: none;
        transition: all 0.3s;
    }

    .video-container .close{
        position: absolute;
        top:10%;
        right: 25px;
        font-size: 20px;
        cursor: pointer;
        color:white;
    }
    .video-container video{
        width: 90%;
        max-width: 800px;
        transform: scale(0);
        box-shadow: 0 20px 20px rgba(0, 0, 0, 0.2);
        outline: none;
        transition: all 0.3s;
    }

    .video-container.show{
        pointer-events: all;
        opacity: 1;
    }

    .video-container.show video{
        transform: scale(1);
    }

@media(max-width: 768px){
    .table thead{
        display: none;
    }
    .table, .table tbody, .table tr, .table td{
        display: block;
        width: 100%;
        box-shadow: none;
    }
    .table tr{
        margin-bottom: 15px;
    }
    .table tbody tr td{
        text-align: right;
        padding-left: 50%;
        position: relative;
    }
    .table td:before{
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 50%;
        padding-left: 15px;
        font-weight: 600;
        font-size: 14px;
        text-align: left;
    }

    }
    </style>

</head>
<body>
        <div class="video-container" id="videoContainer">
            <span class="close" id="close">&#10006;</span>
            <video src="video.mp4" controls autoplay></video>
        </div>
    

    <div class="table-container">
        <h1 class="heading">Video Records</h1>

        

        <table class="table">
            <thead>
            <tr>
                <th>Video ID</th>
                <th>File Name</th>
                <th>Date</th>
                <th>Time</th>
                <th>#</th>
            </tr>
            </thead>
            <tbody>
                <tr>
                    <td data-label="Video ID">0022332</td>
                    <td data-label="File Name">Videocapture.mp4</td>
                    <td data-label="Date">12 / 04 / 2021</td>
                    <td data-label="Time">11:34 PM</td>
                    <td data-label="#"><a href="#" class="btn">Play</a></td>
                </tr>
                <tr>
                    <td data-label="Video ID">0022311</td>
                    <td data-label="File Name">Videocapture1.mp4</td>
                    <td data-label="Date">12 / 04 / 2021</td>
                    <td data-label="Time">11:34 PM</td>
                    <td data-label="#"><a href="#"   class="btn">Play</a></td>
                </tr>
                <tr>
                    <td data-label="Video ID">0022131</td>
                    <td data-label="File Name">Videocapture2.mp4</td>
                    <td data-label="Date">12 / 04 / 2021</td>
                    <td data-label="Time">11:34 PM</td>
                    <td data-label="#"><a href="#"   class="btn">Play</a></td>
                </tr>
                <tr>
                    <td data-label="Video ID">0025321</td>
                    <td data-label="File Name">Videocapture3.mp4</td>
                    <td data-label="Date">12 / 04 / 2021</td>
                    <td data-label="Time">11:34 PM</td>
                    <td data-label="#"><a href="#"   class="btn">Play</a></td>
                </tr>
            </tbody>
    </div>

<script type="text/javascript">
    
    
    btn = document.getElementById("btn");

    videoContainer = document.getElementById("videoContainer");

    close = document.getElementById("close");

    btn.addEventListener('click',()=>{
        videoContainer.classList.add('show');
    })

    close.addEventListener('click',()=>{
        videoContainer.classList.remove('show');
    })


</script>


</body>
</html>

I think its because of my javascript so I kind of wondering if someone could help me to make it work in multiple buttons instead of one only

confused about how CRUD apis should be designed for different authentication approaches

I am aware that there are primarily two approaches for authentication – sessions and tokens. And for sessions for I guess the session id is normally stored in the cookie that gets sent along with each subsequent request. And for tokens e.g. JWT it is normally a string added to the authorization header prefixed by bearer in HTTP header.

My first question: for the APIs that the front end uses to perform CRUD on protected resources on behalf of the logged in user, should userId be part of the API signature. In other words, do the frontend develoeprs need to pass the userId when they make those API calls? For example, I have an api endpoint for updating a resource

UpdateTask(userId?: string, taskId: string, updatedTaskConfig: TaskConfig): Task - POST /v1/tasks/:id

Should we omit userId since the session ID or the token (depends on which authentication approach we choose) is going to be enough for the backend to identify by which user this request is sent? Or we still need to include it?

Another related question is, I am aware that both JWTs and session IDs can be sent via multiple avenues (cookies, headers, request bodies, URLs, etc). Does that affect the API on the inclusion of the userId?

My second question is, for any CRUD operation, do the API calls need to include a timestamp generated on the frontend? Or it should be generated on the backend since the api calls can fail because of a number of reasons so that it makes more sense to let the backend generated the timestamp?

ReactJS SVG icon load fails with svgr in order to change SVG fill dinamically

I’ve been trying to use SVG in ReactJS for the past 2 hours but nothing seems to be working.

I’m using:

"react": "^17.0.2",
"react-dom": "^17.0.2",

"devDependencies": {
        "@svgr/webpack": "^6.0.0",
        "react-svg-loader": "^3.0.3",

Using create-react-app

I call the icon as:

import { ReactComponent as Logo } from '../../icons/logo.svg';
...
<Logo fill="white" />

And the error i get is:

./src/icons/logo.svg (./node_modules/@svgr/webpack/dist?-svgo,+titleProp,+ref!./src/icons/logo.svg)
TypeError: this.getOptions is not a function.

If i use it in an “img” tag, the icon shows, but I need to dinamically change the fill of the SVG.
If there is a way on how i can load an svg and change the fill dinamically, please help and thank you.

How can I loop through my records from MongoDB and display to a page?

I’m trying to loop through security questions and display the question text. Currently, they are displaying like this on the screen, however I only need the text of the question

{ "_id": "61a1569acfc17020c4d67a28", "securityQuestions": [ { "_id": "61a40df8703c7292e09376b3", "text": "What city were you born in?", "answer": "Peoria", "isDisabled": false }, { "_id": "61a40e02703c7292e09376b4", "text": "What is your favorite pets name?", "answer": "Rocky", "isDisabled": false } ] }

Here’s where I’m looping through in my html file

  <ng-container *ngFor="let question of questions; index as i">
    <div class="security-questions" fxLayout="row" fxLayoutGap="60%">
      <div class="icons">
        <h3>{{ question | json }}</h3>
      </div>

here is my TS file

imports...

export class SecurityQuestionsComponent implements OnInit {
  questions: SecurityQuestion[];
  user: User;
  constructor(public dialog: MatDialog, private http: HttpClient) {}
  ngOnInit(): void {
    this.fetchQuestions();
  }

  //Task dialog to open when user hits button
  openCreateQuestionDialog(): void {
    const dialogRef = this.dialog.open(CreateQuestionDialogComponent, {
      width: '250px',
      data: {
        question: {
          text: '',
          answer: '',
        },
      },
    });
    dialogRef.afterClosed().subscribe((result) => {
      this.questions.push(result);
    });
  }

  fetchQuestions(): void {
    this.http
      .get('/api/security-questions')
      .subscribe((res: SecurityQuestion[]) => {
        this.questions = res;
      });
  }

  deleteQuestion(i: number) {
    const question: SecurityQuestion = this.questions[i];
    this.http
      .delete(`/api/security-questions/${question._id}`)
      .subscribe(() => {
        this.questions.splice(i, 1);
      });
  }

  updateQuestion(question: SecurityQuestion): void {
    const dialogRef = this.dialog.open(CreateQuestionDialogComponent, {
      width: '250px',
      data: {
        question: question,
        newQuestion: false,
      },
    });
  }
}

my interface for security question

import { User } from "./user.interface";

export interface SecurityQuestion {
  _id: any;
  text: string,
  answer: string,
  isDisabled: boolean
}

this is what a record in my db looks like db record

How do to upload and convert json file to excel file in using javasxript and html

I need to upload and convert JSON files like

[
    {
        "First Name": "Paul",
        "Last Name": "Craig",
        "Gender": "Male",
        "Age": 18,
        "Phone": "072-8074-38"
    },
    {
        "First Name": "Alan",
        "Last Name": "Richards",
        "Gender": "Male",
        "Age": 22,
        "Phone": "616-2480-27"
    }
]

to excel file. Before downloading the file user must be able to preview the file. This needs to be done using HTML and javascript

Calling Google Local Services API from Google Sheets

I am attempting to call the Local Services API, which is documented here: Local Services API documentation

I am calling the API inside of Apps Script, which is a way to write JavaScript inside of a Google Sheet. I have closely followed the tutorial that has been written to call other Google APIs in Apps Script, but I have not been able to call this one.
Here is the function to call the API:

function makeRequest() {
  var adsService = getAdsService();
  console.log(adsService.getAccessToken()) //I am getting a token back here
  var response = UrlFetchApp.fetch('https://localservices.googleapis.com/v1/accountReports:search?query=manager_customer_id:{manager_customer_id}', {
    headers: {
      Authorization: 'Bearer ' + adsService.getAccessToken()
    }
  });}

The makeRequest() function calls the getAdsService function below. Inside of getAdsService I am specifying ‘adwords’ and I have set the scope for .setScope('https://www.googleapis.com/auth/adwords')

function getAdsService() {
  // Create a new service with the given name. The name will be used when
  // persisting the authorized token, so ensure it is unique within the
  // scope of the property store.
  return OAuth2.createService('adwords')
      // Set the endpoint URLs, which are the same for all Google services.
      .setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
      .setTokenUrl('https://accounts.google.com/o/oauth2/token')

      // Set the client ID and secret, from the Google Developers Console.
      .setClientId(ClientID)
      .setClientSecret(ClientSecret)

      // Set the name of the callback function in the script referenced
      // above that should be invoked to complete the OAuth flow.
      .setCallbackFunction('authCallback')

      // Set the property store where authorized tokens should be persisted.
      .setPropertyStore(PropertiesService.getUserProperties())

      // Set the scopes to request (space-separated for Google services).
      .setScope('https://www.googleapis.com/auth/adwords')

      // Below are Google-specific OAuth2 parameters.

      // Sets the login hint, which will prevent the account chooser screen
      // from being shown to users logged in with multiple accounts.
      .setParam('login_hint', Session.getEffectiveUser().getEmail())

      // Requests offline access.
      .setParam('access_type', 'offline')

      // Consent prompt is required to ensure a refresh token is always
      // returned when requesting offline access.
      .setParam('prompt', 'consent');
}

There are also 2 other methods to redirect the user to authorize this application.

I believe the problem is the way I am structuring the request. I believe I need to supply more information to the API call in the makeRequest function. I have seen a 'payload' : JSON.stringify(request, null, 2) go in the headers section of the request function where request specifies a specific set of instructions to call from the API but I do not know how to structure that for this case. A solution would be super appreciated.

Highcharts – Compare multiple series

https://www.goldmine-sice.com.tw/ag-%e6%a8%a1%e7%b5%84%e7%b8%be%e6%95%88-%e8%a4%87%e8%a3%bd/enter image description here
This is a Highcharts stock charts, and I put it on my wordpress website. I want this charts exactly the same but the data resource. I want to change the data from AAPL, GOOG, MSFT price to my csv data.

My csv data have to columns: date and price(everyday’s price index).

What should I do?

Unable to Detect link from Text with multiple links in text React js

I had tried to get the link from the text using below code

  urlify(description) {
   const regex = /(.+)[(.+)]((.+))/;
   return description.replace(regex, (match, a, b, c) => {
    const text = `${a[0].toUpperCase()}${a.substring(1)}${b}`;
    return a+' '+`<a href="${c}" target="_blank">${b}</a>`;
   });
  }
  render() {
    let description='Hello this is [XYZ](wwww.XYZ.com) and please redirect to [PQR] 
     (www.PQR.com)'
     return (
     <p dangerouslySetInnerHTML={{__html: this.urlify(description),}}></p>
   );
  }
}

The output I get here is like

Hello this is [XYZ](wwww.XYZ.com) and please redirect to PQR

Only the last link is getting as required, I am trying something like ‘Hello this is XYZ and please redirect to PQR’ where XYZ and PQR should only act as link.

How to change other components’ property with styled-components?

I am using styled-components and I am trying to change the height of Top to 300px when I focus on my Input.

I was tried something like this but not working:

&:focus ${Top} {
  height: 500px;
}

My code:

export const Top = styled.div`
  display: flex;
  align-items: flex-start;
  height: 150px;
`;

export const Input = styled.textarea`
  flex: 1;
  height: 100%;
  resize: none;
  border: none;
  outline: none;
  font-size: 16px;
  padding: 10px;

  &:focus ${Top} {
    height: 500px;
  }
`;

How do I change other components’ prop with styled-components?

Web dev project – API calls

I’m looking for high level advice for a web project I’m working on.

I’m working with the BscScan API for crypto tokens, and would like to display 10 different wallet balances on one page of my site using this API call – Get Token balance by address

My first thought to displaying these wallet balances on the page was to use a javascript script that runs the 10 separate API calls upon page load. However, according to BscScan Plans, you can only issue so many calls per second/day.

I’m wondering if there’s a way to run a script like this say every minute and store it somewhere backend. Then just use the page load javascript to retrieve this data from wherever I’m storing it. How would I go about something like this? I’m very new to web dev so this may be something simple, I just need help with the high level method of approach I could use and I can run with it from there.

Replace String with value `$&’ not working in javascript

I have string show {{value}} and I want replace {{value}} with $& but it not work. It return current value show {{value}}.
Here is my code

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  let data ="show {{value}}";
  let output = data.replace("{{value}}","$&");
  alert(output);
});
</script>
</head>
<body>


</body>
</html>

I don’t know why it not work. I try replace with other strings same $1, $a and it work.
How I can fix my problem

apakah ekstensi Beautify bekerja di semua bahasa pemograman?

does the Beautify vscode extension work for all programming languages,
I’m currently working on a PHP, dart/flutter, html, css, javascript and sass project?
if the Beautify extension does not work in all programming languages, is there another extension that can work in all programming languages such as pretier etc.

How can I make certain words highlighted in incoming text?

I am new to application development and working in React Native. I want the color of certain words in the text to be red and clickable like picture below. You can see the incoming data under the picture. The words in data.highlight should be red and clickable when first seen in the text. Although there are a few “dummy” as seen in the picture, only the first one is red. I tried to do this but couldn’t get it to a loop. Everything is constant when I do it. The incoming data may change and for example there may be more than 3 words in the data.highlight. How can I do this in a practical way?

const data = {
    text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, dummy when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
    highlight: ["dummy", "standard", "since"]
}

enter image description here

import React from "react"
import { Text, View } from "react-native"


const data = {
    text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, dummy when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
    highlight: ["dummy", "standard", "since"]
}


const WordBoxText = () => {

    // for first highlight word
    const convertData1 = data.text.split(data.highlight[0])
    let converted = []
    for (i = 1; i < convertData1.length; i++) {
        converted.push(convertData1[i])
    }
    const rest1 = converted.join(data.highlight[0]) // maybe it will useful
    const Highlighter = <Text style={{ color: "red" }}>{data.highlight[0]}</Text>


    // for first highlight word
    const convertData2 = data.text.split(data.highlight[1])
    let converted2 = []
    for (i = 1; i < convertData2.length; i++) {
        converted2.push(convertData2[i])
    }
    const rest2 = converted.join(data.highlight[1]) // maybe it will useful
    const Highlighter2 = <Text style={{ color: "red" }}>{data.highlight[1]}</Text>


    // for first highlight word
    const convertData3 = data.text.split(data.highlight[2])
    let converted3 = []
    for (i = 1; i < convertData3.length; i++) {
        converted3.push(convertData3[i])
    }
    const rest3 = converted.join(data.highlight[2]) //sentences from the last word
    const Highlighter3 = <Text style={{ color: "red" }}>{data.highlight[2]}</Text>


    const Final = () => {
        return (
            <Text>{
                convertData1[0]} {Highlighter}
                {convertData2[0]} {Highlighter2}
                {convertData3[0]} {Highlighter3} {rest3} </Text>
        )
    }

    return (
        <View style={{ marginTop: 100 }}>
            <Final></Final>
        </View>
    )
}

export default WordBoxText