Mapbox Click and Hover condition conflicting

I’m trying to implement some logic

paint: {
  "fill-color": "#627BC1",
  "fill-opacity": [
    "case",
    ["==", ["feature-state", "mystate"], 1],
    0.6,
    ["==", ["feature-state", "mystate"], 2],
    0.8,
    0.4
  ]
}

The problem I have is, when I click on something and then move my mouse, then the hover condition applies and then removes the clicked state. How can I make the hover stop impacting the clicked state?

    map.on('click', 'state-fills', (e) => {
       var description = e.features[0].properties.country;  
       document.getElementById("popup").innerHTML = description;
       map.setFeatureState(
          { source: "states", id: hoveredStateId },
          { mystate: 2 }
       );
    });
    
 
     // When the user moves their mouse over the state-fill layer, we'll update the
     // feature state for the feature under the mouse.
     map.on('mousemove', 'state-fills', (e) => {
         if (e.features.length > 0) {
             if (hoveredStateId !== null) {
                map.setFeatureState(
                   { source: "states", id: hoveredStateId },
                   { mystate: null }
                );
             }
             hoveredStateId = e.features[0].id;
             map.setFeatureState(
                { source: "states", id: hoveredStateId },
                { mystate: 1 }
             );
         }
     });

I feel like I need a condition on hover to say if the mystate on that area is already at 2 then do nothing. This is what I tried but it didn’t work:

         if (hoveredStateId !== null) {
            map.setFeatureState(
               { source: "states", id: hoveredStateId },
               { mystate: null }
            );
         }
         if (hoveredStateId !== 2) {
         hoveredStateId = e.features[0].id;
         map.setFeatureState(
            { source: "states", id: hoveredStateId },
            { mystate: 1 }
         );
         }

Accessing Dexie(Indexed db) inside FCM onBackgroundMessageHandler

I am using FCM for push notifications in my web app and everything is working fine foreground and background except the fact that when my browser is closed, I am receiving FCM notifications but unable to process them. I am storing the data from FCM in an Indexed db wrapped by Dexie and my db is not updated with the FCM data values when the browser is itself closed.
However, if my app’s tab is closed but the browser is open, things work fine,
I am using the below code to do my task in my firebase service worker :

messaging.onBackgroundMessage(async function (payload) {
  console.log('Received background message ', payload);

  const notificationTitle = payload.data.title;
  const notificationOptions = {
    body: payload.data.body,
    tag: "notification-1",
    
  };

  if(!db){
    await initDb()
  }

  if (payload.data.type == 'DATA') {
   await addDataToDb(payload.data.item)
  }

  self.registration.showNotification(notificationTitle,
    notificationOptions);
});

async function initDb() {
  console.log("Initializing Dexie")
  db = await new Dexie('AppDB').open()
  Dexie.getDatabaseNames().then((names) => {
    console.log('Db names ' + names)
  });
}

DB updating code is all fine as it works as expected when the browser is still running.
Can someone please help me here?

graphql-tag: how to get the actual string for the body request?

I want to use the library https://github.com/apollographql/graphql-tag
I’m looking for someone smarter than me that understand how to actually use it.

Say I have a GraphQL query document like so:

const query = gql`
  {
    user(id: 5) {
      ...User_user
    }
  }
  ${userFragment}
`

How do I get now the string to add in the http body request?
I end up with an object, which allows me to do some introspection and manipulations, great, but how to get the actual body string for the server request?

I’m missing something obvious I guess…

Deleting a user is returning nothing in the backend

I’m trying to delete an user, but the req.body in the backend is an empty object.

In the backend I have the following code:

const deleteUser = async (req, res) => {
  console.log(req.body);
  console.log(req.config);
  const user = await User.findById(req.body.userId);
  if (user) {
    const deleteUser = await user.remove();
    res.send({ message: "User Deleted", user: deleteUser });
  } else {
    res.status(404).send({ message: "User Not Found" });
  }
};

Here the console log is an empty object, I must that the other functions work perfectly.

In the frontend, I’m using redux, I think I’m doing something wrong in the actions, but I can’t find out what, I will post all my code for reference.

action.js:

export const deleteUser = (userId) => async (dispatch, getState) => {
  dispatch({ type: USER_DELETE_REQUEST, payload: userId });
  try {
    const { data } = await Axios.delete(
      "http://localhost:3030/v1/user/userProfile/deleteUser",
      {
        userId: userId,
      }
    );
    dispatch({ type: USER_DELETE_SUCCESS, payload: data });
  } catch (error) {
    const message =
      error.response && error.response.data.message
        ? error.response.data.message
        : error.message;
    dispatch({ type: USER_DELETE_FAIL, payload: message });
  }
};

In the reducer:

export const userDeleteReducer = (state = {}, action) => {
switch (action.type) {
case USER_DELETE_REQUEST:
return { loading: true };
case USER_DELETE_SUCCESS:
return { loading: false, success: true };
case USER_DELETE_FAIL:
return { loading: false, error: action.payload };
default:
return state;
}
};

And I’m calling the action like that:

const userSignin = useSelector((state) => state.userSignin);
const { userInfo, loading, error } = userSignin;

<button
              onClick={() => {
                console.log(userInfo._id);
                dispatch(deleteUser(userInfo._id));
                props.onClose();
              }}
              className='deleteAccountModalButton'
            >
              Delete account!
            </button>

I tried everything, but I can’t find where the problem, can somebody tell me why the req.body is empty in the backend?

optimize/simplify two functions (changeLetterNumber and registerMovements) with javascript

we are developing a chess game with javascript and I have been told to reduce/optimize/simplify the two functions that record the movements of the pieces (they are the two below), that is, reduce the lines of code as much as possible.
Everything works fine, all the pieces move, kill…
He creado también una tabla HTML que registra estos movimentos, movimiento realizado de cada pieza hecho por el usuario.
Thanks

function changeLetterNumber(box){
var row = box.substring(1,3);
var col = box.substring(0,1);
switch(col){
    case "1":
        return "a"+row;
    case "2":
        return "b"+row;
    case "3":
        return "c"+row;
    case "4":
        return "d"+row;
    case "5":
        return "e"+row;
    case "6":
        return "f"+row;
    case "7":
        return "g"+row;
    case "8":
        return "h"+row;
}
registerMovements(box);
}

function registerMovements(box1,box2){
  let piece = document.getElementById(box1).innerHTML;
  let piece2 = document.getElementById(box2).innerHTML;
  let col = columna(box1);
  let row2 = box1.substring(1,3);
  let kill="";
  if(document.getElementById(box2).textContent!="" && 
  document.getElementById(box2).textContent!="·") {//es kill
    kill=changeLetterNumber(box1)+" x "+piece2;
  }
  switch (document.getElementById(box1).textContent) { 
  //"♙""♖""♗""♘""♕""♔"/"♟""♜""♝""♞""♛""♚"
    case "♙":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerWhiteMovement").innerHTML += row;
        break;

    case "♖":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerWhiteMovement").innerHTML += row;
        break;

    case "♗":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerWhiteMovement").innerHTML += row;
        break;

    case "♘":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerWhiteMovement").innerHTML += row;
        break;

    case "♕":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerWhiteMovement").innerHTML += row;
        break;

    case "♔":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerWhiteMovement").innerHTML += row;
        break;

    case "♟":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerBlackMovement").innerHTML += row;
        break;

    case "♜":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerBlackMovement").innerHTML += row;
        break;

    case "♝":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerBlackMovement").innerHTML += row;
        break;

    case "♞":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerBlackMovement").innerHTML += row;
        break;

    case "♛":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerBlackMovement").innerHTML += row;
        break;

    case "♚":
        var row = "<tr><td>"+piece+kill+changeLetterNumber(box2)+"</td></tr>";
        document.getElementById("registerBlackMovement").innerHTML += row;
        break;
    }
    }


    HTML
    <table border="1" id="register">
     <tr>
       <th colspan="4"><h1>Movements</h1></th>
     </tr>
     <tr>
       <td colspan="2" id="registerWhiteMovement">Blanc<br></td>
       <td colspan="2" id="registerBlackMovement">Negre<br></td>
     </tr>
   </table>

Why is my firebase login showing on a different page in reactjs

I have a login page using firebase and I can log in and out successfully. What I want to do is to add a redirect. So, when the user logs in they are taken to another tab. Currently, it opens another tab with the correct path but instead of loading the correct content, it loads the login page. See images…

enter image description here

redirect
enter image description here

This is the code I am using

const login = async () => {
  try {
const existingUser = await signInWithEmailAndPassword(auth, LoginEmail, LoginPassword, browserSessionPersistence,)
console.log(existingUser);

window.open('./Test')
}catch (err){
  if (err) {
    console.log(err);
  }
}
}

Am I missing something?

what is wrong with this code drag and drop in html

<!DOCTYPE html>
<html>
    <head>
        <title>My Web Page</title>
         <script>
            function dragstart(ev){
               ev.dataTransfer.setData("Text",ev.target.id);
            }
            function dragfinish(ev){
             ev.preventDefault();   
            }
            function dropstart(ev){
                var data = ev.dataTransfer.getData("Text");
                ev.target.appendChild(document.getElementById(data));
                ev.preventDefault();
            }
        </script>
    </head>
    <body>
    <p text-style="center"> I started to work on drag and drop</p>
<div style="width:400px;height:380px; border:2px; border-style:solid;"   id="div1" ondrop="dropstrat(event)" ondragover="dragfinish(event)"></div>  
<div style="height:300></div>
    <img id="pic1  src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTAqB_HEXzRtgLQiHn71I1-ph0cAhoiBXkMwA&usqp=CAU" width="355" height="355" draggable="true" ondragstart="dragstart(event)">
    </body>

I tried this code but have no idea what is wrong with it?
can anyone help me!
I wonder whether the problems roots in my web browser, upper case or lowercase, or I don’t know maybe a semicolon can make problem?

Is there a way to parse a string that points to computed properties in Vue as code?

I hope something like this hasn’t been asked before. I have searched and can’t find an answer. I’ve created a Vue 2 app that takes props from a JSON file created with ArchieML.

I want to find out if it is possible to take a prop, that comes as a string, and run it as code? The complication comes as the string is actually a template literal that contains the names of computed properties that are calculated within the Vue component I’m passing the string into.

As an illustration, the following template literal is passed as a string as a prop to the Vue component. Please note this doesn’t get passed to the component as a template literal but as a string.

`Revenue has increased by ${ amount } compared with last year`

Then, I have the following computed property in the component:

amount() {
   return this.thisYear - this.lastYear
}

The amount value needs to be computed in the component and the text for the template literal has to come as a prop in the form of a string. Is there a way to parse the text as code so that it picks up computed properties created in the component?

I’d appreciate any help!

Adding users with role to thread channel using discord.js

I want to add users with specific role to threads. My code is:

    bot.on('message', async message => {
  if (message.content == '?threadref') {    
    let list = message.guild.roles.cache.get('948258030192058410').members.map(m=>m.user.id);
    for (var i = 1; i < list.length; i++) {
      const user = list[i-1];
      const thread1 = channel.threads.cache.find(x => x.id === '945763756728787006');
      const thread2 = channel.threads.cache.find(x => x.id === '947100498035638283');
      const thread3 = channel.threads.cache.find(x => x.id === '947100722321846272');
      const thread4 = channel.threads.cache.find(x => x.id === '945763910756204585');
      const thread5 = channel.threads.cache.find(x => x.id === '946785089486987305');
      const thread6 = channel.threads.cache.find(x => x.id === '946784996537012254');
      const thread7 = channel.threads.cache.find(x => x.id === '946784810981023754');
      
      await thread1.members.add(user);
      await thread2.members.add(user);
      await thread3.members.add(user);
      await thread4.members.add(user);
      await thread5.members.add(user);
      await thread6.members.add(user);
      await thread7.members.add(user);
      console.log(`${user} was added to threads`);
    }
  }
});

But when i try to use this code i get error:

(node:453) UnhandledPromiseRejectionWarning: ReferenceError: channel is not defined
(node:453) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:453) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Can someone tell how get channel variable.
I get code from https://discordjs.guide/popular-topics/threads.html#adding-and-removing-members and there i can’t find what channel mean.

PouchDB get document returns undefined

The pouchDB get document is returning an undefined value

function getVal(db, id) {
    if (db == "lvldb") {
        lvldb.get(db.toString()).then(function (doc) {
            if (id == null) {
                return doc;
            } else {
                return doc[id];
            }
        });
    }
}

There is no error but when I view what the function returns it says undefined

useNavigate() used in Router and still displaying error

The error displayed:

useNavigate() may be used only in the context of a <Router> component.

I’am just starting a new react project and doing basic routing however an error is cause by the use of useNavigate, I used to the same many times and I don’t know what I’m missing:

App.js:

import {BrowserRouter, Route, Routes} from "react-router-dom";
function App() {
  return (
        <BrowserRouter>
            <Routes>
                <Route path='/' element={<Login/>} exact/>
                <Route path={"/chat/:room"} element={<Chat/>} socket={socket} exact/>
            </Routes>
        </BrowserRouter>
  );
}

Login.js:

function Login() {
    const navigate = useNavigate()
    const [error, setError] = useState("")
    const validationSchema = yup.object({
        username: yup.string("username must be a string").required("username is required"),
        password: yup.string("password must be a string").required("password is required")
    })
    const onSubmit = async () => {
        const user = {
            username: formik.values.username,
            password: formik.values.password
        }
        const res = await api.post('/login', formik.values)
        if (res === true){
            localStorage.setItem('user', JSON.stringify(user));
            navigate("chat/1");
        }
        else
            setError("username or password incorrect");
    }
    const formik = useFormik({
        initialValues: {
            username: '',
            password: ''
        },
        onSubmit,
        validationSchema
    })

   ...
}

laravel 8 logout confirmation message how to do it?

I have a logout button in my navber.blade.php

<a class="dropdown-item" id="logout" href="{{ route('admin.logout') }}">
    {{ __('Logout') }}
</a>

I want that when I click the logout button it will show me a confirmation message that you want to logout yes or no? how to do this with jquery of javascript?