React Responsive Design Issue with Fixed Positioning

I’m currently facing an issue with a React application I’m working on. I’ve built a website using React where I have a component called CartMenu which is used within another component called Products.

The problem arises when using the developer tools in my browser and selecting a screen with ‘Dimensions: responsive’. I can see a button in the page (https://i.stack.imgur.com/OGlta.png), but when I use the resolution of devices like iPhone, Samsung, or iPad, the bottom part of the screen is not visible (https://i.stack.imgur.com/a25gg.jpg).

  return (
    <div className=''>
        <div className={`absolute ${!props.isCartDisplayed ? "hidden" : "flex flex-col"} bg-black bg-opacity-70 w-full top-0 left-0 bottom-[-200px] z-9`}
             onClick={props.toggleCart}
        > 
        </div>
        <div className={`absolute ${!props.isCartDisplayed ? "hidden" : "flex flex-col"} flex justify-between h-[100vh] bg-white w-[90%] sm:w-[70%] top-0 right-0 bottom-0 z-10 overflow-hidden`}>
  <div className="border-b-2">
    <div className="flex justify-between items-center mb-2 mt-4">
      <div>
        {props.totalCartProducts > 0 ? (
          <h2 className="text-xl font-bold mx-5">
            Carrito de compras ({props.totalCartProducts}{" "}
            {props.totalCartProducts > 1 ? "productos" : "producto"})
          </h2>
        ) : (
          <h2 className="text-xl font-bold mx-5">Carrito de compras</h2>
        )}
      </div>
      <div className="flex justify-end">
        <img
          src={close}
          onClick={props.toggleCart}
          className="w-10 h-10 mx-5 object-contain cursor-pointer"
          alt="Close"
        />
      </div>
    </div>
  </div>
  <div className="flex flex-col flex-grow overflow-y-auto">
    {cartProductElements}
  </div>
  <div className={`${props.totalCartProducts ? "" : "hidden"} border-t-2 mb-auto`}>
    <div className="flex flex-col sm:flex-row gap-2 sm:gap-0 sm:items-center px-5 my-2 justify-between">
      <h3 className="text-lg font-semibold">Total: ${total.toFixed(2)}</h3>
      <button className="flex justify-center items-center gap-2 px-4 pt-3 pb-2 bg-[#25D366] font-semibold rounded-lg text-sm hover:bg-[#128C7E]" onClick={checkout}>
        Continuar compra por WhatsApp
        <img src={whatsapp} alt='whatsappLogo' className='h-5 w-5 mb-1'></img>
      </button>
    </div>
  </div>
</div>

    </div>
  )

This code is the return statement of the CartMenu component, which is utilized by the Products component. The latter component, when the CartMenu is displayed, makes the page fixed because I don’t want it to be scrollable below the shopping cart menu (https://i.stack.imgur.com/OjLKm.png).

However, on mobile devices, when the page is fixed, the browser takes up more space than it does on a scrollable page. As a result, this part of the browser UI covers the button at the bottom of the screen. I’ve tried adjusting various CSS properties and using media queries, but I’m still encountering this issue.

Could anyone please provide some guidance on how to resolve this problem? Any help or suggestions would be greatly appreciated.

Thank you!

How can i create a tweet directly from a button with JavaScript?

I am creating a random quote generator following along with a tutorial found at this link: https://www.youtube.com/watch?v=pbWHp63-V3c&t=2465s

In the video around the 40 minute mark he adds the functionality to create a tweet with the quote auto-populated into the input of the tweet. I know twitter has went through some changes in the transition to X and this does not seem to be working for me. Here is my code I have written so far:

    <script>
      const QUOTEBANK = [
        {
          quote: "We suffer more often in imagination than in reality.",
          author: "Seneca",
        },
        {
          quote:
            "You're the air I breathe. You're EVERYTHING to me. I wish you could see yourself through my eyes...",
          author: "Clara Dobbins",
        },
        {
          quote:
            "Accept the things to which fate binds you, and love the people with whom fate brings you together, but do so with all your heart",
          author: "Marcus Aurelius",
        },
        {
          quote: "He has the most who is most content with the least.",
          author: "Diogenes",
        },
        {
          quote:
            "For a man to conquer himself is the first and noblest of all victories",
          author: "Plato",
        },
        {
          quote:
            "It's not what happens to you, but how you react to it that matters.",
          author: "Epictetus",
        },
        {
          quote: "The goal of life is living in agreement with Nature",
          author: "Zeno of Citium",
        },
      ];
      window.onload = init;
      function init() {}

      function generateQuote() {
        let quoteSize = QUOTEBANK.length;
        let randomIndex = Math.floor(Math.random() * quoteSize);
        let randomQuoteData = QUOTEBANK[randomIndex];

        let twitterLink =
          "https://twitter.com/intent/tweet?hashtags=quotes&amp;related=freecodecamp&amp;text=%22";

        //Add the quote
        let quoteInApiFormat = randomQuoteData.quote.replace(/ /g, "%20");
        twitterLink += quoteInApiFormat;
        //Add the author
        let authorInApiFormat = randomQuoteData.author.replace(/ /g, "%20");

        twitterLink += authorInApiFormat;

        document.getElementById("tweet-quote").href = twitterLink;
        document.getElementById("text").innerText = randomQuoteData.quote;
        document.getElementById("author").innerText = randomQuoteData.author;
      }
    </script>

I tried implementing the same code as the tutorial but when I press the link, I only get a tweet that says “#quotes ” instead of my quote.

does fetch request cache the response?

When querying using fetch in js, I get data on the site /order/1 returns to me {uri:'/me/order/1'}, which means that I am the owner of this resource at this moment, my user id is 1, then I go to the site under the data of another user with id=2 and my token is different

My code

  fetch(`${runtimeConfig.public.apiBase}/orders/${route.params.id}`, {
    method: 'GET',
    cache: 'no-cache',
    headers: {
      'Authorization': `Bearer ${token.value}`
    }
  }).then((response) => {
    return response.json();
  }).then((data) => {
    if (data && !data.uri) {
      order.value = data
    }
    if (data.uri) {
      getMyOrder(data.uri)
    }
  }).catch((err) => {
    console.error("Error:", err);
  });

I execute the request /order/1 and I get the result {uri:'/me/order/1'}, although the user has changed and I should get {order_id:1, name: 'qwerty'}, I checked, the token definitely belongs to another user. Everything works correctly in postman, I get the expected response, and in browsers I get what I think is a cached response

After the deletion request, I get this list

{order_id:2, name: 'asd'},
{order_id:3, name: 'rew'},
{order_id:0, name: ''}
]```
In Postman, there is no third element at all, as it should be

How can I get the cyclomatic complexity by method of a collection of Javascript files?

I want to programmatically extract the cyclomatic complexity of all methods in a javascript project.

I know eslint can do this, but the project already has an _eslintrc.json defined, and I would like to avoid modifying it.

Is it possible to get eslint to write the cyclomatic complexity of all methods of a javascript project to a file without changing _eslintrc.json, perhaps by configuring it from the command line?

How to use includes() like method on an array?

Right now I am working on a search system but for a table that holds data with names but I want to know how to use the includes() Method I dont think you can use it with an array but yeah. An Example is this.

const array = {nicecool:"hi"}
function findarrayincludesname(array,includes) {
var includesa = {}
for (let i=1; i<array.length; i++) {
if (array.includes(includes) {
includesa.push(eval(array.+"idkhowtogetarraychildname"))
}
}
return includesa
}

console.log(findarrayincludesname(array,"nice")

the code really explains a lot but I need a fast solution that would not take much time to load and not hackable.

So if you have any single answer please I will be needing it for my online platform

CSS from One Div is showing up on Another Div. How to contain the CSS within the Div?

I am trying to understand how I can contain a CSS from one div from not starting over another div.
For example here is my HTML and CSS and JS:

<div class="blueBackground"></div>

<div class="divTwo">
    <div class="col-md-12 col-sm-10">   
        <div id="blue_square" style="top: 310px;"></div>
    </div>   
</div>

#blue_square{
    position: fixed;
    right: 0;
    z-index: 9;
    width: 370px;
    box-shadow: 0 0 6px transparent;
}


$("#blue_square").css("top", $(window).height() / 2 - 90)

As you can see I have here to separate divs: blueBackground and divTwo.

The problem I am seeing is that my CSS from divTwo is somehow starting on from blueBackground div. Here is a snap shot: example 1.

I want the CSS for #blue_square to only apply within the divTwo not outside of it. Why is the “blue sqaure” diagram starting on blueBackground and not from within divTwo? I am trying to make it to look like this: example 2

Cypress Won’t Open Button to Type Form

Chrome vs Cypress

Click focus

Using Cypress 13.3.0

So I’ve tried doing a .click( {force: true} ) and all that, even attempted using .trigger(‘click’) on it, but it doesn’t seem to open the form so the next line can get it and type in it. The cursor Cypress shows is focused on it and it clicks, but it doesn’t seem to go anywhere. When I investigated the HTML elements, it seems to load a whole new area outside of the button. Any idea how I can fix this?

//image upload
cy.findByText(/Add existing Image/i).click({ force: true });
cy.get( //This wont open
'#edit-field-pac-publication-image-form-0-entity-id--wruseI7wRoU'
).type('test_0.jpeg (434)');

Vue 3 @click methods $options.x is not a function

Totally stumped on this. I’m developing a WordPress plugin with Vue but I can’t get the @click event to work.

<script>
export default {
  name: "App",

  methods: {
    showPanel: function () {
      console.log("Clicked!");
    }
  }
};
</script>

<template>
  <div id="frontend-app" class="app">
    <button @click="showPanel()">Test Button</button>
    <!-- <router-view /> -->
  </div>
</template>

But I get the following warning and error:

runtime-core.esm-bundler.js:179  [Vue warn]: Unhandled error during execution of native event handler 
  at <App>
Uncaught TypeError: $options.showPanel is not a function
    at onClick._cache.<computed>._cache.<computed> (App.vue?./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/dist/templateLoader.js??ruleSet%5B1%5D.rules%5B2%5D!./node_modules/vue-loader/dist/index.js??ruleSet%5B1%5D.rules%5B8%5D.use%5B0%5D:13:59)
    at callWithErrorHandling (runtime-core.esm-bundler.js:296:18)
    at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:304:17)
    at HTMLButtonElement.invoker (runtime-dom.esm-bundler.js:437:82)

I used Vue.js 3 Plugin Generator to setup the WordPress plugin if that’s relevant and the Vue app is built with Webpack.

Any ideas? I’ve searched all over and tried everything I can think of.

Thanks

Why does DATE_SUB function not work for mysql query with node js?

I have a datetime field in a MySQL database table on Planetscale. I want to return the datetime value after some time has been subtracted from it using the DATE_SUB function. This works in the database console on Planetscale’s website but is not working from my node js server request.

Server code:

const mysql = require('mysql2');  
mysql.query('SELECT DATE_SUB(log_time,INTERVAL 4 HOUR) AS time FROM time_table;',[], function(err, records){
   if (err) {
      console.log(err);
   }
   else {
      console.log(records);
   }
})

And this is my table:

CREATE TABLE time_table (
    log_time DATETIME
);

But is not subtracting the 4 hours as I am expecting and as it does on the db console on Planetscale’s website. Is this an issue with Planetscale, MySQL, MySQL2, node js, or something else? Thanks.

Canvas running in a visual studio code extension errors, saying module was compiled by an earlier version that the one running

When running a visual studio code extension using canvas to generate image error logs, I get a problem when in the test enviroment stating that

node_modules/canvas.node was compiled against a different Node.js version using NODE_MODULE_VERSION 115. This version of Node.js requires NODE_MODULE_VERSION 116. Please try re-compiling or re-installing the module (for instance, using npm rebuild or npm install)..

This is strange because I’m using the latest version of mode, and running canvas outside of the visual studio code extension works.

I used yarn ,updated node to the latest version , rebuilt all the extensions, deleted node modules and then reinstalled, rebuilt using –rebuild-binary

Uncaught TypeError: Cannot read properties of null (reading ‘Column1’)

I can’t render array of objects from slaves.json file. It shows me ‘Uncaught TypeError: Cannot read properties of null (reading ‘Column1′)’

How can i render this?
Help.please

App.js

import './App.css';
import slaves from './slaves.json';

console.log('slaves', slaves);

const arr = slaves.map((obj) => obj.Column1);

function App() {
  return (
    <div className="App">
      <div>
        {arr.filter((obj) => {
          return <div>{obj}</div>;
        })}
      </div>
    </div>
  );
}

export default App;

slaves.json

Javascript Local Storage seems to be loading nonexistent items

I have a simple to-do list app and I want to save/load the added items. I’m using the following code to add an item to localStorage each time an item is added:

localStorage.setItem("LIST_ITEM_" + makeid(24), uinput); //makeid() generates random strings

I’m setting the key to LIST_ITEM_ and a random 24-character string

I am using the following code to load items from localStorage:

for (i in localStorage) { // Iterate through the cookies
    for (const [key,value] of Object.entries(localStorage)) { // Create key-value pairs for each
        if (key.includes("LIST_ITEM")) { // Check if the key is a LIST_ITEM
            // Create elements to display the item
        }
    }
}

The problem comes in on the page where it seems to load each item 8 times instead of just once as it should.

I ran this code to see what was inside localStorage:
for (i in localStorage) {console.log(localStorage[i])}

And got this:

ww
VM1809:1 w
VM1809:1 2
VM1809:1 ƒ clear() { [native code] }
VM1809:1 ƒ getItem() { [native code] }
VM1809:1 ƒ key() { [native code] }
VM1809:1 ƒ removeItem() { [native code] }
VM1809:1 ƒ setItem() { [native code] }

The keys that have actually been input are “w,” and “ww”.

The page displays:

w
ww

8 times.

Not sure what I’ve done wrong but that is definitely not supposed to happen.

cannot import module I created in node

I can’t figure out why this import is failing. I have tried everything I can think of, changed the export and import to every single tutorial I can find online, and every single time it fails. Theoretically this should be very simple….

server.js

import express from 'express'
import sqlite3 from 'sqlite3'
import fetch from 'node-fetch'
import config from './config'

//rest of my code here...

config.js

const config = {
  url: "my url string here",
  port: 5000,
  callbackURL: "another url here"
}
export default config

in my package.json file I do have "type": "module" in there and all the imports from the node modules work just fine, it just fails on the config import. When I try to run the code above I get…
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '{path}/config' imported from '{path}/server.jsDid you mean to import ..config.js? But there is no ../config.js, both server.js and config.js are in the same directory

I figured this should be something easy, I just need to import a module that I am creating, but nothing works, it always tells me if can’t find the module config. I’ve tried changing the name thinking maybe config was reserved. So I changed to settings.js, same thing, Cannot find module settings.
I’ve tried changing the export to numerous ways, stuff like…
config.js

const config = {
  url: "my urls",
  port: 5000,
  callbackURL: "another"
}
export { config }

then changing my import to import { config } from './config'. Same thing. I've tried removing the ./` in front of config, same thing. I’m pretty lost, any help would be really appreciated. Thank you.

Just for extra information here is my actual package.json…

{
  "name": "my_test_app",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "type": "module",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1",
    "start": "node server.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.2",
    "node-fetch": "^2.7.0",
    "request": "^2.88.2",
    "sqlite3": "^5.1.6"
  }
}

And I am trying to run it with npm start in terminal

how to divide an array into 2 arrays?

I’m trying to turn this array into 2 different arrays. One array should be of names that contain the letter ‘o’ in them and the second array should be the rest of the names, that do not have ‘o’.

Given array:

var names = ['octavia', 'peter', 'olive', 'ava', 'aiden']; 

Desire result:

var nameO = ['octavia', 'olive'];
var nameNoO = ['peter', 'ava', 'aiden'];

This is the code I came up with. Got one of the results for names with ‘o’, but not without ‘o’.

var names = ['octavia', 'peter', 'olive', 'ava', 'aiden'];
var namesO = [];
var namesNoO = [];
for(let i in names){
  for(let j in names[i]){
    if(names[i][j] === 'o'){
      namesO.push(names[i]);
    } 
    if(names[i][j] !== 'o'){
    namesNoO.push(names[i])
    }
 }
}
console.log(namesO, namesNoO);