redux update delete add value to object inside object by id if exist or not

hello I would like to update, delete and add value inside my redux store, my API return object of map for example

carList:{
"bmw" : [
   {
            "id": "C4FC3DC3-4C88-EC11-97A5-B07D6412D8C3",
            "buyDate": "2000-02-07T19:33:02.613+00:00",
            "sellDate": "2022-02-07T19:33:02.613+00:00",
            "carID": "bmw",
            "color": "red"
        },
{
            "id": "C4FC3DC3-4C88-EC11-97A5-B07D6412D8A3",
            "buyDate": "2010-03-07T19:33:02.613+00:00",
            "sellDate": "2019-01-12T19:33:02.613+00:00",
            "carID": "bmw",
            "color": "blue"
        }
],
"Ford" : [
   {
            "id": "C4FC3DC3-4C88-EC11-97A5-B07D6412D8C3",
            "buyDate": "2000-02-07T19:33:02.613+00:00",
            "sellDate": "2022-02-07T19:33:02.613+00:00",
            "carID": "Ford",
            "color": "red"
        },
{
            "id": "C4FC3DC3-4C88-EC11-97A5-B07D6412D8A3",
            "buyDate": "2010-03-07T19:33:02.613+00:00",
            "sellDate": "2019-01-12T19:33:02.613+00:00",
            "carID": "Ford",
            "color": "blue"
        }
]

}

and I dont know how to make cases in reducer for this simple code.

My insert update and delete object looks like

{
            "id": "C4FC3AS3-4C88-EC11-97A5-B07D6412D8A3",
            "buyDate": "2020-03-07T19:33:02.613+00:00",
            "sellDate": "2021-01-12T19:33:02.613+00:00",
            "carID": "Ford",
            "color": "blue"
        }

Why isn’t webpack retaining console.log statements?

I’m doing my first tests with webpack and experimenting with code splitting, and I simply wanted to log from my index.js file. It gets compiled, but it doesn’t log nothing, both in development or in production mode. Files are compiled and loaded. Very strange. I’m sure I’m doing something wrong… Could you please point me in the right direction?

// index.js
import _ from 'lodash';
import Swiper from 'swiper';
import { Fancybox, Carousel, Panzoom } from "@fancyapps/ui";

function log(){
  console.log('from index');
  console.log(Swiper);
  console.log(Fancybox, Carousel, Panzoom);
  console.log(_);
}

log();

webpack config:

const path = require('path');

module.exports = {
  //mode: 'development',
  mode: 'production',
  watch: true,
  entry: {
    index: './src/index.js',
    //page_2: './src/page-2.js'
  },

  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, 'dist'),
  },

  optimization: {
    splitChunks: {
      cacheGroups: {
        visuals: {
          name: 'visuals',
          chunks: 'all',
          test: /[\/]node_modules[\/](swiper|@fancyapps/ui|dom7|ssr-window)[\/]/
        },
        lowdash: {
          name: 'lowdash',
          chunks: 'all',
          test: /[\/]node_modules[\/]lodash[\/]/
        }
      },
    }
  },

  module: {
    rules: [
      {
        test: /.m?js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: { presets: ['@babel/preset-env'] }
        }
      } // babel
    ] // rules
  } // module
};

Adding an item to a table (js,html)

How to add an element using the dialog box so that it is saved in the table?

 buttonik[0].addEventListener("click", ()=> {
    const lastname = prompt("enter your last name");
    if(lastname){
     const name= prompt("enter your  name");
     if(name){
     const sex = prompt("enter your sex (M albo F)");
     if(plec) {
     const points= prompt("eneter your points");
     if(points){
         alert("participant added")
    }else{alert("the number of points was not given")}
     }else{alert("gender was not given")}
     }else{alert("no name was given")}
    }else{alert("no last name was given")}

Strict Mode Issue with Binding Arguments

I have an issue with running a test on my files. Would love if someone more experienced could help me out here.

the following code gives me this error:

error Parsing error: Binding arguments in strict mode

return function someFunc(...arguments){
  if (cache[arguments]){
    return cache[arguments]
  }

(p) element doesn’t display when it should

Hi I’m trying to make a website editor with drag and drop feature
I added an input field when you press a button and the text you type in becomes the inner text for a “p” element but the “p” element doesn’t display
Here’s the code
HTML:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>HTML</title>
  
  <!-- HTML -->
  

  <!-- Custom Styles -->
  <link rel="stylesheet" href="style.css">
</head>

<body>
   <nav>
   <button class="button" id="h1">Header</button>
   <button class="button" id="h2">Header2</button>
   <button class="button" id="p">Text</button>
   <button class="button" id="img">Image</button>
   </nav>
   <input type="text" placeholder="type your text here" id="text-field">
<!-- Linking scripts -->
   <script type="module" src="main.js"></script>
   <script type="module" src="mouse.js"></script>
   <script type="module" src="header_button.js"></script>
   <script type="module" src="header2_button.js"></script>
   <script type="module" src="image_button.js"></script>
   <script src="text_button.js"></script>

JavaScript:

let text_button = document.getElementById('p')
let text_data_holder = document.getElementById('text-field')
let paragraph = document.createElement('p')
let text_data = ''
//Creating text
text_button.addEventListener('click', function() {
  text_data_holder.style.display = 'block'
})
text_data_holder.addEventListener('change', function(e) {
   e.preventDefault()
   text_data += e.target.value
    if(text_data == e.target.value){
     paragraph.innerText = text_data
     console.log(text_data)
    }
})

Zend Framework’s JsPush adapter only refreshing progress once the PHP script is finished

Since we switched a project from PHP 5 to 7.4, something odd is happening, although I doubt it’s a PHP thing, but please hear me out first.

The HTML/PHP project uses the Zend_ProgressBar_Adapter_JsPush class of the Zend Framework.

There’s an HTML button on screen. Once it’s clicked, a PHP script is running in the background and calling the update method of the Zend_ProgressBar class. After each step the PHP script does/finishes, the value goes up by +20, until 100 is reached.

There is also an HTML table. 2nd column showing a load-icon before the results of each step coming in. There are 5 rows in that table, so one row for each step.

Now here’s the situation: During the times of PHP5 when the PHP script was running, the user could see which step the PHP script has reached/finished so far, but now with PHP7.4 in use, ALL fields are getting updated once the PHP script is finished. They are shown correctly, but the problem is that it doesn’t refresh step by step anymore.

It’s like everything is getting queued in the background or something, and JavaScript doesn’t get the chance to update any fields “live”, so it does it at the end of the PHP script.

I got no clue what the reason is. I even tried to add sleep(5) between these steps, and I saw it was working. But why letting the user wait 5 times 5 seconds if there could be a better solution?

Here’s the (light version) of the PHP code:

$adapter = new Zend_ProgressBar_Adapter_JsPush();
$adapter->setUpdateMethodName('Zend_ProgressBar_Update');
$adapter->setFinishMethodName('Zend_ProgressBar_Finish');

$progress = new Zend_ProgressBar($adapter, 0, 100);
$result = "";
$progress->update(0, $result);
// Do something...
$progress->update(20, $result);
// [...]
$progress->update(100, $result);

JavaScript methods:

function Zend_ProgressBar_Update(data)
{
    switch (data.current) {
        case 0:
        /* Reset progress table */
        /* [...] */
        break;
    case 20:
        /* Fill first row column of table with data.text */
        /* [...] */
        break;
    /* [...] */
    case 100:
        /* Fill final row column of table with data.text */
        /* [...] */
        break;
    default:
        //alert('default');
        break;
}

function Zend_ProgressBar_Finish()
{
    alert('Finished');
}

Convertir array a object

Tengo el siguiente array:

const arrPers = [ 1, 'ORIGINAL', 2, 'ORIGINAL', 3, 'PERSON001', 'PERSON002', 'PERSON003', 'PERSON004', 'PERSON003', 4, 'PERSON003', 'PERSON004', 'PERSON003', 'PERSON004', 'PERSON003', 'PERSON004', 'PERSON003', 5, 'PERSON003', 'PERSON004', 'PERSON003', 'PERSON003']

Necesito convertirlo de la siguiente manera:

const objPerson = {
  1: ['ORIGINAL'],
  2: ['ORIGINAL'],
  3: ['PERSON001', 'PERSON002', 'PERSON003', 'PERSON004', 'PERSON003'],
  4: ['PERSON003', 'PERSON004', 'PERSON003', 'PERSON004', 'PERSON003', 'PERSON004', 'PERSON003'],
  5: ['PERSON003', 'PERSON004', 'PERSON003', 'PERSON003']
}

He probado con varios bucles y no soy capaz. ¿Alguien me podría ayudar? Gracias

how to show stars based on user rating?

i woud like to show star based on rating . i can only show one product with rating stars and the other products don’t show any star only show rating number. could help to check which part need to change ?

<%- include ('_layouts/header'); -%>
<h1>......Exciting Books.....</h1>
 <hr size="100" width="100%" align="center" color="black">
    <br>
 <div class="row products">
    
    <% savedexcit.forEach(function(products){ %>
            <div class="col-xs-12 col-md-4 p shop-item">
                 <a class="pa" href="/products/<%= products.category %>/<%= products.slug %>">
                    <img class="pimage" src="/product_images/<%= products.id %>/<%= products.image %>" alt="">
                    </a>
                <h3><%= products.title %></h3>
                <b>Rating: <span id=stars></span><%= products.rating %>/5</b>
                <a class="vd" href="/products/<%= products.category %>/<%= products.slug %>">View Details</a>
            </div>
        <% }); %>  
</div>
<script>
 <% savedexcit.forEach(function(products){ %>
document.getElementById("stars").innerHTML = getStars(<%= products.rating %>);

function getStars(rating) {

  // Round to nearest half
  rating = Math.round(rating * 2) / 2;
  let output = [];

  // Append all the filled whole stars
  for (var i = rating; i >= 1; i--)
    output.push('<i class="fa fa-star" aria-hidden="true" style="color: gold;"></i>&nbsp;');

  // If there is a half a star, append it
  if (i == .5) output.push('<i class="fa fa-star-half-o" aria-hidden="true" style="color: gold;"></i>&nbsp;');

  // Fill the empty stars
  for (let i = (5 - rating); i >= 1; i--)
    output.push('<i class="fa fa-star-o" aria-hidden="true" style="color: gold;"></i>&nbsp;');

  return output.join('');

}
<% }); %>  
</script>
    <%- include ('_layouts/footer'); -%>

output result:
enter image description here

html/css/js – marquee, scroll one element then pause, then scroll again

I am trying to create an overlay page for my twitch channel. I play Rocket League and the tracker network site provides overlays that show your rank.

Basically what I have put together is a marquee with a bunch of iframes to grab the rank overlays and scroll them. It works pretty well so far.

What I’d like to do is have it pause on load, scroll slowly to the next one, then pause again, and repeat at the end. I’m having a bit of trouble with finding the right combination of words to search in Google about this, most queries I get answers relating to scroll-stop with javascript.

Here’s the current code:

<html>
<head>
    <style>
        iframe {
            border: 0px;
            margin: 0px;
        }
    </style>
</head>
<body>
<marquee>
    <iframe src="https://tracker.gg/overlays/overlay/347710c7-d003-47ec-8c56-29269060692c"></iframe>
    <iframe src="https://tracker.gg/overlays/overlay/687c5759-99f1-4f40-95c3-377cfb1751be"></iframe>
    <iframe src="https://tracker.gg/overlays/overlay/b8efb59c-02ae-4edf-9c9d-50a6d1643064"></iframe>
    <iframe src="https://tracker.gg/overlays/overlay/80fc2dab-f197-452e-827d-36aafdeca87d"></iframe>
    <iframe src="https://tracker.gg/overlays/overlay/76576b68-97aa-42a5-a5e4-45574ab0d3e9"></iframe>
    <iframe src="https://tracker.gg/overlays/overlay/fe174a33-4b60-4bcd-aed6-3188dbf1d432"></iframe>
    <iframe src="https://tracker.gg/overlays/overlay/7c1a3a59-7540-4c15-a5b4-24d19dbd5880"></iframe>
    <iframe src="https://tracker.gg/overlays/overlay/ebc95461-8851-4576-a8bf-0f8aec7c9d46"></iframe>
</marquee>
</body>
</html>

Any tips would be appreciated! Also looking into making it pure css/html without iframes and marquee in the future.

Differ between regular files and minified files in plain html

I got the following files – no frameworks or libraries are used:

  • hello.html
  • hello.css
    • hello.min.css
  • hello.js
    • hello.min.js
  1. What would be the best practice to use hello.js for development (local) but hello.min.js for production. Is it possible without separate tooling for building or packaging?

  2. If I use in development (local) a css class “class-A” when hello.css is embedded – what would happen on production? If in production hello.min.css is used would hello.html find the correct class even if the minified name is different?

Unable to embed a dashboard into our website — retrieved authentication token and embed token, but the embedded view still requires user to sign in

I am using Domo’s dashboards to display analytics in our website. We are embedding an iframe into the webpage, and the user is to click on the link to it, which should automatically generate an authentication token, which then generates an embed token, which then displays the dashboard to the user.

We have the embed ID, the auth token, and the embed token (which shows up in the console when logged). And yet, it is still prompting the user to log in. The iframe src is set up like so:
src={ 'https://my-company.domo.com/embed/pages/private/${ embedToken.embedId }?filters=${ embedToken.embedToken }' }

What am I missing here? How do you display a Domo iFrame?

Function not providing state in constructor as expected React

I am building a Kanban board where on page load, a cookie handler loads some tasks into local storage. If a cookie has been detected, nothing is done and the constructor loads state from local storage. Otherwise, the cookie handler loads some data into local storage and then the constructor loads state from that. However, when I delete the cookie and reload the page, it does not load. I need to reload the page a second time for it to work. I put everything in the constructor so shouldn’t it load before the page renders and avoid errors like this? I know this has something to do with asynchronicity but I cannot figure it out. Thank you for any help.

App.js

import React from "react";
import initialData from "./initial-data";
import styled from "styled-components";
import CreateForm from "./components/CreateForm";
import { withCookies, Cookies } from "react-cookie";
import { instanceOf } from "prop-types";

const Container = styled.div`
  display: flex;
`;

class App extends React.Component {
  static propTypes = {
    cookies: instanceOf(Cookies).isRequired,
  };

  constructor(props) {
    super(props);
    this.state = {
      tasks: JSON.parse(localStorage.getItem("tasks")),
      initialData,
      email: this.props.email,
      password: this.props.password,
      showForm: false,
      user: this.props.cookies.get("user") || "",
    };
    this.logOut = this.logOut.bind(this);
    this.onDragEnd = this.onDragEnd.bind(this);
    this.handleCookie = this.handleCookie.bind(this);

    this.handleCookie();
  }

  handleCookie = () => {
    this.deletedLocalStorage();
    if (!this.props.cookies.get("user")) {
      console.log("cookie not found.");
      const { cookies } = this.props;
      cookies.set("user", "gowtham", { path: "/" }); // setting the cookie
      this.setState({ user: cookies.get("user") });
      console.log("cookie set");
      const initData = JSON.stringify(initialData);
      localStorage.setItem("tasks", initData);
    } else {
      console.log("cookie found");
    }
  };

  deletedLocalStorage = () => {
    if (!localStorage.getItem("tasks")) {
      localStorage.setItem("tasks", JSON.stringify(initialData));
    }
  };


  render() {
    const { showForm } = this.state;
    //const { user } = this.state.user;

    if (this.state.email === "") {
      return <LogIn />;
    } else {
      return (
        <DragDropContext onDragEnd={this.onDragEnd}>
          <Container>
            {this.state.tasks.columnOrder.map((columnId) => {
              const column = this.state.tasks.columns[columnId];
              const tasks = column.taskIds.map(
                (taskId) => this.state.tasks.tasks[taskId]
              );

              return <Column key={column.id} column={column} tasks={tasks} />;
            })}
          </Container>
          <button onClick={this.logOut}>Log Out</button>

          <button onClick={() => this.hideComponent("showForm")}>
            Create Task
          </button>

          <Container>
            <div>
              {showForm && <CreateForm onSubmit={(value) => alert(value)} />}
            </div>
          </Container>
        </DragDropContext>
      );
    }
  }
}

export default withCookies(App);

Uncaught ReferenceError: require is not defined in Electron Js when using require() in html page

I am new to Electron Js and I am trying to make a custom titlebar as a project. I made the titlebar in a html page called nav.html and imported it in index.html (the main page)

nav.html :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />


    <title>Document</title>

    <style>
      * {
        margin: 0;
        padding: 0;
      }
      button {
        margin: 0;
        padding: 0;
        border: none;
        outline: none;
        background-color: transparent;
        height: 35px;
      }
      .header {
        background-color: black;
        color: white;
        overflow: hidden;
      }
#title {
        width: 80%;
        -webkit-app-region: drag;
        -webkit-user-select: none;
        user-select: none;
      }
      svg.restore {
        fill: rgb(255, 255, 255) !important;
        width: 15px;
        height: 15px;
        padding: 10px 14px;
      }
      svg.restore:hover {
        fill: rgb(255, 255, 255) !important;
        background-color: #5e5e5e !important;
      }

      button.minimize {
        padding: 3.5px 16px;
        color: white;
      }
      button.minimize:hover {
        background-color: #5e5e5e !important;
      }

      .maximize {
        cursor: default;
        fill: white;
        padding: 10px 14px;
        height: 15px;
        width: 15px;
        display: none;
      }
      .maximize:hover {
        background-color: #5e5e5e !important;
        color: white;
      }

      button.close {
        padding: 3.3px 14px;
        color: white;
      }
      button.close:hover {
        background-color: red !important;
      }
    </style>
  </head>
  <body>
<div
      class="header"
      style="display: flex; align-items: center; justify-content: space-between;"
    >
      <div id="title"></div>
      <div style="display: flex; align-items: center; justify-content: center;">
        <button
          style="font-size: 25px; cursor: default"
          class="minimize"
          id="minimize"
        >
          -
        </button>
        <button>
          <svg
            width="25px"
            height="25px"
            viewBox="0 0 512 512"
            xmlns="http://www.w3.org/2000/svg"
            style="cursor: default"
            class="restore"
            id="restore"
          >
            <path
              d="M352,153H40.247a24.028,24.028,0,0,0-24,24V458a24.028,24.028,0,0,0,24,24H352a24.028,24.028,0,0,0,24-24V177A24.028,24.028,0,0,0,352,153Zm-8,32v45.22H48.247V185ZM48.247,450V262.22H344V450Z"
              class="ci-primary"
            />
            <path
              d="M472,32H152a24.028,24.028,0,0,0-24,24v65h32V64H464V339.143H408v32h64a24.028,24.028,0,0,0,24-24V56A24.028,24.028,0,0,0,472,32Z"
              class="ci-primary"
            />
          </svg>

          <svg
            viewBox="0 0 1024 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            class="maximize"
            id="maximize"
          >
            <path
              d="M896 85.333333H128a42.666667 42.666667 0 0 0-42.666667 42.666667v768a42.666667 42.666667 0 0 0 42.666667 42.666667h768a42.666667 42.666667 0 0 0 42.666667-42.666667V128a42.666667 42.666667 0 0 0-42.666667-42.666667z m-42.666667 768H170.666667V426.666667h682.666666z m0-512H170.666667V170.666667h682.666666z"
            />
          </svg>
        </button>
        <button
          style="font-size: 25px; cursor: default"
          class="close"
          id="close"
        >
          &times;
        </button>
      </div>
    </div>
    <script>
      document.getElementById("title").innerHTML = document.title;
      // ipc connection between main.js and nav.html buttons to mainpulate the function of the window asynchronously
      const { ipcRenderer } = require("electron");
      const ipc = ipcRenderer;

      const restore = document.querySelector("#restore");
      const maximize = document.querySelector("#maximize");
      const minimize = document.querySelector("#minimize");
      const closeBtn = document.querySelector("#close");

      // close the window
      closeBtn.onclick = function(){
        ipc.send("closeApp");
        console.log('mama earth');
      }
      restore.onclick = function () {
        maximize.style.display = "block";
        restore.style.display = "none";
      };
      maximize.onclick = function () {
        restore.style.display = "block";
        maximize.style.display = "none";
      };
    </script>
  </body>
</html>

I have added inline styles as well as style tag and script tag in the same html document

Problem comes when I am not able to use require('electron') in a script tag. I am trying to make the top window buttons and using the ipcRenderer to process them to main.js.

Main.js :

const { app, BrowserWindow , ipcMain} = require('electron')
const path = require('path')
const ipc = ipcMain

function createWindow() {
  const win = new BrowserWindow({
    width: 1200,
    height: 700,
    center: true,
    minHeight: 700,
    minWidth: 1200,
    frame: false,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation : true,
      devTools: true,
      preload: path.join(__dirname, 'preload.js'),
    }
  })

  win.loadFile('index.html')

  //close window function 
  ipc.on('closeApp', () => {
    console.log('app is closed')
    win.close()
  })
}

app.whenReady().then(() => {
  createWindow()

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })
})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

I have just added the index.html and preload.js for no confussion :

index.html :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
    
    <title>Home</title>

    <link rel="stylesheet" href="style.css" />

    <script src="main.js"></script>

</head>
<body>
    <iframe id="nav-placeholder" src="nav.html" width="100%" style="border: none;height: 35px !important;" loading="eager"></iframe>
    <a href="nav.html">Go to nav page</a>
</body>
</html>

Preload.js :

window.addEventListener('DOMContentLoaded', () => {
    const replaceText = (selector, text) => {
      const element = document.getElementById(selector)
      if (element) element.innerText = text
    }
  
    for (const type of ['chrome', 'node', 'electron']) {
      replaceText(`${type}-version`, process.versions[type])
    }
  })

I tried using require JS but I had no idea how to do it. If anyone has an answer to it or can guide me through the error it would be highly appreciatable!

Thank you in advance!