How to delete a data of both api in mongodb using nodejs and express?

So, I have been trying to delete a particular object’s property with axios and used axios.delete(url).. I used this function inside a onClick operator.
It was Like this ->

const deleteFromMyItems = async () => {
    const url = `http://localhost:5000/myItems/${_id}`;
    const ok = window.confirm('Are you sure?');
    if (ok) {
        await axios.delete(url, {
            headers: {
                authorization: `Bearer ${localStorage.getItem('accessToken')}`
            }
        })
        await axios.delete(`http://localhost:5000/laptops/${_id}`)
        
    }
}

but the problem is that It only deletes one of them……
I want to delete both together….

how to slove this “TypeError: Failed to fetch why I’m facing this error”

reactjs to mongoDb

As you can see in tha reactjs code, am trying to the delet item in ui.

const ManageItem = () => {
      const [products, setProducts] = useProducts();
      const handleDelete = (id) => {
        const proceed = window.confirm("Are you sure you want to delete");
        if (proceed) {
          const url = `https://guarded-fjord-51404.herokuapp.com/products/${id}`;
          fetch(url, {
            method: "DELET",
          })
            .then((res) => res.json())
            .then((data) => {
              console.log(data);
              const remaining = products.filter((product) => product._id !== id);
              setProducts(remaining);
              toast("Delete Success");
            });
        }
      };

How to display record roll and attempts same time?

I got this little dice game and i display roll attempts at each game session but i also want to display “record score”, which will be in local storage. how could i make that?

  const [score, setScore] = useState(0)
   function updateScore() {
    setScore(prevScore => {
      return prevScore + 1
    })
  }
<Button rollDice={rollDice}>{tenzies ? "New Game" : "Roll"}</Button>
      <div>Roll attempts: {score} </div>
      <div>Record: {score} </div>
  function rollDice() {
    if (!tenzies) {
      updateScore()
      setDice(prevDice => {
        return prevDice.map(dice => {
          return dice.isSaved
            ? dice
            : generateDice()
        })
      })
    } else {
      setTenzies(false)
      setDice(allNewDice())
      setScore(0)
    }
  }

how to get an updated copy of a node tree after removing some of its nodes?

I need based on a condition to remove a node from a tree nodes and obtain as a result an updated copy of the tree nodes

With the help of this answer https://stackoverflow.com/a/72121755/615274 I get to the node to delete, I exclude it from the array it belongs to but the returned node tree does not reflect the changes

The data is as follows

const data = [
    {
        data: 1,
        children: [
            { data: 1000, children: [] },
            { data: 1200, children: [] },
        ],
    },
    {
        data: 2,
        children: [
            {
                data: 10,
                children: [
                    { data: 1001, children: [] },
                    { data: 1201, children: [] },
                    { data: 1002, children: [] },
                    {
                        data: 1201,
                        children: [
                            { data: 111, children: [] },
                            { data: 222, children: [] },
                        ],
                    },
                ],
            },
            {
                data: 12,
                children: [
                    { data: 100, children: [] },
                    { data: 120, children: [] },
                ],
            },
        ],
    },
];

The logic I use now is the following

function deleteNode(treeNode, targetId) {
    if (treeNode && Array.isArray(treeNode) && treeNode.length > 0) {
        for (let node of treeNode) {
            if (node.data === targetId) {
                treeNode = treeNode.filter((n) => n.data !== targetId);
                break;
            }
            deleteNode(node.children, targetId);
        }
    }

    return treeNode;
}

This identifies the node to delete, excludes it from it container, but when returning the node tree, the modification is not reflected.

const data = [
    {
        data: 1,
        children: [
            { data: 1000, children: [] },
            { data: 1200, children: [] },
        ],
    },
    {
        data: 2,
        children: [
            {
                data: 10,
                children: [
                    { data: 1001, children: [] },
                    { data: 1201, children: [] },
                    { data: 1002, children: [] },
                    {
                        data: 1201,
                        children: [
                            { data: 111, children: [] },
                            { data: 222, children: [] },
                        ],
                    },
                ],
            },
            {
                data: 12,
                children: [
                    { data: 100, children: [] },
                    { data: 120, children: [] },
                ],
            },
        ],
    },
];

function deleteNode(treeNode, targetId) {
    if (treeNode && Array.isArray(treeNode) && treeNode.length > 0) {
        for (let node of treeNode) {
            if (node.data === targetId) {
                treeNode = treeNode.filter((n) => n.data !== targetId);
                console.log("==== deleted node ====")
                console.dir(treeNode, { depth: null });
                console.log("==== deleted node ====")
                break;
            }
            deleteNode(node.children, targetId);
        }
    }

    return treeNode;
}

const output = deleteNode(data, 111);

console.dir(output, { depth: null });

Thanks in advance

Function doesn’t update value correctly onClick everywhere it should

I’m making a site with ranking of movies in React. I’ve decided to use this rating component (https://github.com/awran5/react-simple-star-rating) and it does work, but there’s problem with onClick.

My code looks like this:

Here’s component which includes rating system.

import { useState } from "react";
import { Rating } from "react-simple-star-rating";

const MovieInfoModal = ({ selectedMovieInfo, onClose, onRatingChange }) => {
  const [movieRating, setMovieRating] = useState(selectedMovieInfo.rating);


  const handleRating = (rate) => {
    setMovieRating(rate);
    let id = selectedMovieInfo.id;
    onRatingChange({ movieRating, id });
  };

  return (
    <div className="modal-blur">
      <div className="movie-info-box-modal">
        <button className="btn close-modal" onClick={() => onClose(false)}>
          X
        </button>
        <img src={selectedMovieInfo.cover} alt="" />
        <div className="movie-info-text">
          <div className="movie-info-title-description">
            <h1>{selectedMovieInfo.title}</h1>
            <h2>Description: </h2>
            <p>{selectedMovieInfo.description}</p>{" "}
          </div>
          <div className="movie-info-remarks">
            <h2>My Remarks:</h2>
            <p>{selectedMovieInfo.myRemarks}</p>
          </div>

          <div className="movie-info-box-rating">
            <p>Rating: {selectedMovieInfo.rating}</p>
            <Rating onClick={handleRating} ratingValue={movieRating} />
          </div>
        </div>
      </div>
    </div>
  );
};

export default MovieInfoModal;
}

And here’s the prop “onRatingChange”

 const changeRating = ({ movieRating, id }) => {
    setMoviesList((moviesList) =>
      moviesList.map((movie) =>
        movie.id === id ? { ...movie, rating: parseInt(movieRating) } : movie
      )
    );
  };

I’ve tried locating where the code doesn’t run using console.log(), but it turns out the code does run. For some reason movieRating value changes on first click only inside MovieInfoModal component, but it isn’t being send further by onRatingChange() inside changeRating.

EDIT:
I’ve changed “rate” inside handleRating to movieRating and it does work now, but I’m not really sure why.

How can I convert Python codes to C#?

I don’t know anything about C#. How can I convert Python codes to C#?

def encrypt(word):
        # from the javascript
        phrase = "e5dl12XYVggihggafXWf0f2YSf2Xngd1"
        # (a[2 * n] = (240 & t[n % t.length].charCodeAt()) | ((15 & r) ^ (15 & t[n % t.length].charCodeAt()))), (a[2 * n + 1] = (240 & t[n % t.length].charCodeAt()) | ((r >> 4) ^ (15 & t[n % t.length].charCodeAt())));
        a = []
        for idx, char in enumerate(word):
            r = ord(char)
            positioncode = ord(phrase[idx % len(phrase)])
            a.append((240 & positioncode) | ((15 & r) ^ (15 & positioncode)))
            a.append((240 & positioncode) | ((r >> 4) ^ (15 & positioncode)))
        return "".join(chr(char) for char in a)

p5.js ReferenceError: keyDown is not defined

Created this simple code that should move a rect in p5.js. I get the error ReferenceError: keyDown is not defined. What’s wrong? Do I have to install any other libraries or is it a syntax error?

function setup() {
    createCanvas(400, 400);
}
 
let x = 0;
let y = 0;

function draw() {
    if (keyDown(68)) // d
    {
        x += 3
    }
    if (keyDown(65)) // a 
    {
        x -= 3
    }
    if (keyDown(87)) 
    {
        y -= 3
    }
    if (keyDown(83)) 
    {
        y += 3
    }

    background(220)
    rect(x, y, 30, 50);
           
}

Firebase authentication register problem?

I am try to my best register on firebase authentication but I am facing some problems.

I am try to like this code but it’s not working.

const hadleToLogin = async event => {
    event.preventDefault();
    let email = event.target.email.value
    const password = event.target.password.value
    console.log(email, password)
    await signInWithEmailAndPassword(email, password);



    if (user) {
        navigate('/home');
    }

}

const navigateRegister = () => {
    navigate('/register')
}
const resetPassword = async () => {
    const email = emailRef.current.value;
    if (email) {
        await sendPasswordResetEmail(email);
        toast('sent email');
    }
    else{
        toast('enter a valid email')
    }
}

Create a carousal component with react-native-reanimated-carousel in react native

I have installed the package as per the instuctions but I get this error:
TypeError: Cannot read property 'computedFillDataWithAutoFillData' of undefined and Error: Requiring module "node_modulesreact-native-reanimated-carousellibcommonjsutilscomputedWithAutoFillData.js", which threw an exception: TypeError: undefined is not a function, js engine: hermes when I start the app.

I have create my app with react native CLI. I have tried using the bare example code, still nothing, like so:

      <View >
        <Carousel
          loop
          width={200}
          height={100 }
          data={[1, 2, 3]}
          //data={[...new Array(6).keys()]}
          renderItem={({index}) => (
            <View key={index}>
              <Text>111</Text>
            </View>
          )}
        />
      </View>

Is there a problem with my configuration?

Is CASL React library safe for authorization?

I came CASL JavaScript library, which restricts what resources a given client is allowed to access.

My question is whether it can be used for role based access in a React app in a secure way?

And whether user can temper with the permission and gain unauthorized access if used only in front end to display/hide components as shown in following react code?

import React, { useContext } from 'react';
import { AbilityContext } from './Can'

export default () => {
  const createTodo = () => { /* logic to show new todo form */ };
  const ability = useContext(AbilityContext);

  return (
    <div>
      {ability.can('create', 'Todo') &&
        <button onClick={createTodo}>Create Todo</button>}
    </div>
  );
}

Reference: https://casl.js.org/v5/en/package/casl-react

Excel-like overflowing cells in CSS

I want to implement an excel-like table using CSS, and have run into a problem – whenever the text overflows the bounds of a cell, if the next cell is empty it should overflow onto it, but stop once there is an un-empty cell, like such –
example
but I do not know how to limit overflow length. Does anyone know how to do it?