how to type props for text area react typescript

I have a react component that looks like this:

import { TextareaHTMLAttributes} from 'react'
import styled from 'styled-components'

const TextAreaElement = styled.textarea`
  border-radius: 40px;
  border: none;
  background: white;
`

const TextArea = (props: TextareaHTMLAttributes<any>) => {  <--- replace any here
  return <TextAreaElement {...props} />
}

I know I can do something like this, but would rather not have to add every prop manually:

const TextArea = ({placeholder} : {placeholder: string}) => {
  return <TextAreaElement placeholder={placeholder} />
}

Sortable.js mismatched naming convention to child elements

I’m working on a WordPress website and I want the user to have the ability to reorder the sidebar widgets even if the site reloads.

So I’m using Sortable JS and using the saving and restoring of the sort as I plan to store it in localStorage but I couldn’t make it work. It’s pretty straightforward in the documentation and the demo but for some reason, it’s not working for me and I’m not sure what I’m missing.

Below is the default sorting of the elements.

enter image description here

And once I reorder these widgets, I get this result.

enter image description here

I believe the issue was the naming of the keys is incorrect. See the highlighted text with blue in the image below. It’s missing in the array called from the set method.

enter image description here

So the highlighted with blue here is the log from the get: function (sortable) method and the array output is from the set: function (sortable) .

Here’s a quick video to see it more clearly.

Below is my code.

let el = document.getElementById('sticky-sidebar');

Sortable.create(el, {
    group: 'foo',
    animation: 100,
    draggable: ".widget_block",
    store: {
        /**
                 * Get the order of elements. Called once during initialization.
                 * @param   {Sortable}  sortable
                 * @returns {Array}
                 */
        get: function (sortable) {
        var order = localStorage.getItem(sortable.options.group.name);
        console.log(order)
        return order ? order.split('|') : [];
        },
    
        /**
                 * Save the order of elements. Called onEnd (when the item is dropped).
                 * @param {Sortable}  sortable
                 */
        set: function (sortable) {
        var order = sortable.toArray();
        console.log(order)
        localStorage.setItem(sortable.options.group.name, order.join('|'));
        }
    }
});

How can I pull all values from a Firestore document in React Native?

This is my database and the data I want to pull:

This is my code:

const MatchScreen = ({route}) => {

  const id = route.params.id;
  const booking = getDoc(doc(db, 'bookings', id))
  console.log(booking)

  return (
    <View style = {{justifyContent: 'center', alignItems: 'center'}}>
      <Text>{id}</Text>
  </View>
  )
      }

I got the id value from another page and that one is displayed properly on the screen, but when I try to console log booking to see if the values are there, this is what I get:

Promise {
  "_U": 0,
  "_V": 0,
  "_W": null,
  "_X": null,
}

What am I doing wrong?

“SyntaxError: Cannot use import statement outside a module” error while testing a Nodejs project with Jest

So I’m working on a Nodejs project with expressjs and I’m trying to use Jest to test my apis.
I’ve read about configuring Jest in the documentation, but I’m new to jest and it’s a bit confusing.
The error I’m getting :

    SyntaxError: Cannot use import statement outside a module at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)

My test file:

const userController = require("../controllers/user.controller");
const router = require("../routes/user.routes");


//Testing login route
describe("POST /api/user/login", () => {
    describe("given a username and password", () => {
  
      test("should respond with a 200 status code", async () => {
        const response = await request(router).post("/login").send({
          username: "username",
          password: "password"
        })
        expect(response.statusCode).toBe(200)
      })
     })
  

  
  })

Live Search in PHP using AJAX working, but buttons not in td

my live search in working perfectly, but my tags are not in td. I can’t figure out what is the problem. The picture, and the code are below. Thank you in advance.
The problem is down there in td, the the tags.
how it looks like

enter code here    
<?php

@include('./config/constants.php');
$output = '';

if (isset($_POST['query'])) {
    $search = $_POST['query'];
    $stmt = $conn->prepare("SELECT * FROM clients WHERE full_name LIKE CONCAT('%',?,'%') OR email LIKE  CONCAT('%',?,'%')");
    $stmt->bind_param("ss", $search, $search);
} else {
    $stmt = $conn->prepare("SELECT * FROM clients");
}
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
    $output = "<tr>
                <th>ID</th>
                <th>Full Name</th>
                <th>E-mail</th>
                <th>Phone</th>
                <th>City</th>
                <th>Address</th>
                <th>Actions</th>
            </tr>
            ";
    while ($row = $result->fetch_assoc()) {
        $output .= "<tr>
                        <td>" . $row['id'] . "</td>
                        <td>" . $row['full_name'] . "</td>
                        <td>" . $row['email'] . "</td>
                        <td>" . $row['phone'] . "</td>
                        <td>" . $row['city'] . "</td>
                        <td>" . $row['address'] . "</td>
                        <td>"
?>
        <a href="<?php echo SITEURL; ?>/update-client.php?id=<?php echo $row['id']; ?>" class="main-btn">Update Client</a>
        <a href="<?php echo SITEURL; ?>/delete-client.php?id=<?php echo $row['id']; ?>" class="danger-btn">Delete Client</a>
<?php
        "</td>
                    </tr>";
    }
    echo $output;
} else {
    echo "<h3>No Records found!</h3>";
}

Why is my ngRoute in AngularJS not working

I am learning some AngularJS at school and we were asked to implement routing for our project but I am having some trouble with ngRoute:

Here is my js file (app.js):

var app = angular.module("myApp", ["ngRoute"]);

app.config(function ($routeProvider) {
  $routeProvider
    .when("/", {
      templateUrl: "index.html",
    })
    .when("/jadwal", {
      templateUrl: "showJadwal.html",
      controller: "jadwalController",
    })
    .when("/jadwalUjian", {
      templateUrl: "showJadwalUjian.html",
      controller: "jadwalUjianController",
    });
});

These are the files I have imported in my html:

    <script src="js/angular.js"></script>
    <script src="js/angular-route.js"></script>
    <script src="js/angular.min.js"></script>
    <script src="js/controllers/app.js"></script>

These are the hrefs:

<div id="navbar" class="collapse">
                <ul>
                    <li class="active"><a href="#!/" data-nav-section="home">Home</a></li>
                    <li><a href="#!jadwal">Jadwal</a></li>
                    <li><a href="#!jadwalUjian">Jadwal Ujian</a></li>
                    <li><a href="#" data-nav-section="skills">To Do List</a></li>
                </ul>
            </div>

Plus I have also placed <div ng-view></div>

Any kind of help would be greatly appreciated 🙂

My react component is not showing if I am getting from backend

I am trying to send data as props to my DashboardCard component which isn’t showing. But if I hard code the values and send the props DashboardCard works fine.

data = result?.data?.projects

data:

{
    "success": true,
    "projects": [
        {
            "_id": "62c05cff856b2c153895280f",
            "name": "MERN Stack",
            "description": "This is a project",
            "files": [
                {
                    "id": "projects/bqykwx3kbfjkbkgvbaqu",
                    "secure_url": "https://res.cloudinary.com/blackeyedemon/raw/upload/v1656773886/projects/bqykwx3kbfjkbkgvbaqu",
                    "_id": "62c05cff856b2c1538952810"
                }
            ],
            "category": "MERN",
            "user": "62c0544545c865a21117311b",
            "reviews": [
                {
                    "user": "62c0545445c865a21117311d",
                    "name": "testing",
                    "rating": 5,
                    "comment": "Nice but needs some optimizations in code",
                    "_id": "62c06661643356d458cda9c7"
                }
            ],
            "createdAt": "2022-07-02T14:58:07.285Z",
            "__v": 1
        }
    ]
}

DashboardCard.jsx:

if (loading === true) {
        return (
            <h2>Loading....</h2>
        )
    }
    else {
        return (
            <div>
                <div>
                    <h2>Dashboard</h2>
                    <button onClick={handleLogout}>Logout</button>
                    {data.map((project) => {
                        <DashboardCard
                            avatarName={project.name[0]}
                            title={project.name}
                            createdAtDate={project.createdAt[i]}
                            category={project.category}
                            description={project.description}
                        />;
                    })}
                </div>
            </div>
        );
    }
}

I don’t why this isn’t working? What I am doing wrong here? What changes should I make so that it works fine?

Convert jquery ajax to fetch

does someone knows jquery and can help me convert this ajax to js fetch ?

Unfortunately, I don’t know jquery and I need to convert this into js fetch.

function ajaxLogoutDetailsApi() {
  $.ajax({
    type: "GET",
    url: "OIDCGetLogoutDetails",
    async: false,
    cache: false,
    data: "json",
    success: function (data, status, xhr) {
      data = data.replace('/*', '');
      data = data.replace('*/', '');
      var dataJson = JSON.parse(data);
      if (dataJson.logoutUrl != null) {
        document.location.href = dataJson.logoutUrl;
      }
    },
    error: function (xhr, status, err) {
      console.log("error in ajaxLogoutDetailsApi");
    }
  });
}

req.param.id brings “undefined”

Getting req.param undefined

Hi, I have a similar error to the one above.

server.get('/:file_id', function(req , res) {
  var file_id = req.params.id;
  console.log(file_id);
  gfs.files.find({_id: file_id}).toArray(function (err, files) {
    if (err) {
      res.json(err);
    }
    if (files.length > 0) {
      var mime = files[0].contentType;
      var filename = files[0].filename;
      res.set('Content-Type', mime);
      res.set('Content-Disposition', "inline; filename=" + filename);
      var read_stream = gfs.createReadStream({_id: file_id});
      read_stream.pipe(res);
    } else {
      res.json(file_id+ '  This file does not exist.');
    }
  });
});

Below is a ejs file that gets file_id to server.

<div class="card card-body mb-3">
    <%= file.filename %>
          <form action="/:<%= file._id %>" method="get">
            <input type="submit" value="DOWNLOAD" class="btn btn-primary btn-block">
          </form>
  </div>

What I get from this code is : "undefined This file does not exist."
I think the problem lies on req.params.id but am not sure where to fix.

Thank you.

Javascript if variable value equal to variable value

I have code like this in my website

var created = 10;
var limitacc = 25;
var element = document.querySelector(".progress-bar");

if (created.value === limitacc.value){
element.classList.add("bg-danger");
} else {
element.classList.add("bg-warning");
}

I want to change the bootstrap progress bar bg if created is same value in limitacc but the code is not working its stay in bg-warning even the created to 25

Checkbox clicked style appears for all the checkboxes when i press dropdown option through useState in a different page in React/Next JS

So I have these sets of checkboxes for 3 different categories. 1 is “types”, 1 is “Price” and the other is “Categories”. they work perfectly. I have created a separate checkbox component and data is passed there without any problem.

The problem is when I click the checkbox and data is rendered but when I click the dropdown in the index page once and then press it again the data is the same as expected but the clicked style by that I mean”checked” is applied to all the checkboxes. is there any way to overcome this?

this is the separate checkbox component

import React, { useState } from "react";

interface Props {
  isChecked?: boolean;
  handleClick?: any;
  label: string;
  className?: string;
  labelClassName: string;
  handleChange?: any
}

const Checkbox = ({isChecked,handleClick,label,labelClassName,handleChange}: Props) => {
  const [checking,setChecking]=useState(isChecked)
  return (
    <div>
      <input
        type="checkbox"
        id={label}
        checked={checking}
        onClick={()=>{handleClick();setChecking(!checking)}}
        onChange={handleChange}
        className={`space-x-3 text-gray-400 bg-gray-800 border rounded border-stone-200 $`}
      />
      <label className={labelClassName} htmlFor={label}>{label}</label>
    </div>
  );
};
export default Checkbox;

Main Index Page

// these states are for dropdown/dropup styling
const [categoryOpts, setCategoryOpts]= useState(true);
const [typeOpts, setTypeOpts]= useState(true);
const [priceOpts, setPriceOpts]= useState(true);

 const [checking,setChecking]=useState(false)
    const handleCheckChange=()=>{
        setChecking(!checking)
    }
index (){
<div>
// this is for showing/hiding price option
<div className='flex justify-between cursor-pointer' onClick={()=>setPriceOpts(!priceOpts)}>
<Text as='h5' tag='h2'>
Price
</Text>
{priceOpts?
<dropdown icon up/>
</svg> :
<dropdown icon down>
</svg>
}
</div>
// price option mapping that comes from api source.
{ priceOpts? 
<div className='flex flex-col gap-2'>
{checkboxes.map(({ label, onClick, key }) => 
<div key={key}>
<Checkbox 
labelClassName='text-sm text-gray-400 ml-3'
label={label}
handleClick={onClick}
isChecked={checking}
handleChange={handleCheckChange}
/>
</div>
)}                    
</div>: ''
}
</div>
}