Trying to use var as img src in JSX

I’m working on a react project and I have a situation where I need the src attribute for an img tag to be a variable. The relevant parts of the code look something like this:

import React, { useState, useEffect } from 'react';

// topics is already defined and is a js object

const allTopics = topics.map(topic => {
        url = topic['image_url'];
        return (
            <Grid item key={ topic['topic_id'] } item xs={4}>
                <div class='img-wrapper'>
                    <img id='topicpreview' src={url} alt="loading" />
                    <h1>{topic['topic_name']}</h1>
                </div>
            </Grid>
        );
    });

return (
<div style={{ padding: '0', margin: '0', border: '1px solid black', width: '100%', height: '60%', overflow: 'hidden', display: 'inline-block' }} text-align='center'>
                <Grid container>
                    {allTopics}
                </Grid>
            </div>
    );

The image path exists and points to a valid file and I’ve console logged the url to make
sure it’s the same path. However, it doesn’t find the image and ends up printing the “Loading” alternate text instead. I’m not sure what’s going wrong, so any help would be appreciated!

javascript how to get the web page get Session variable

I’m trying to a Session variable in javascript.

I have tried a number of post suggestions without success unfortinately.

I see this example all over the place.

    var userName = '<%= Session["UserName"] %>'

However that is not working, at least for me. What I am trying to do is as below.

    var qrdataString = "<qr-code data=" + "XL" + ' <%= Session["style"] %>'  + "></qr-code>";
    document.getElementById("styleqr").innerHTML = qrdataString; 

Using Single quotes where they appear above just returns the string as

    <%=Session["xUID"]%>   in the alert that I use to show me the returned value

Using Double quotes give me either – unexpected token: string literal – or unexpected token identifier.

Thanks

Method Tracers for New Relic in Nodejs

As the new relic docs are not very rich in providing examples. I wondered how I can use Method Tracers in Node Js for New Relic ?.
I want to make a common method that can be used for this purpose.

For example

ApplyMethodTracer (className, MethodNameOfClass) this method should apply method tracer for the given method of the given class.

expected spy to have been called at least once but was never called

How to fix this error –

AssertError: expected spy to have been called at least once but was never called

describe('subscribe()', () => {
    let subscription: subscriptionType;
    let eventCallbackSpy: SinonSpy = Sinon.spy();
    let track : Track;
    let videoTrack: MediaStreamTrack;

    describe('track mute event & publisher', () => {
      const mockDeviceAudio = {
        ID: '47dd6c612bb77e7992cb8f026b660c59648e8105baf4c569f96d226738add9a4',
        groupId: '99782d7b13f331947c1a9865b27cf7eabffbfd48cfe21ab99867d101c6d7b4d0',
        kind: DeviceKinds.AUDIO_INPUT,
        label: 'Fake Audio Input 1',
        mediaDeviceInfo: null,
      };

      const mockDeviceVideo = {
        ID: '47dd6c612bb77e7992cb8f026b660c59648e8105baf4c569f96d226738add9a4',
        groupId: '99782d7b13f331947c1a9865b27cf7eabffbfd48cfe21ab99867d101c6d7b4d0',
        kind: DeviceKinds.VIDEO_INPUT,
        label: 'Fake Video Input 1',
        mediaDeviceInfo: null,
      };

      before(async () => {
        [videoTrack] = (await navigator.mediaDevices.getUserMedia({video: true})).getVideoTracks();
        track = new Track(videoTrack as MediaStreamTrack);
        setupMediaTrackMocks();
        subscription = await track.subscribe('track:mute', eventCallbackSpy);
      });

      after(() => {
        resetMediaTrackMocks();
      });

      it('should have subscribe, track mute event available', () => {
        expect(subscription.listener.method).to.be.equal(eventCallbackSpy);
        expect(subscriptions.events['track:mute'].get(subscription.listener.id)).to.be.equal(eventCallbackSpy);
      });

      it('should have track object from the library (instanceof Track)', async () => {
        eventCallbackSpy = Sinon.spy();
        subscriptions.events['track:mute'].set(subscription.listener.id, eventCallbackSpy);
        Sinon.assert.called(eventCallbackSpy);
        console.log("log ", eventCallbackSpy.getCall(0));
        expect(eventCallbackSpy.getCall(0).args[0].action);
        // making sure track object from the library(instanceof Track)
        expect(eventCallbackSpy.getCall(0).args[0].track).to.be.an.instanceof(Track);
      });

This test is given error –

track mute event & publisher
        ✖ should have track object from the library (instanceof Track)
          Chrome Headless 93.0.4577.0 (Mac OS 10.15.7)
        AssertError: expected spy to have been called at least once but was never called

This is my subscribe –

async subscribe(eventName: string, listener: () => void): Promise<subscription> {
    const subscriptionListener = {
      id: uuidv4(),
      method: listener,
    };
  
    subscriptions.events[eventName].set(subscriptionListener.id, subscriptionListener.method);
    const thisEventListeners = subscriptions.events[eventName];
  
    switch (eventName) {
      case 'track:mute': {
        if (thisEventListeners.size === 1) {
          this.#mediaStreamTrack.onmute = (event) => {
            // using arrow function which should bind to this from outer scope track
            trackMutePublisher(event, this);
          }
        } 
        break;
      }
  
      default:
        break;
    }
  
    return new Promise((resolve) => {
      resolve({
        type: eventName,
        listener: subscriptionListener,
      });
    });
  }

In Test I am trying to check Sinon.assert.called(eventCallbackSpy); but still it’s giving the error expected spy to have been called at least once but was never called

Please help me.

ReactJs Download Excel Error : We found problem with content

I have below code to call api which returns bytes for excel.

When I convert bytes to excel online , file looks good.

But , When I call api through react js with below code , it gives me error –

We found a problem with content in <file.xlsx>. Do you want to recover
as mych as we can?

 agent.ExcelExport(data,{
responseType:"arraybuffer"
})
.then((res:any)=>{
const url= window.URL.createObjectURL( new Blob([res.data],{type:"application/x-msdownload"}));
const link=document.createElement('a');
link.href=url;
link.setAttribute('download','filename.xlsx');
link.click();
window.URL.revokeObjectURL(url);

I can see , Api getting hit clearly and responding with expected data. While opening file , its giving error.

.NET Core Api is returning –

return File(excelbytes,”application/x-msdownload”,”filename.xlsx”);

How to set custom x, y position of Electron Menu when using BrowserWindow.fromWebContents

I’m using contextBridge and contextIsolation to create a custom context menu on click and I’m using this example from the docs: https://github.com/electron/electron/blob/main/docs/api/menu.md#render-process

// renderer
window.addEventListener('contextmenu', (e) => {
  e.preventDefault()
  ipcRenderer.send('show-context-menu')
})

ipcRenderer.on('context-menu-command', (e, command) => {
  // ...
})

// main
ipcMain.on('show-context-menu', (event) => {
  const template = [
    {
      label: 'Menu Item 1',
      click: () => { event.sender.send('context-menu-command', 'menu-item-1') }
    },
    { type: 'separator' },
    { label: 'Menu Item 2', type: 'checkbox', checked: true }
  ]
  const menu = Menu.buildFromTemplate(template)
  menu.popup(BrowserWindow.fromWebContents(event.sender))
})

This works but the context menu appears right under the mouse. I want to supply a custom x and y. In the docs for menu.popup, I can set an x and y property like this:

menu.popup({
  window: /* my window object /*,
  x: /* x position */,
  y: /* y position */,
})

But I don’t know how to add these properties to the object that I get back from BrowserWindow.fromWebContents(event.sender).

I tried these options:

menu.popup({ ...BrowserWindow.fromWebContents(event.sender), x, y } );
// or
const window = BrowserWindow.fromWebContents(event.sender);
menu.popup({ window, x, y });

and I get this error

Error processing argument at index 1, conversion failure from 
at EventEmitter.a.popup (node:electron/js2c/browser_init:81:3188)

It seems like electron doesn’t like converting the results from BrowserWindow.fromWebContents(event.sender) into an object.

I also tried this, but get the same error.

const window = BrowserWindow.fromWebContents(event.sender);
window.x = x;
window.y = y;
menu.popup(window);

Thanks for the help

problem when using responsive file, code in responsive file has been add in index.html but can not active?

I am newbie with HTML CSS and trying to write a very simple program with HTML CSS with responsive file and here is my problem.

I wrote an index.html file and in this file, I added two classes like this

<div class="row contact-content">
                <div class="col col-half contact-info s-col-full">
                    <p><i class="ti-location-pin"></i>Chicago, US</p>
                    <p><i class="ti-mobile"></i>Phone: +00 151515</p>
                    <p><i class="ti-email"></i>Email: [email protected]</p>
                </div>
                <div class="col col-half contact-form s-col-full">
                    <form action="">
                        <div class="row">
                            <div class="col col-half">
                                <input type="text" name="" placeholder="Name" required id="" class="form-control">
                            </div>
                            <div class="col col-half">
                                <input type="email" name="" placeholder="Email" required id="" class="form-control">
                            </div>
                        </div>
                        <div class="row mt-8">
                            <div class="col col-full">
                                <input type="text" name="" placeholder="Message" required id="" class="form-control">
                            </div>
                        </div>
                        <input class="btn pull-right mt-16" type="submit" value="Send">
                    </form>
                </div>
            </div>

As you can see in my code, in the class, I want the class Chicago, US v.v will take up 100% the screen, and the row Name Email v.v will take up 100% the screen too because I add the code

.s-col-full {
    width: 100%;
}

to the responsive.

But, it does not happen.

Here is what I got in the screen, as you can see, the Chicago US is lying next to Name, Email, Message.my problem

But, as design, it must lie up the Name, Email, Message (because s-col-full is width: 100% in responsive)

Here is my code, sorry because I can not upload to bitbucket.

https://www.mediafire.com/folder/kfuqch81jqkwk/bai_90

Could you please give me some advice for this problem ? Thank you very much for your time.

Firebase App Check for Web App not working, did follow instructions, where am I going wrong?

So I followed the instrucutions on adding Firebase App Check as listed here. I created a reCAPTCHA V3 project and copied the “Use this site key in the HTML code your site serves to users.” in my firebase Init and then copied the “Use this secret key for communication between your site and reCAPTCHA” onto App Check setup (project/../settings/appcheck). I still am getting all unverified requests. Am I missing something? what am I doing wrong?

My init code is below:

    import firebase from 'firebase/compat/app'
    import 'firebase/compat/app-check'
    import 'firebase/compat/auth'
    import 'firebase/compat/analytics'

        // setting of firebase config params

        export const firebaseApp = firebase.initializeApp(config)
        if (firebaseApp) {
          const appCheck = firebase.appCheck()
          appCheck.activate('the HTML key from reCaptcha')
        }

I am not getting any errors in console. How do I debug this?
enter image description here

How does a parameter become a function call in JavaScript? [duplicate]

I often like to say that JS is not my home language and that’s led me to this question.

import Dropzone from "dropzone";

let myDropzone = Dropzone({
  paramName: "file", // The name that will be used to transfer the file
  maxFilesize: 2, // MB
  accept: function(file, done) {
    if (file.name == "justinbieber.jpg") {
      done("Naha, you don't.");
    }
    else { done(); }
  }
});

The preceding code is from Dropzone website about their great file upload tool.

The else done() confuses me. How would you know that’s a function if you were calling this? Done sports appears to be a parameter to me. If I’m using a good IDE, would I be directed as such? If not how do I know?