Key press shows the key character

I have a search box which is by default not autofocused.
So i am putting a keypress event on the body i.e. when forward slash (/) is pressed the search box should be in focus. Although on key press it puts the search box in focus but also puts the “/” in the search box.

body.onkeypress = (e) => {
    if(e.which === 47) {
        searchInput.focus()
    }
} 

How should I fix this?

navigator.mediaDevicesenumerateDevice() “audiooutput” not show in safari

I found a problem that navigator.mediaDevices.enumerateDevice() not show a audiooutput when I use Safari browser enter image description here but audioinput and videoinput still normally

In another case I use Chrome browser to see audiooutput but it can show audiooutput normally in log enter image description here

did anyone know why audiooutput can not show in Safari ?

How to open particular folder on using useref in react

I am trying to open particular folder from a button in react . But every time I use useRef i get the recent visited folder . I am referring the below for my code.
https://medium.com/web-dev-survey-from-kyoto/how-to-customize-the-file-upload-button-in-react-b3866a5973d8

Code sample is same as the above link

Is there a way to open particular folder every time and not the last visited folder?
Can I modify the input folder field anywhere or is there any other method..
Thanks for your response

How to conditionally show global Storybook argTypes?

In Storybook 6 my components have common properties such as theme, size, etc. which apply to 90% of my components. I want to define the controls for those props in a global way so I don’t have to duplicate it for each story.

This works when you define global argTypes however if a component does not have one of these props, Storybook still renders the prop in the table but does not show any control for it.

How do I prevent the prop from being rendered at all in the props table but still be defined in a global way?

Is pushing an object to an array async operation?

I was doing one problem-solving program where I had to find all the pairs from an array that adds up to a target (classic two-sum program just with a little addition). This was my first approach:

let findPair = (arr, target) => {
    let res = [];
    let mappingArr = new Map()
    let obj = {
        first: 0,
        second: 0
    }

    for(let i=0; i<arr.length; i++){
        let comp = target - arr[i];
        if(mappingArr.has(comp)){
            obj.first = arr[mappingArr.get(comp)];
            obj.second = arr[i];
            res.push(obj)
        } else {
            mappingArr.set(arr[i], i)
        }
    }
    return res;
}

let arr = [8, 7, 2, 5, 3, 1]
let target = 10;

let sumPair = findPair(arr, target);
console.log(sumPair);

**
This should output: [{first: 8, second: 2},{first: 7, second: 3}]
but instead it prints: [{first: 7, second: 3},{first: 7, second: 3}]
**

Now if I make one little change in the for loop like this:

if(mappingArr.has(comp)){
    res.push({first: arr[mappingArr.get(comp)], second: arr[i]});
} else {
    mappingArr.set(arr[i], i)
}

by directly pushing the object instead of first assigning to one object and then pushing the object to an array, it works fine.

I also faced a similar issue with my back-end code once. That time too I couldn’t understand why the issue was arising.

Any idea why this is happening.?

Thanks.!

Why my DIV is not showing up in mobile browser but shows on desktop browsers?

Very generic issue I am sure, and apologies for the title, but not sure how else to word this.

Background: VisualStudio 2022 preview, .Net 4.8, ASP.Net (not Core)

index.aspx

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <style>
        iframe {
            position: absolute;
            border: solid ;
            border-width: 1px;
            box-sizing: border-box;
            min-width: 855px;
            min-height: 465px;
        }
    </style>
    
    <div class="divCanvas">
        <canvas id="compass" height="230" width="230"></canvas>
    </div>

    <iframe id="if1" 
        src="https://awebsite">
    </iframe>
</asp:Content>

CSS

#compass {
    background: url("../images/compass2.png");
    background-size: cover;
    vertical-align: middle;
}

.divCanvas
{
    z-index:99;
    position:absolute;
    margin-left: 525px;
    margin-top: 70px;
}

So what we have here is a simple <iframe> showing me a website and using CSS and <div> I am overlaying a <canvas> object over the iframe, and yes in a specific spot so that it overlays an area of the iframe where I want it displayed, hence the margin-left and margin-right properties.

Problem is, this only works on desktop browsers (all of them), but does nothing other than show the iframe in a mobile browser (all of them again). What’s happened with my <div>?

Incidentally, the VS project generated a ViewSwitcher.ascx file, which I think is the issue here, but it doesn’t stand out where in the code there is anything happening for mobile browsers.

Any ideas please? Should I be using the ViewSwitcher ascx file in some way to display my div over the iframe? I have no idea what viewswitcher is really doing here in the first place or if it’s even needed.

Thanks

Feathers js how to customize service endpoints

So I want to attach a url to my user requests which is in another service. Problem is i cannot even get to customize the service as it would say invalid field. In this example, i just wanted to add a test data to the retuned data for get the get request.

const { Service } = require('feathers-sequelize')

exports.Users = class Users extends Service {
  get(data, params) {
    const userData = { ...data, test: 'test' }
    return super.get(userData, params)
  }
}

javaScript clock project clock hand issues

for some reason the hands on the clock are static and not following current time like i want it to, would appreciate some feedback as to why its not moving.

setInterval(setClock, 1000)

const hourHand = document.querySelector('[data-hour-hand]')
const minuteHand = document.querySelector('[data-minute-hand]')
const secondHand = document.querySelector('[data-second-hand]')

function setClock() {
  const currentDate = new Date()
  const secondsRatio = currentDate.getSeconds() / 60
  const minutesRatio = (secondsRatio + currentDate.getMinutes()) / 60
  const hoursRatio = (minutesRatio + currentDate.getHours()) / 12
  setRotation(secondHand, secondsRatio)
  setRotation(minuteHand, minutesRatio)
  setRotation(hourHand, hoursRatio)
}

function setRotation(element, rotationRatio) {
  element.style.setProperty('--rotation', rotationRatio * 360)
}

setClock()

Does Javascript finish executing async function even after the rest of the code has finished executing?

This is what I tried –

async func1(){
 // do asynchronous calls with await
 console.log("call finished");
}

func2(){
 func1(); // without await
 console.log("func2 finished");
 return;
}

func2();

The output was – func2 finished call finished.
So even after the parent function completed execution, the async function still completed what it was intended for.

Will this work in case of an API where we are returning something to an external service?
Like cloud functions –

async func1(){
 // do asynchronous calls - post db using await
 console.log("call finished");
}

func2(){
 func1(); // without await
 return response.status(200).send("");
}

func2();

Will the database call complete even if the response.send is executed first provided I don’t await for the first function to finish execution?

How to implement MUI skeleton on API response data?

I am using material-ui skeleton (Shimmer effect) on data which is coming from API.

{
accountData.usersAccountData.map((userData, index) => (
// ...UI code
)
)
}

Output is given below :
output
As you can see, I received 3 objects from API. So accountData.usersAccountData.map will run 3 times.
My question is, How can I implement mui skeleton while API is under process ?
How can show shimmer effect while API is under process ?

NOTE :
I have tried <Skeleton ...otherParams /> inside accountData.usersAccountData.map but this didn’t work because accountData.usersAccountData length is zero while API is under process.

What should i do if i have a componet with many methods that have a lot of code and logic in it and this logic is reused in many other components?

I am building an application with a lot of screens (components) each one has some methods such as save, add, delete, redo, view, and other functions. every function of them has a lot of code in it. now I have declared these functions outside my components and call them from my methods attached to the screen component so I can access them. when I call them I pass this keyword as an argument so I can access the state and props from these functions.
I did this to be able to share this logic across the components.
now my question: Is this a best practice?
if yes what is the best way to do this
if not what should I do instead
note I am using react