filter an array within a collection of objects belonging to an array in Ts

I’m trying to filter objects inside an array in order to render them in React with Ts.
I think that when I want to filter I am changing the typing and that gives me an error with typescript, but it allows me to render correctly.
However, I am trying to find out if there is a more efficient way to do this in the code. I want to filter to category genres. The idea is with a query of my path or url compare it with an array of numbers that are ids, each array belongs to a collection of objects within an array.

Something like this would be the API data

results = [
    {id:1, title"spiderman", genre_ids:[14,23,3]},
    {id:2, title:"batman", genre_ids:[14,23,3]},
    {id:3, title:"batman 2", genre_ids:[14,23,3]}
  ]

My code

const df = data?.results.map((item) => {
    const db = item.genre_ids.map(
      (el) => el.toString() === searchParams.get("genre_ids") && item
    );

    return db.filter((el) => el !== false && el);
  });
  if (df === undefined) return;
  const db = df.reduce((acc, el) => acc.concat(el), []);
  console.log(db);

  if (searchParams.get("genre_ids"))
    return (
      <>
        {db.map((item) => (
          <div key={item.id}>
            {toggle ? <ListData item={item} /> : <GridData item={item} />}
          </div>
        ))}
      </>
    );

The error says this the property “id” does not exist on type “false | movieApiResult” is not assignable to type “movieResult”. Type boolean is not assignable to type “movieApiResult”

Using buttons to scroll through a carousel

I have created a carousel where each slide contains different content. Currently, the only way to go to the next item is to click a little button on the bottom of the carousel. I want to add buttons on the side that when clicked, the carousel goes to the next slide. I added the buttons with the id nextBtn and prevBtn, I want the previous/next carousel slide to appear on the screen when the button is pressed. I also want to keep the 3 little buttons on the bottom of the container.see image

Here is my current HTML:

<div class="carousel">
  <div class="carousel__item item-one">
    <div class="carousel-text">
        <h1>Make your business</h1>
        <h1>shine online</h1>
    </div>
  </div>
  <div class="carousel__item item-two">
    <div class="carousel-text">
        <h2>Make your business</h2>
        <h2>shine online</h2>
    </div>
  </div>
  <div class="carousel__item item-three">
      <div class="carousel-text">
        <h2>Make your business</h2>
        <h2>shine online</h2>
    </div>
  </div>
  <button id="prevBtn">prev</button>
  <button id="nextBtn">next</button>
</div>

JavaScript:

document.querySelectorAll(".carousel").forEach((carousel) => {
  const items = carousel.querySelectorAll(".carousel__item");
  const buttonsHtml = Array.from(items, () => {
    return `<span class="carousel__button"></span>`;
  });

  carousel.insertAdjacentHTML(
    "beforeend",
    `
        <div class="carousel__nav">
            ${buttonsHtml.join("")}
        </div>
    `
  );

  const buttons = carousel.querySelectorAll(".carousel__button");

  buttons.forEach((button, i) => {
    button.addEventListener("click", () => {
      // un-select all the items
      items.forEach((item) =>
        item.classList.remove("carousel__item--selected")
      );
      buttons.forEach((button) =>
        button.classList.remove("carousel__button--selected")
      );

      items[i].classList.add("carousel__item--selected");
      button.classList.add("carousel__button--selected");
    });
  });

  // Select the first item on page load
  items[0].classList.add("carousel__item--selected");
  buttons[0].classList.add("carousel__button--selected");
});

How to get a user’s keypair from their public key only (Solana)?

I’m making a dApp and I want to add a button where a user (the one with their wallet connected) can send exactly 0.01 SOL to another user. I already wrote the function in my Rust program and after testing it with anchor test it seems to be working when I use my own personal wallet’s Keypair to sign the transaction. However, now I am writing the event handler function in my web app’s frontend and I’m not sure what to pass for the signers parameter if I want the user to sign the transaction. What do I pass if I don’t know their secret key? Is there a way that I can generate a user’s Keypair from their public key alone or would I need to use the Solana Wallet Adapter for this? Any help would be appreciated. This is my first time working with Solana!

This is the function:

const tipSol = async (receiverAddress) => {
    try {
      const provider = getProvider();
      const program = new Program(idl, programID, provider);

      const lamportsToSend = LAMPORTS_PER_SOL / 100;
      const amount = new anchor.BN(lamportsToSend);
      await program.rpc.sendSol(amount, {
      accounts: {
        from: walletAddress,
        to: receiverAddress,
        systemProgram: SystemProgram.programId,
      },
      signers: ?
     })
     console.log('Successfully sent 0.01 SOL!')
     window.alert(`You successfully tipped ${receiverAddress} 0.01 SOL!`)
    } catch (error) {
      console.error('Failed to send SOL:', error);
      window.alert('Failed to send SOL:', error);
    }
  }

how can i update html elements with javascript same as inspect html google chrome? [closed]

is it possible to update html elements with javascript instantly like inspect html google chrome does? for example if I move a yellow div with drag and drop and then press a button to change the color of the div with style or a css class to black that is changed without refreshing the page and only the element is updated.

What javascript function can I use?

thanks

Vue 3 Firebase Auth get *any* user data by id? [duplicate]

New to vue/firebase. I was able to lookup how to pull up “current user” data from auth no problem but trying to write a js composable that I can pass in any user id (not necessarily current user) and it will return the user object or at least displayName.

All the docs/vids I can find on the topic reference getting info on *current user *only not another user. From the Google Docs it says I should be able to do this in the “Retrieve user data” section. Closest model to Vue code-wise seems to be “Node.Js” but it isn’t working.

Here’s what I’ve got in getUserById

import { getAuth } from 'firebase/auth'

const getUserById = (u) => { // u = user id
    const userData = null
    getAuth()
        .getUser(u)
        .then((userRecord) => {
            // See the UserRecord reference doc for the contents of userRecord.
            console.log(`Successfully fetched user data: ${userRecord.toJSON()}`);
            userData = userRecord
        })
        .catch((error) => {
            console.log('Error fetching user data:', error);
        });

    return { userData }
}
export default getUserById

The error I get is getUser is not a function. I tried adding getUser to the import but same error.

Compares Two Different Strings Characters (JS)

Let’s say I have:

string1 = "abcdefgh"
string2 = "abb" 

I want to compare all the characters in string2 and check they are represented in string1

Examples:

// Example 1
string1 = "abcdefgh"
string2 = "abb" 
// -->TRUE (even though "b" is used twice it checks it twice to make sure")

// Example 2
string1 = "abcdefgh"
string2 = "abz"
// FALSE ("z" is not represented in string1)

// Example 3
string1 = "abcdefgh"
string2 = "ddd"
// TRUE

// Example 4
string1 = "abcdefgh"
string2 = "xyz"
// FALSE

Thank kindly

What would be the best way to create an isAuthor guard for nestjs?

I have been taking online course from udemy and playing around with the guard middleware

I also created the admin.guard auth.guard suggested by following the tutorial but I am thinking what if I want to add an isAuthor.guard that not only the admin can make changes to post or whatever but the original author is also able to make edits…

What would be a better way to create this? Should it be a guard? or middleware would be better?

P.S. I tried accessing services through guard with this post Inject service into guard in Nest.JS but didn’t work for me.

Thanks in advance for any suggestions / advices.

Laravel-admin Delete action in grid view doesn’t work

I’m working on a project, and I have made the decision of working with Laravel-admin to make a admin panel.

When I try to delete a row via grid view action, it occours an error ilustrated in the print below:
Error that occours

_key element is null, and that makes the _model=false

I think its something in the what creates the request, because the _key element comes null, i think that is what is causing the problem.

I have little experience with client side JS and JQuery please help me!

How do I display text from a file on my webpage?

I’m trying to make a webpage that will display the contents of a text file, this file will eventually be stored online when the webpage is hosted, however, right now I am testing the webpage locally with the file being stored in the same directory as the html file. Below is the code I am using but I’m running into the error ” Messages is not defined”

<script type="text/javascript">
        function loadFile(filePath) {
            var result = null;
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open("GET", filePath, false);
            xmlhttp.send();
            if (xmlhttp.status==200) {
                result = xmlhttp.responseText;
            }
            return result;
        }
        document.getElementById("test").textContent = loadFile(Messages.txt);
</script>

String match one or more numbers with a # – Javascript / regex

I am trying to match a part of a string with another string.
In string one I have a larger amount of text that has the desired string within. In string two I have a part of the desired string with the numbers replaced with ‘#’.

How can I match any numbers in the same position of the #?

I am guessing that there would be a regex that does this but I can’t figure it out.

Example

Str1 = "Adds 2 to 5 Cold Damage Adds 20 to 50 Fire Damage Adds 1 to 100 Lightning Damage"    

Str2 = "Adds # to # Fire Damage" 

res = "Adds 20 to 50 Fire Damage"

Javascript replace a capture group to uppercase (not a duplicate)

I am aware of Replace a Regex capture group with uppercase in Javascript

That is for replacing the entire match and not a () match.

Here is my problem:

var text = '<span style="font-variant: small-caps" class="small-caps">Lord</span>'
text = text.replaceAll(/<span style="font-variant.*?>(.*)</span>/g, function (v) { return v.toUpperCase(); });
console.log(text);

This returns the entire tag as uppercase and not the actual text in (.*).

I just want to replace the span tag with just the uppercase of the innertext. There is more than one span tag as well in the actual text variable.

How to mock a module just to call a function

Is it possible to make when someFunction or any inner function that call ReactDom.render use my function instead real implementation?

export const testHelperFunction = (widget, anotherArg) => {
    jest.mock('react-dom', () => {
      return {
      __esModule: true,
      render: console.log,
    }});
    widget.someFunction(anotherArg);
    jest.unmock('react-dom');
};

MongoDB FIND method does not work in code

so when I try to find items in a collection through the console using the method db.DB_NAME.find({ x: y }, it works just fine. However, when trying to do the same in the code, it does not work.

Perhaps it is worthy mentioning that the method findOne works great within the code.

Consulting through the console

Code:

app.get("/api/customer/:cpf", async (req, res) => {
  const properties = await Customer.consult(req);
  console.log(properties);
  res.status(200);
  res.end();
});

static async consult(req) {
    const conn = await client.connect();
    const db = conn.db("website");
    const cpf = req.params.cpf.toString();
    console.log(cpf);
    const properties = await db.collection("Property").find({
      customerCpf: cpf,
    });
    return properties;
  }

What I get from these pieces of code is a huge and weird (for me, a beginner) object in my console instead of the three expected objects.