React/Spring Boot application API call is returning .jsx from the frontend instead of the expected data

I am using a decoupled React / Spring Boot application deployed on a single DigitalOcean Droplet. The application file structure is separated into a “backend” and “frontend” folder but it is all in the same repo. I was told that this is possible but it seems like my API calls are going to the frontend only for some reason.

I have the following API call in my frontend that is meant to return a list of services provided

const [ services, setServices ] = useState([]);

useEffect(() => {
    axios.get('https://my_application_domain/api/packages/load')
      .then(response => {
        if (response.status === 200) {
          const sortedServices = response.data.sort((a, b) => a.price - b.price);
          setServices(sortedServices);
        } else
          console.log("nope")
      })
      .catch(error => console.error(error));
  }, [])

Please forgive my poor error handling. I just wanted to get something working. I will refactor later.

The issue is occurring with all of my API calls but since they are all very similar, I expect the issue is in the URL itself rather than some other aspect of the function
This API call used to have localhost:8080 instead of my domain but i changed it over after deployment. when i enter that URL in to my browser, i get a blank page as if I used a malformed <Route /> in my App.jsx it has a navbar and footer but no content. I tried logging the response which output .jsx instead of the expected data.

It would seem that my API is not hitting the backend and is instead hitting the frontend and returning .jsx but I’m not sure where to go to fix it. My only idea is that I need to configure DigitalOcean differently to account for the ports but I have never deployed a site before and I can’t find a tutorial that is using the same stack as I am.

I’ve tried following about 6 different YT tutorials and searched SO for the solution but I keep getting stuck on one part or another. I would love to be able to say where exactly I got stuck but I got so frustrated with it that I set it all aside for a couple days and I no longer remember.

Conditionally wrap a vue 3 element

In Vue 3, how can an element be conditionally wrapped rather than creating two seperate blocks with v-if directive?

I have a simplified example here, but the question deals with conditional wrapping. There are a few issues here, in the html block there is a lot of coupling with state in the script setup block, so abstracting that to a child component is more trouble than it’s worth. There would be mixed state and it would be a mess having to deal with emitting data from child to parent. Second, because of the size of the html block, creating manual render functions would also be a mess.

The below code does work, but there is a big block that is duplicated just because I need an extra wrapper. Note that this question is not about how css could be used to fix this.

<script setup>
const isMobile = ref(true)
</script>

<template>
  <div v-if="isMobile" class="mobile-wrapper">
    <div class="product-meta">
      <!-- long html block tightly coupled with script setup block -->
    </div>
  </div>
  <div v-else class="product-meta">
    <!-- same html block -->
  </div>
</template>

Need help for migration from php 7.4 to 8.2 + mysql [closed]

Need help for migration of php code from 7.4 to 8.2

Expecting new code for php 8.2

Hi friends,
I have a simple feedback form.
When the Send button is pressed, it will post the form data and update the feedback table.
Its working in PHP 7.4
When i have uploaded the code to cpanel, Its not updating the table.
Cpanel is having version PHP 8.1, 8.2 and 8.3

Can some body help me with the new coding for 8.2


<?php
$booknoworsave =0;

   if ($_SERVER['REQUEST_METHOD'] == 'POST')
   {
      $mysql_server = 'localhost';
      $mysql_database = 'db1';
      $mysql_table = 'feedback';
      $mysql_username = 'admin';
      $mysql_password = 'password';
      $eol = "n";

if(isset($_POST['Send']))
{
$booknoworsave = $_POST['Send'];
}
global $booknoworsave;


 if($booknoworsave == "Send")
{

//Input sanitization to replace special characters
      $search = array("ä", "Ä", "ö", "Ö", "ü", "Ü", "ß", "!", "§", "$", "%", "&", "/", "x00", "^", "°", "x1a", "-", """, " ", "\", "", "x0B", "t", "n", "r", "(", ")", "=", "?", "`", "*", "'", ":", ";", ">", "<", "{", "}", "[", "]", "~", "²", "³", "~", "µ", "@", "|", "<", "+", "#", ".", "´", "+", ",");
      $replace = array("ae", "Ae", "oe", "Oe", "ue", "Ue", "ss");
      foreach($_POST as $name=>$value)
      {
         $name = str_replace($search, $replace, $name);
         $name = strtoupper($name);

         $form_data[$name] = $value;
  
      }
//input sanitization ends here

//Create database in not exists
      $conforbooknow = mysqli_connect($mysql_server, $mysql_username, $mysql_password) or die('Failed to connect to database server!<br>'.mysqli_error($conforbooknow));
      mysqli_query($conforbooknow, "CREATE DATABASE IF NOT EXISTS $mysql_database");
   
 
//Create table in not exists 
      $conforbooknow =mysqli_connect($mysql_server, $mysql_username, $mysql_password, $mysql_database);

 mysqli_query($conforbooknow, "CREATE TABLE IF NOT EXISTS $mysql_table (ID int(9) NOT NULL auto_increment, `DATESTAMP` DATE, `TIME` VARCHAR(8) NOT NULL DEFAULT '00', `IP` VARCHAR(30) NOT NULL DEFAULT '00', `BROWSER` TINYTEXT, PRIMARY KEY (id))");


//create column names
      foreach($form_data as $name=>$value)
      {
         mysqli_query($conforbooknow, "ALTER TABLE $mysql_table ADD $name VARCHAR(50) NOT NULL DEFAULT '00'");
      }
      mysqli_query($conforbooknow, "INSERT INTO $mysql_table (`DATESTAMP`, `TIME`, `IP`, `BROWSER`)
                   VALUES ('".date("Y-m-d")."',
                   '".date("G:i:s")."',
                   '".$_SERVER['REMOTE_ADDR']."',
                   '".$_SERVER['HTTP_USER_AGENT']."')")or die('Failed to insert data into table!<br>'.mysqli_error($conforbooknow)); 
 

     $id = mysqli_insert_id($conforbooknow);


// add values to table
      foreach($form_data as $name=>$value)
      {

         mysqli_query($conforbooknow,"UPDATE $mysql_table SET $name =  '$value'  WHERE id = '$id'");

      }
      mysqli_close($conforbooknow);


}//Add new item

}
?>

emailVerified Property Not Syncing in Firebase Auth Emulator

I am developing a React application using Firebase Auth and the Firebase emulator. I’ve encountered an issue where the emailVerified property of a user does not sync as expected. Despite setting this property to false in the Firebase Auth emulator interface, when I query this property through the onAuthStateChanged listener, it consistently returns true. Here is the relevant part of my code:

useEffect(() => {
  const unsubscribe = firebase.auth().onAuthStateChanged(user => {
    if (user) {
      console.log(user.emailVerified, 'emailVerified')  // Log the current state of 'emailVerified'
      // The user is logged in
      const getUserProfile = async () => {
        setLoading(true);
        try {
          const snap = await db.collection("users").doc(id).get();
          if (snap.exists) {
            const userData = snap.data();
            const userProfileData = {
              ...userData,
              emailVerified: user.emailVerified  // Use the 'emailVerified' property from the user object
            };
            setUserProfile(userProfileData);
          }
        } catch (error) {
          setError(error.message);
        }
        setLoading(false);
      };

      getUserProfile();
    } else {
      // The user is not identified, handle this case if necessary
      setUserProfile({});
    }
  });

  return () => unsubscribe();
}, []);

I’ve tried using user.reload() to force a refresh of the user’s state, but this hasn’t resolved the issue. I’m looking for any advice on why this might be happening and how to ensure that the emailVerified state is correctly synchronized between the emulator and my application.

Unable to view tinymce editor in my angular project’s UI(However it is present in t elements)

I have installed tinymce in my project. I have installed it successfully but when I am trying to use it, it is not displaying on the UI however it is present in the elements when I inspect the area where it should be displaying.

I am attaching both the package.json of my project and an image of the UI.

The Image of the UI:-
[1]: https://i.sstatic.net/659mbYUB.png

Please find below my my project’s package.json :-

    {
  "name": "cat",
  "version": "1.0.1",
  "license": "MIT",
  "scripts": {
    "build-high": "node --max_old_space_size=7000 ./node_modules/@angular/cli/bin/ng build --prod --output-hashing=all",
    "ng": "ng",
    "start": "ng serve --host 0.0.0.0",
    "serve": "set NODE_OPTIONS=--max_old_space_size=8192 & ng serve --open",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build-prod": "node ./replace.build.js && ng build --prod --aot=false",
    "bundle-analyze": "node --max_old_space_size=7000 ./node_modules/@angular/cli/bin/ng build --prod --stats-json && webpack-bundle-analyzer dist/stats-es2015.json"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.1.0",
    "@amcharts/amcharts3-angular": "^2.2.4",
    "@amcharts/amcharts4": "^4.10.38",
    "@angular/animations": "^9.1.13",
    "@angular/common": "^9.1.13",
    "@angular/compiler": "^9.1.13",
    "@angular/core": "^9.1.13",
    "@angular/forms": "^9.1.13",
    "@angular/platform-browser": "^9.1.13",
    "@angular/platform-browser-dynamic": "^9.1.13",
    "@angular/router": "^9.1.13",
    "@angular/service-worker": "^9.1.13",
    "@tinymce/tinymce-angular": "^4.2.4",
    "@types/lodash": "^4.14.104",
    "ag-grid-angular": "^25.2.0",
    "ag-grid-community": "^25.2.0",
    "angular2-counto": "^1.2.5",
    "angular2-text-mask": "^9.0.0",
    "angular2-tinymce": "^2.1.2",
    "auth0-js": "^9.24.1",
    "auth0-lock": "^12.4.0",
    "check-peer-dependencies": "^4.3.0",
    "d3": "^4.12.2",
    "d3-scale-chromatic": "^1.3.3",
    "dom-autoscroller": "^2.3.4",
    "file-saver": "^2.0.5",
    "font-awesome": "^4.7.0",
    "html2canvas": "^1.0.0-rc.7",
    "jspdf": "^2.3.1",
    "lodash": "^4.17.21",
    "moment": "^2.30.1",
    "ng2-dragula": "^2.1.1",
    "ng2-pdf-viewer": "^6.4.1",
    "radial-progress-chart": "0.0.4",
    "rxjs": "^6.6.7",
    "rxjs-compat": "^6.6.7",
    "signalr-no-jquery": "^0.2.0",
    "tinymce": "^7.0.1",
    "tslib": "^1.14.1",
    "underscore.deepclone": "^0.1.3",
    "webpack-bundle-analyzer": "^4.10.1",
    "xlsx": "^0.18.5",
    "zone.js": "^0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.901.15",
    "@angular-eslint/builder": "1.2.0",
    "@angular-eslint/eslint-plugin": "1.2.0",
    "@angular-eslint/eslint-plugin-template": "1.2.0",
    "@angular-eslint/schematics": "1.2.0",
    "@angular-eslint/template-parser": "1.2.0",
    "@angular/cdk": "^8.2.3",
    "@angular/cli": "^9.1.15",
    "@angular/compiler-cli": "^9.1.13",
    "@angular/language-service": "^9.1.13",
    "@types/googlemaps": "^3.43.3",
    "@types/jasmine": "^3.7.0",
    "@types/jasminewd2": "^2.0.9",
    "@types/node": "^15.0.2",
    "@typescript-eslint/eslint-plugin": "4.3.0",
    "@typescript-eslint/parser": "4.3.0",
    "codelyzer": "^6.0.1",
    "eslint": "^7.6.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "^3.7.1",
    "jasmine-spec-reporter": "^7.0.0",
    "karma": "^6.3.2",
    "karma-chrome-launcher": "^3.1.0",
    "karma-cli": "^2.0.0",
    "karma-coverage-istanbul-reporter": "^3.0.3",
    "karma-jasmine": "^4.0.1",
    "karma-jasmine-html-reporter": "^1.6.0",
    "protractor": "^7.0.0",
    "replace-in-file": "^6.2.0",
    "ts-node": "^9.1.1",
    "typescript": "^3.8.3",
    "webpack": "^4.46.0"
  }
}

Downloading images (curl) is not the right way for Linux?

I have a lot of images and there is a function that takes an array of links in each element and runs them through a function to download them and returns links to them, which I then save to the database. This works on windows, but doesn’t work on linux. The folder has write rights, I transfer files there manually via ssh without any problems and can download the image by running curl in the console without any problems.

cd /var/www/html/static && curl -O https:/imgurl.com/uploads/catalog/i/lbig/963949fdf7.jpg --parallel

But when the script runs, it creates subfolders, but there is nothing in them. I think the problem is with the paths

I made test scripts with different options, the first two create folders but again there is nothing in them.

The problem is definitely on the way, because… curl in console downloads everything correctly and the folder has permissions for everything

Help me choose the best path so that it works correctly in Linux and node.js

shell.cd('./static/images')
if (shell.ls('./').includes('objects')) {
    shell.rm('-rf', './objects')
}
shell.mkdir('objects')


async function downloadAndSaveImages(cleanLinks, folderPath) {
    const arr = []
    try {
        await fs.mkdir(folderPath, { recursive: true });
        shell.cd(folderPath)
        let command = `cd ${folderPath} && curl `
            + Array(cleanLinks.length).fill('-O').join(' ')
            + ' '
            + Array(cleanLinks.length).fill(null).map((_, i) => {
                return cleanLinks[i].split('?')[0]
            }).join(' ')
            + ' --parallel'

        for (let i = 0; i < cleanLinks.length; i++) {
            const imageUrl = cleanLinks[i].replace(/?.*/, '');
            const imageFileName = path.basename(imageUrl);
            const imagePath = path.join(folderPath, imageFileName);
            arr.push(imagePath.replace(/.*?static/, '/static').replace(/\/g, '/'))
        }
        await execPromise(command, { timeout: 5000 })
        await Promise.allSettled(command)
        return arr;
    } catch (error) {
        return arr
    }
}

async function start() {

    const photoFolderPath = path.join(__dirname, '..', 'static', 'test', '9639497');
    const cleanLinksNew = await downloadAndSaveImages(['https:/imgurl.com/uploads/catalog/i/lbig/963949fdf7.jpg'], photoFolderPath);

    const photoFolderPath2 = path.resolve(__dirname, '../static/test1', '9639497');
    const cleanLinksNew2 = await downloadAndSaveImages(['https:/imgurl.com/uploads/catalog/i/lbig/963949fdf7.jpg'], photoFolderPath2);

    const photoFolderPath3 = path.join('/var/www/html/static', 'test2', '9639497');
    const cleanLinksNew3 = await downloadAndSaveImages(['https:/imgurl.com/uploads/catalog/i/lbig/963949fdf7.jpg'], photoFolderPath3);

    const photoFolderPath4 = path.resolve('/var/www/html/static/test3', '9639497');
    const cleanLinksNew4 = await downloadAndSaveImages(['https:/imgurl.com/uploads/catalog/i/lbig/963949fdf7.jpg'], photoFolderPath4);

    const photoFolderPath5 = path.join('/var', 'www', 'html', 'static', 'test4', '9639497');
    const cleanLinksNew5 = await downloadAndSaveImages(['https:/imgurl.com/uploads/catalog/i/lbig/963949fdf7.jpg'], photoFolderPath5);

    const photoFolderPath6 = path.join('/var', 'www', 'html', 'static', 'test5', '9639497');
    const cleanLinksNew6 = await downloadAndSaveImages(['https:/imgurl.com/uploads/catalog/i/lbig/963949fdf7.jpg'], photoFolderPath6);

    const photoFolderPath7 = path.join( 'static', 'test6', '9639497');
    const cleanLinksNew7 = await downloadAndSaveImages(['https:/imgurl.com/uploads/catalog/i/lbig/963949fdf7.jpg'], photoFolderPath7);

}

start()

enter image description here

JS Functions names with object syntax

Can functions be declared like this in Javascript and safely be used on the web.

$is.array = function (e) {
  return typeof e === "array" || e instanceof Array;
};
$is.element = function (e) {
  return e instanceof Element || e instanceof HTMLDocument;
};
$is.function = function (e) {
  return typeof e === "function";
};

No errors appear to be taking place but I am not familiar with this syntax.

In NVDA, Button receives focus upon pressing Enter/space in the inner icon when aria-label/aria-labelled is used

Steps to Reproduce the Issue:

Open the link: https://nvda-test.w3spaces.com/button-accessibility-label.html
Two buttons: This page contains two buttons, each with a focusable icon inside.
ARIA Attributes: The first button has an aria-label attribute or an aria-labelledby attribute, while the second button does not have either.
NVDA Behavior: When using a screen reader like NVDA, focusing the icon within the first button (the one with aria-label or aria-labelledby) and pressing Enter or Space will cause the focus to return back to the button itself. This issue doesn’t occur with the second button (without ARIA attributes).
Project Use Case:

In my project, I have a button with a close icon inside. Ideally, focusing the close icon and pressing Enter/Space should remove the button from the page. This works as expected without NVDA, but the issue mentioned above arises when NVDA is enabled. While removing the aria-labelledby attribute from the button fixes this issue, but it’s necessary for other accessibility concerns and hence cannot be removed.

I want to prevent the focus from returning to the button when pressing Enter/Space on the icon inside the button, while still maintaining the aria-label or aria-labelledby attribute on the button for accessibility.

problems when mapping un useState [closed]

I’m having trouble mapping a useState. I have a context that sends a simple useState to my useFilter hook (const[ valueSelects, setValueSelects] = useState({})).

In the hook I have a function called getInitFilters that tries to initialize the valueSelects of a filter. This function maps a constant called initFilter from the outside and with that data I try to put it inside the useState of valueSelects.

The final result of [id], [key] and value is fine, it maps the two values ​​of the array, it goes through them but when it reaches the useState , the result is only one of them, the category is not there
Object { tailles: {…} }
tailles: Object { M: 1 }

I want the value selects to be equal to the initFilter constant

use of the hook

const initFilter = { 'categorie': { 'TOUS': 'all' }, 'tailles': { 'M': 1 } }
const { filterProducts } = useFilter(initFilter);
const filteredProducts = filterProducts(products[0]

El valueSelets en el contexto es solo un useState,

const [valueSelects, setValueSelects] = useState({})






import { useEffect } from "react";    
import { useUi } from "../context/useUi";

export const useFilter = (ids) => {
 const { valueSelects, setValueSelects, range } = useUi();


    useEffect(() => {
        getInitFilters(ids);
    }, [])


   
         const getInitFilters = () => {
             Object.keys(ids).map(id => {
                 const key = Object.keys(ids[id])[0];
                 const value = Object.values(ids[id])[0]
                 setValueSelects({ ...valueSelects, [id]: { [key]: value } })
             });
         } 



const filterProducts = (datas) => {

        return datas.filter(data => {
            return (Math.round(data.price * optionValue) >= range &&
                (valueFilter === 'all' || data.type === valueFilter))
        })
    }
    
    return { filterProducts }
}

How can I optimize NextJS first load pages?

I am using Nextjs 13.5 with Pages structure in building a large scale application that consists of many complix logic and components.

I alwayse make sure to separate my logic and sections in one page into small components.

However, I am facing an issue with First Load JS time as many of the application pages taske long time to load and render.

enter image description hereenter image description here

I have tried improving my code a lot, removing unnecessary codes, using dynamic content, writing clean code but still the problem is there.

I just want to know what are the factors that increase the loading of such pages? And what can I do to reduce it.

Using @starting-style and allow-discrete, how to remove a dialog element after it is closed?

Using @starting-style and allow-discrete, how to remove a dialog element after it is closed and transitioned?

Using @starting-style and allow-discrete to do the transition entry and exit of dialog.I need to remove the dialog element after closing dialog. I didn’t want a redundant element to exist in the DOM. Here is the code i use.

dialog {
  &,
  &::backdrop {
    opacity: 0;
    transition: opacity 0.15s, display 0.15s allow-discrete, overlay 0.15s allow-discrete;
    transition-timing-function: ease-out;
  }
  &::backdrop {
    background-color: black;
  }
  &:modal {
    opacity: 1;
    &::backdrop {
      opacity: 0.5;
    }
    @starting-style {
      &,
      &::backdrop {
        opacity: 0;
      }
    }
  }
}
<button type="button">open dialog</button>
document.querySelector('button').onclick = event => {
  const dialog = document.createElement('dialog')
  const close_button = event.currentTarget.cloneNode()
  close_button.textContent = 'close'
  close_button.onclick = () => dialog.close()
  dialog.append(close_button)
  
  // 1.
  // This will cause the click to close immediately after triggering remove, losing the exit transition
  // dialog.onclose = Element.prototype.remove

  // 2.
  // According to the specifications, in the case where a transition is removed before completion, such as if the transition-property is removed or display is set to none, then the event will not be generated.
  // dialog.onclose = () => {
  //   dialog.ontransitionend = Element.prototype.remove
  // }
  
  // 3.
  // After entering the transition, register a transitionstart event, listen to exit the transition, time to 150ms, and then remove dialog.
  // dialog.addEventListener(
  //   'transitionend',
  //   () => {
  //     dialog.ontransitionstart = () => setTimeout(() => dialog.remove(), 150)
  //   },
  //   {once: true}
  // )
  document.body.append(dialog)
  dialog.showModal()
}

I used three methods, none of which solved my problem well, either by not implementing it or by being too ugly.