How can i make my magnifying glass show a search bar when clicked REACT

Im trying to get my magnifying glass image to show the search bar when clicked and display bottom left of magnifying glass image itself. I cant seem to figure this out. I would like the magnifying glass to be in the search bar. Also the magnifying image should only show when screen width is 425. Which is what the screen.width is. Thank you

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

import React from "react";
import axios from "axios";
import { Link } from "react-router-dom";
import TopButton from "./TopButton";
import FavButton from "./FavButton";
import Footer from "./Footer";
import warrior from "../images/amazon.png";
import amazonJSON from "../amazon.json";
import useWindowSize from "./WindowSize";
import glass from "../images/glass.png";

const Games = () => {
  const [games, setGames] = React.useState([]);
  const [search, setsearch] = React.useState("");

  const options = {
    method: "GET",
    url: `https://free-to-play-games-database.p.rapidapi.com/api/games`,
    headers: {
      "X-RapidAPI-Key": process.env.REACT_APP_GAME_API,
      "X-RapidAPI-Host": "free-to-play-games-database.p.rapidapi.com",
    },
  };

  const getGames = async () => {
    let response = await axios.request(options);
    // console.log(response.data);
    setGames(response.data);
  };

  let isFav = JSON.parse(localStorage.getItem("Favorites"));

  React.useEffect(function () {
    getGames();
  }, []);

  const searchGame = (event) => {
    setsearch(event.target.value);
  };

  const size = useWindowSize();

  return (
    <div>
      <div className="main-games">
       
        {!size.width <= 425 && size.width >= 426 && (
          <input
            className="search"
            type="text"
            value={search}
            onChange={searchGame}
            placeholder="Search game or genre here..."
          />
        )}
        <img src={glass} alt="search" onClick={searchGame} />

        {games
          .filter((item) => {
            const searchTerm = search.toLowerCase();
            const title = item.title.toLowerCase();
            const genre = item.genre.toLowerCase();

            return (
              !searchTerm ||
              title.startsWith(searchTerm) ||
              genre.startsWith(searchTerm)
            );
          })
          .map(function (game) {
            return (
              <div className="main-games-layout">
                <Link key={game.id} to={`/games/${game.id}`}>
                  <img src={game.thumbnail} alt="game picture" />
                  <br />
                  <h3>{game.title.toUpperCase()}</h3>
                  <br />
                  <p className="main-games-desc">{game.short_description}</p>
                </Link>
                <FavButton
                  isFav={
                    isFav &&
                    isFav.some(function (heart) {
                      return heart.title === game.title;
                    })
                  }
                  game={game}
                />
              </div>
            );
          })}
        <TopButton />
        <div className="main-games-amazon">
          <Link to="/amazon">
            <img height="200" src={warrior} />
            <h3>{amazonJSON.title} </h3>
            {amazonJSON.short_description}
          </Link>
        </div>
      </div>
      <Footer />
    </div>
  );
};

export default Games;

How to append the code to the textnode in Javascript(JS, Bootstrap)

I have a full code here: Codepen link.

 //Making legend
    legend = document.getElementById('legend');
//data, labels and colors
    datasets = [
    {
        "label": "# des personnes avec des ages entre 40-85+ ans en 2016",
        "data": [
            9545,
            8855,
            8610,
            7775,
            6850,
            6245,
            4800,
            3715,
            3065,
            3700
        ],
        "backgroundColor": [
            "rgba(255, 99, 132, 0.2)"
        ],
        "borderColor": [
            "rgba(255, 99, 132, 0.5)"
        ],
        "pointBackgroundColor": [
            "rgba(255, 99, 132)"
        ],
        "borderWidth": 1
    },
    {
        "label": "# des personnes avec des ages entre 40-85+ ans en 2011",
        "data": [
            9730,
            9445,
            8440,
            7565,
            6980,
            5355,
            4260,
            3685,
            3170,
            3385
        ],
        "backgroundColor": [
            "rgba(54, 162, 235, 0.2)"
        ],
        "borderColor": [
            "rgba(54, 162, 235, 0.5)"
        ],
        "pointBackgroundColor": [
            "rgba(54, 162, 235)"
        ],
        "borderWidth": 1
    },
    {
        "label": "# des personnes avec des ages entre 40-85+ ans en 2006",
        "data": [
            10300,
            9350,
            8600,
            7890,
            6170,
            4910,
            4485,
            4095,
            3495,
            3245
        ],
        "backgroundColor": [
            "rgba(255, 206, 86, 0.2)"
        ],
        "borderColor": [
            "rgba(255, 206, 86, 0.5)"
        ],
        "pointBackgroundColor": [
            "rgba(255, 206, 86)"
        ],
        "borderWidth": 1
    },
    {
        "label": "# des personnes avec des ages entre 40-85+ ans en 2001",
        "data": [
            10315,
            9470,
            8660,
            6795,
            5680,
            5030,
            4980,
            4495,
            3325,
            3565
        ],
        "backgroundColor": [
            "rgba(75, 192, 192, 0.2)"
        ],
        "borderColor": [
            "rgba(75, 192, 192, 0.5)"
        ],
        "pointBackgroundColor": [
            "rgba(75, 192, 192)"
        ],
        "borderWidth": 1
    }
    
]
    agelabels = [
    "40 à 44 ans",
    "45 à 49 ans",
    "50 à 54 ans",
    "55 à 59 ans",
    "60 à 64 ans",
    "65 à 69 ans",
    "70 à 74 ans",
    "75 à 79 ans",
    "80 à 85 ans",
    "85 ans et plus"
]
//appending bootstrap card-group to the legend element
    const cardGroup = document.createElement('DIV');
    cardGroup.classList.add('card-group');
    legend.appendChild(cardGroup);

    //first loop which shows the datasets labels along with colored circles
    for (let i = 0; i < datasets.length; i++) {
        //creating the color circles
        let legendbg = datasets[i].backgroundColor;
        let legendborder = datasets[i].borderColor;
        const lp = document.createElement('P');
        const lcircle = document.createElement('SPAN');
        const card = document.createElement('DIV');
        const cardBody = document.createElement('DIV');
        card.classList.add('card');
        cardBody.classList.add('card-body');
        lcircle.classList.add('lcircle');
        lcircle.style.backgroundColor = legendbg;
        lcircle.style.borderColor = legendborder;

        //creating the text which is applied to the circle
        let datasetLabel = datasets[i].label;
        const ltext = document.createElement('SPAN');
        ltextnode = document.createTextNode(datasetLabel);
        ltext.classList.add('ltext');
      
        //appending circles with year labels to the card in the legend
        legend.getElementsByClassName("card-group")[0].appendChild(card);
        card.appendChild(cardBody);
        cardBody.appendChild(lp);        
        lp.appendChild(lcircle);
        lp.appendChild(ltext);
        ltext.appendChild(ltextnode);
      
      //Appending age labels and their data from datasets
      //I dont know how to append this code to the card so it shows it after the year labels
        for (let y = 0; y < agelabels.length; y++) {
            const lp = document.createElement('P');
            const ltext = document.createElement('SPAN');
            ltextnode = document.createTextNode(`${agelabels[y]} : ${datasets[i].data[y]}`);
            ltext.classList.add('ltext');
            legend.appendChild(lp);
            lp.appendChild(ltext);
            ltext.appendChild(ltextnode);
        }
    }

I have some data in objects and an array of labels. What I am trying to do is to show in my legend my year labels with their data and the data labels together as bootstrap cards which will flex throughout the page. My problem now is to append data and their labels from the 2nd for loop to the year labels which are in the card group. Thank you in advance!

Uses createRoot in react but still got the depreciation warning about ReactDOM.render

I recently switch to react 18 and also find out that reactDOM.render is depreciated.
I change accordingly and now My index.js is looked like

import React from "react";
import { createRoot } from "react-dom/client";
import "./index.css";
import { ChakraProvider } from "@chakra-ui/react";
import App from "./App";

const root = createRoot(document.getElementById("root"));
root.render(
  <React.StrictMode>
    <ChakraProvider>
      <App />
    </ChakraProvider>
  </React.StrictMode>
);

And the react app is working fine but this error is generated to console every time my app is re-rendered.

Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it’s running React 17.

But It’s kinda annoy me if anyone knows the solution then please help.

Thank you

How to add SVG image icon in dropdown list?

I am trying to add some SVG image icons to my dropdown list, I tried a few different approaches but none of them seems to be working.

  <select class="form-control" data-bind="value: selectedAppointmentStatus">
            <option class="status-list" value="1" style="color: #3EA47B; background-image: url(icons/confirmed-icon.svg) ">Confirmed</option>
            <option class="status-list" value="2" style="color: #FF0000; background-image: url(icons/reschedule-icon.svg)">Reschedule</option>
            <option class="status-list" value="3" style="color: #FFA927; background-image: url(icons/pending-icon.svg) ">Pending</option>
            <option class="status-list" value="0" style="color: #3EA47B; background-image: url(icons/notconfirmed-icon.svg) ">Not opted-in</option>
        </select>

Below is the design mockup I would like to achieve

enter image description here

I have saved these SVG icons in wwwroot -> icons folder

“something” validation failed : array.0: cast to [ObjectId] failed for value | React Node js

This is my Model

isbn: {type: String, required: true},
titre: {type: String, required: true},
annedition: {type: Number, required: true},
prix: {type: Number, required: true},
qtestock: {type: Number, required: true},
couverture: {type: String, required: true},
specialite: {type: mongoose.Schema.Types.ObjectId,ref:Specialite, required: true},
maised: {type: mongoose.Schema.Types.ObjectId,ref:editeurs, required: true},
auteurs: [{type: mongoose.Schema.Types.ObjectId,ref:Auteur, required: true}],

the auteurs field is an array of ObjectId.
this is the state i am facing an error with.

const [auteurs, setAuteurs] = useState([]);

i pushed 2 values in the state auteurs with this method and console logged them it works fine

const handleChange = async (event) => {
setAuteurs((state) => [...state, event.target.value]);};

but when i send the data to the API the Error 409 Conflict appears.
this what i get in the console
Error Message

Problem with conditional rendering with React

I don’t really have an error but I’m not getting the desired outcome. I have a Flask API as my backend. It returns JSON data, this data is then passed to the React frontend to be displayed after certain actions such as a button click.

The Flask backend is working fine, the data is being sent to the React frontend and I can use console.log(data) to see it in the console.

The issue is I tried doing something to make it so that while the data is being fetched from the API, I want a message such as “Loading…” to be displayed.

Here’s what I did in that regard.

  const [data, setData] = useState([{}])

  useEffect(() =>{
    fetch("/details").then(
      res => res.json()
    ).then(
      data => {
        setData(data)
        console.log(data)
      }
    )
  }, [])

That console.log(data) does show my the JSON response in the console.

Then I do this for the display.

  return (
    <div>
    ...
      <div>
      {(typeof data.members === 'undefined') ? (
        <p>Loading...</p>
      ) : (
        data.members.map((member, i) => (
          <p key={i}>{member}</p>
        ))
      )}
    </div>
    </div>
  );

This is supposed to display “Loading…” while the data is being fetched and then display the data. But it keeps displaying “Loading…” even though my data was fetched and it’s never displayed.

Merging 2 CJSON object

Hi I have 2 CJSON objects

CJSON *a = cJSON_GetObjectItem(root,”inputs”);
CJSON *b = cJSON_GetObjectItem(root,”outputs”)

Is there a way I can create a third cJSON object c that can contain both the items of a and b.
I.e my c should ideally be a+b.
Any help is appreciated

change text value when checkboxes changed with array or any way

i have 3 checkboxes and a Text as Title
I want to do this: add spans text inside label to Title
for Example :
if 3 checked => invoice 1,invoice 2,invoice 3
i want return only item is checked

<div class="m-0">
                                                <a href="#" id="get-doctype-box" class="btn btn-sm btn-flex bg-body btn-color-gray-700 btn-active-color-primary fw-bold doc-type-box" data-kt-menu-trigger="click" data-kt-menu-placement="bottom-start">
                                                    <span class="me-1 fw-semibold" id="get-doc-type">Documentenart</span>
                                                    <span class="svg-icon svg-icon-6 svg-icon-muted" >
                                                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-down" viewBox="0 0 16 16">
                                                                <path fill-rule="evenodd" d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/>
                                                            </svg>
                                                    </span>
                                                </a>
                                                <div class="menu menu-sub menu-sub-dropdown w-150px" data-kt-menu="true" id="doc_type_menu">
                                                    <div class="px-6 py-4 doctype-area" id="doctype-area">

                                                            <div class="my-3">
                                                                <label class="form-check form-check-sm form-check-custom form-check-solid me-5">
                                                                    <input class="form-check-input doc-check" type="checkbox" value="1" id="invoice-check" data-toggle="checkbox">
                                                                    <span class="form-check-label">Rechnung</span>
                                                                </label>
                                                            </div>

                                                            <div class="my-3">
                                                                <label class="form-check form-check-sm form-check-custom form-check-solid me-5">
                                                                    <input class="form-check-input doc-check" type="checkbox" value="1" id="shipping-check" data-toggle="checkbox">
                                                                    <span class="form-check-label">Lieferschein</span>
                                                                </label>
                                                            </div>

                                                            <div class="my-3">
                                                                <label class="form-check form-check-sm form-check-custom form-check-solid me-5">
                                                                    <input class="form-check-input doc-check" type="checkbox" value="1" id="order-d-check" data-toggle="checkbox">
                                                                    <span class="form-check-label">Ordersatz</span>
                                                                </label>
                                                            </div>

                                                    </div>
                                                </div>
                                            </div>

How selenium replaces JavaScript files of web pages

I am using the selenium automated testing tool of Python to write a program that can replace JavaScript files of web pages.

But I don’t know how selenium can replace the JavaScript file in the web page with the JavaScript file created by itself. Just like the “route()” method of playwright, it can replace a JavaScript file in the web page with the JavaScript file created by itself. How can selenium realize this function?

Thank you for your advice, I will be grateful!

How can I modify the ban command in converse.js package

I am trying to modify the ban command, I don’t see any documentation for banning the users from chatroom, I need to type /ban(userName,the reason), what I am trying to do is if I click on the user icon then I can be able to ban the user by just clicking. Is there any suggestion on how can I do this?

Fabric.js works only inside the function

I have a function

function createCanvas() {
  
  const canvas = new fabric.Canvas('canvas');
  var rect = new fabric.Rect({
  left: 100,
  top: 100,
  fill: 'red',
  width: 20,
  height: 20
  });
  
  const text = new fabric.IText('sample', {
  left: 250,
  top: 250,
  textAlign: 'left'

  });

  canvas.add(rect);
  canvas.add(text);
  canvas.setBackgroundImage('./img.png');

  let batton = document.getElementById('baton');
  batton.remove();
  return canvas;
  }

I want to make the const canvas = new fabric.Canvas('canvas'); global, but the console in browser says that ReferenceError: Can't find variable: fabric and it works only inside the function

What should I do to make that const global?

How to show chat left and right

i am new in react native and making chat with async storage now i have data but i am trouble with that how to set condition for showing data accordingly receiver and sender and how to move messages left and right side, please help

Proper way to close responsive navbar menu on click of link (in same page)

So, I have a navbar with a (burger icon animation on mobile view) and when I click a link I want the navbar to close & the burger icon cross animation to reverse to normal.

NOTE: This already worked on my previous builds. But since this is a one pager and the link goes out to a section of my page it does not automaticly refresh the page. (Like in my previous projects). I want to do it in vanilla js (so no JQuery).

NOTE2 : This will mainly be a JS problem, but I added the css of the nav just in case.

Thanks in advance

My html code :

<nav id="navbar" class="c-nav">
    <div class="logo">
      <a href="index.html">
        <img class="logo_size" src="./images/Dumotech1.png" alt="Logo van Minter">
      </a>
    </div>

    <ul class="nav-links">
      <li><a class="c-underline" href="#about">Over ons</a></li>
      <li><a class="c-underline" href="#services">Diensten</a></li>
      <li><a class="c-underline" href="#projects">Projecten</a></li>
      <li><a class="c-underline" href="#contact">Contact</a></li>

    </ul>

    <div class="burger">
      <div class="line1"></div>
      <div class="line2"></div>
      <div class="line3"></div>
    </div>

  </nav>

Css :

.c-nav {
    /* overflow-x: hidden; */
    text-transform: uppercase;
    position: fixed;
    z-index: 4;
    top: 0;
    width: 100%;
    height: 5rem;
    display: flex;
    justify-content: space-around;
    align-items: center;
    vertical-align: middle;
    min-height: 8vh;
    background-color: rgb(0, 0, 0);
    font-family: 'Raleway', sans-serif;
}

#navbar {
    background-color:rgb(0, 0, 0);
    position: fixed; 
    top: 0; 
    width: 100%;
    transition: top 0.5s ease;
  }

.logo_size {
    max-width: 16rem;
    max-height: auto;
}

.nav-links {
    display: flex;
    justify-content: space-around;
    width: 20%;
}

.nav-links li {
    list-style: none;
}

.nav-links a {
    position: relative;
    top: 0.5rem;
    color: rgb(255, 255, 255);
    font-family: 'Raleway', sans-serif;
    text-decoration: none;
    letter-spacing: 3px;
    font-weight: regular;
    font-size: 14px;
    padding: 0 1px;
    display: inline-block;
}

.c-underline::after {
    background: none repeat scroll 0 0 transparent;
    bottom: -3px;
    content: "";
    display: inline-block;
    height: 2px;
    left: 50%;
    position: absolute;
    background: rgb(194, 12, 12);
    transition: width 0.3s ease 0s, left 0.3s ease 0s;
    width: 0;
}

.c-underline:hover::after {
    display: inline-block;
    width: 100%;
    left: 0;
}

.nav-links a:hover {
    color: rgb(194, 12, 12);
    text-decoration: none;
}

.burger {
    display: none;
}

.burger div {
    width: 35px;
    height: 4px;
    background-color: rgb(255, 255, 255);
    margin: 8px;
    transition: all 0.3s ease;
}

@media screen and (max-width: 1024px) {
    .nav-links a {
        position: relative;
        top: 0;
    }
}

@media screen and (max-width: 780px) {
    .nav-links {
        width: 60%;
    }
}

@media screen and (max-width: 1024px) {
    .nav-links {
        width: 60%;
    }
}

@media screen and (max-width: 1920px) {
    .nav-links {
        width: 40%;
    }
}

@media screen and (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    .nav-links {
        position: fixed;
        right: 0px;
        height: 92vh;
        top: 8vh;
        background-color: rgb(0, 0, 0);
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 50%;
        transform: translateX(100%);
        transition: transform 0.5s ease-in;
    }

    .nav-links li {
        opacity: 0;
    }

    .burger {
        display: block;
        cursor: pointer;
    }
}

.nav-active {
    transform: translateX(0%);
}

@keyframes navLinkFade {
    from {
        opacity: 0;
        transform: translateX(50px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

JS :

function navSlide() {
    const burger = document.querySelector(".burger");
    const nav = document.querySelector(".nav-links");
    const navLinks = document.querySelectorAll(".nav-links li");
    
    
    burger.addEventListener("click", () => {
        //Toggle Nav
        nav.classList.toggle("nav-active");

        //Animate Links
        navLinks.forEach((link, index) => {
            if (link.style.animation) {
                link.style.animation = ""
            } else {
                link.style.animation = `navLinkFade 0.5s ease forwards ${index / 7 + 0.3}s`;
            }
        });
        //Burger Animation
        burger.classList.toggle("toggle");
    });
}

createElement and loops [duplicate]

I am trying to find out why createElement or maybe appendChild doesn’t work
Does every createElement have some kind of unique id?

Works – 4 buttons

 const arr = [1, 2, 3, 4];
 const list = document.getElementById('list');
 arr.map(item => {
     const newButton = document.createElement('button');
     newButton.innerHTML = `Button`;
     list.append(newButton)
 });

Doesn’t work – only 1 button
it seems it would work to me…

 const list2 = document.getElementById('list2');
 const newButton2 = document.createElement('button');
 newButton2.innerHTML = `Button2`;

 arr.map(item => {
    list2.append(newButton2);
 });