Having some issue when trying to group objects from nested array of objects

I am trying to group some nested array of objects. On my below data, there is a ‘products’ key property. I am trying to group the products if the vendor.email is the same. After grouping the products I also want to put the paymentDetails key property on each group.

This is my code. I am able to group the products but am not able to set the paymentDetails key and value on each group.

const data= [
        {
            _id: "622d70a49bd88b1599026318",
            products: [
                {
                    _id: "6223186e2278d4e502f5264a",
                    title: "Product number 1",
                    price: 600,
                    cartQuantity: 1,
                    vendor: {email: "[email protected]"}
                },
                {
                    _id: "622d4e9f9bd88b1599026317",
                    title: "asdas",
                    price: 100,
                    cartQuantity: 5,
                    vendor: {
                        email: "[email protected]"
                    }
                },
                 {
                    _id: "622d4e9f9bd88b1599026317",
                    title: "asdas",
                    price: 100,
                    cartQuantity: 5,
                    vendor: {
                        email: "[email protected]"
                    }
                },
            ],
            paymentDetails: {
                createdId: 1647145079,
                date: "Sun Mar 13 2022",
                amount: 700,
                email: "[email protected]",
                last4: "4242",
                transaction: "p"
            },
            status: "Pending",
            billing: {
                country: "BD",
                name: "Md. Fathe Karim",
                phone: "+88010000000",
                line1: "Madhabdi",
                city: "Narshingdi",
                postal_code: "1604",
                state: "Bandarban"
            }
        }]

const mapped = {};                       // MY function
data[0].products.forEach(item => {
  if (item.vendor.email in mapped) return mapped[item.vendor.email].push(item); 
  mapped[item.vendor.email] = [item];
});

const expectedFormat = Object.keys(mapped).map(key => {
  const o = {}; 
  o["orders"] = mapped[key];
  return o; 
});
console.log(expectedFormat)

My expected result is:

[
  {
    "orders": [
      {
        "_id": "6223186e2278d4e502f5264a",
        "title": "Product number 1",
        "price": 600,
        "vendor": {
          "email": "[email protected]"
        }
      }
    ],
    "paymentDetails": {
      createdId: 1647145079,
      amount: 700,
      email: "[email protected]",
    }
  },
  {
    "orders": [
      {
        "_id": "622d4e9f9bd88b1599026317",
        "title": "Product number 2",
        "price": 100,
        "vendor": {
          "email": "[email protected]"
        }
      },
      {
        "_id": "622d4e9f9bd88b1599026317",
        "title": "Product number 3",
        "price": 100,
        "vendor": {
          "email": "[email protected]"
        }
      }
    ],
    "paymentDetails": {
      createdId: 1647145079,
      amount: 700,
      email: "[email protected]",
    }
  }
]

Adding rendercell on Material-UI DataGrid lags the app

If I scroll either to the left or to the right, it lags so much. I can’t also filter or click on the row. How do I fix this and what is happening here?

Codesandbox: https://codesandbox.io/s/controlledfilters-material-demo-sample-qy2qf7?file=/demo.js:2242-3000

{
      field: "cartItems",
      headerName: "Cart Items",
      type: "number",
      width: 400,
      align: "center",
      renderCell: ({ value }) => {
        const t = Object.entries(
          value.reduce((prev, item) => {
            if (!prev[item.id]) prev[item.id] = { ...item, nest: [] };
            prev[item.id].nest.push(item);
            return prev;
          }, {})
        ).map(([id, obj], idx) => (
          <List key={id + obj.color}>
            <ListItemText primary={obj.name + " " + obj.size} />
            <li>
              {obj.nest.map((nest, idx) => (
                <li key={idx}>
                  <ListItemText
                    secondary={nest.color + " (" + nest.quantity + " pcs)"}
                  />
                </li>
              ))}
            </li>
          </List>
        ));
        console.log(t);
        return t;
      }
    },

Matching user-input text with a user-input regex in Node.js

I’m assuming that DoS is a possible issue when matching, on the backend in Node.js, arbitrary strings with arbitrary regexes with one of JS’s regex functions. If the provided regex is simply invalid, the error thrown by the constructor can just be caught — but I’m thinking it’s possible that matching the string with the RegExp could become a significantly or even completely blocking operation, deliberately or accidentally by the creator of the regex and the string? If so, how exactly would this be caused, and how could it be mitigated?

How to match pattern with Id on them react router

I am new to react. I have a route with react router that takes :id as parameter, how do I match this using react-router-dom useLocation.

basically path can be posts or post/21
how do I match post/21 to render a component, I want to render a seperate component if I
am on the detail page

{path === 'post/:id' ? <PostDetail /> : <Posts /> }

but use location returns posts/1 which I can’t use to match the post detail

summary
Any path that matches: post/:id

passing JavaScript variable into a php for loop not working [duplicate]

I am trying to limit a PHP loop based on a variable passed from JavaScript into the for loop as follows, however it doesn’t seem to be working.

</script>
var res =  5;
</script>

<?php
   $xx = "<script>document.writeln(res);</script>";
   echo $xx. " the number echo's fine";
?>

<br>

<?php  
for ($i= 1; $i <= $xx; $i++) {
  echo "The number is: $xx <br>";
}
?>  

Help with a solution would be greatly appreciated and thanks in advance!
I am new to PHP.

Aran

how to make an audio pause on reactjs?

I wanted to know why my audio is not pausing, it plays the normal audio but when I click the pause button it does not pause

const [iconAudio, iconAudioState] = useState(true)
const audio = new Audio(urlmp3)

<div>
                    <div onClick={()=>
                        {
                            iconAudio == true ? audio.play() : audio.pause()
                            iconAudio == true ? iconAudioState(false) : iconAudioState(true) 
                        } 
                    }>
                        {
                            iconAudio == true ? 
                                    <PlayArroyOutlined />
                                : 
                                    <PauseOutlined />
                        }
                    </div>
                </div>

TypeError Cannot read properties of undefined (reading ‘related’)

I am trying to follow a tutorial from someone who created a full website using Adonisjs, almost everything was exactly like showed in the tutorial, exept that the frontend was a little different, but the results were the same.
Now I am trying to get the posts showed in the browser, but when I try I get this error:
TypeError Cannot read properties of undefined (reading ‘related’)
I tried to see if I had mistaken something, but even using the same code used on the tutorial. The error is the same. Here is my code:

import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import State from 'App/Enums/States'
import Post from 'App/Models/Post'
import PostStoreValidator from 'App/Validators/PostStoreValidator'

export default class PostsController {
  public async index({ view, auth, params }: HttpContextContract) {
    const page = params.page ?? 1
    const posts = auth.user!.related('posts').query().paginate(page, 20)
    return view.render('studio/posts/index', { posts })
  }

  public async create({ view }: HttpContextContract) {
    return view.render('studio/posts/create', {})
  }

  public async store({ request, response }: HttpContextContract) {
    const data = await request.validate(PostStoreValidator)

    await Post.create({ stateId: State.PUBLIC, ...data })

    return response.redirect().toRoute('studio.posts.index')
  }
}

But there are a lot more, so I am letting my gthub repositore here, so you can take a look at the entire code. The error shows some typeerror, but I have already tried to copy and paste the same code as gave on the tutorial, but nothing changes…

I hope someone can see what can be causing this error because obviously I can’t.

How is the function in my eventlistener able to receive an event without using function parameters? [duplicate]

I’m working on a very simple game using vanilla JavaScript and the behavior I’m seeing right now goes against everything I’ve learned about with functions. I don’t understand why getInput can be called without the usual parenthesis that you’d use when calling functions. In fact, when I add parenthesis like this: document.addEventListener("keydown", getInput());, it doesn’t work at all.

So then, how am I able to receive and print the event key without it having been passed as a parameter?

document.addEventListener("keydown", getInput);

function getInput() {
    console.log(event.key);
}

Swiper JS Slider next/previous buttons aren’t working perfectly

Hi guys I’m having a bit of trouble using swiper js slides. This is the link of my website having swiper js slider:
https://nyside2.internet.dk/
As you can see in the start the swiper js slider is showing a few parts from the next slide. This is a very big concern for me. Because I want only one slider per view also when I click on the next or previous button I’m having half part of the previous slider and half part of the next slider at the same time. Again this isn’t what I want I want only one slide after clicking the next or previous button.
You can see the code below that I’m using:

<HTML>
<head>
<style>
HTML,body
{position: relative;
  height: 100%;
}
body{
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color:#000;
  margin: 0;
  padding: 0;
}
#Slider .swiper-container {
  width: auto;
  height: 100%;
}
#Slider .swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;
  /* Center slide text vertically */
  display: flex;
  justify-content: center;
  align-items: center;
}

/* reset list */
#Slider ul.swiper-wrapper{
  list-style-type: none;
  padding: 0px;
  margin: 0px;
}

#Slider h2{
  flex-basis: 100%;
}


#Slider .swiper-button-prev,
#Slider .swiper-button-next{
 top: 45%;
 background: none;
 color: #FFFFFF;
 opacity: 0;
}

#Slider .swiper-container:hover .swiper-button-prev{
    opacity: 1.0;
    animation-duration: 1s;
    animation-iteration-count: 1;
    margin-left: 30px;
    animation-name: PreviousSlider;
}

u/keyframes PreviousSlider{
    0%{
    opacity: 1;
    }
    100%{
    opacity: 1;
    transform: translate(30px, 0px);
    }
}


#Slider .swiper-container:hover .swiper-button-next{
    opacity: 1.0;
    animation-duration: 1s;
    animation-iteration-count: 1;
    margin-right: 30px;
    animation-name: NextSlider;
}


u/keyframes NextSlider{
  0%{
    opacity: 1;}
  100%{
    opacity: 1;
    transform: translate(-30px, 0px);}
}

#Slider .h2--small .heading-line--0{
    position: absolute;
    display: block;
    top: 50%;
    margin-left: 20px;
    z-index: 11;
    font-family: futura-pt;
    font-style: Regular;
    text-transform: uppercase;
    height: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 894px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 75px;
    letter-spacing: normal;
    font-size: 60px;
    font-weight: 200;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}

#Slider .h2--small .heading-line--1{
    position: absolute;
    display: block;
    top: 58%;
    margin-left: 20px;
    z-index: 11;
    font-family: futura-pt;
    font-style: Regular;
    text-transform: uppercase;
    height: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 894px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 75px;
    letter-spacing: normal;
    font-size: 60px;
    font-weight: 500;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
} 

#Slider .content_subtitle{
    position: absolute;
    display: block;
    top: 68%;
    margin-left: 20px;
    z-index: 9;
    font-family: futura-pt;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 579px;
    height: 87px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 29px;
    letter-spacing: 0px;
    font-weight: 400;
    font-size: 24px;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}

#Slider .button--inline{
    position: absolute;
    display: block;
    top: 77%;
    margin-left: 20px;
    z-index: 8;
    background-color: rgba(0, 0, 0, 0);
    font-family: "News Cycle";
    text-transform: uppercase;
    height: auto;
    width: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: nowrap;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 23px;
    letter-spacing: 2px;
    font-weight: 700;
    font-size: 20px;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
    border-width: 0px;
    border-radius: 0px;
}

#Slider .button--inline .b8{
    color: #EF8524;
}

#Slider .fa-long-arrow-alt-right:before{
    color: #EF8524;
    text-align: left;
    letter-spacing: 0px;
    font-weight: 400;
}

#Slider .video-overlay{
    margin-top: -759px;
    width: 100%;
    height: 750px;
    position: relative;
    display: flex;
    background: black;
    opacity: 0.5;
}

/* Extra small devices (phones, 600px and down) */
u/media only screen and (max-width: 600px) and (min-width: 360px){
#Slider .swiper-button-prev,
#Slider .swiper-button-next{
display: none;
}

#Slider .h2--small .heading-line--0{
    position: absolute;
    display: block;
    top: 22%;
    margin-left: 20px;
    z-index: 11;
    font-family: futura-pt;
    font-style: Regular;
    text-transform: uppercase;
    height: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 894px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 75px;
    letter-spacing: normal;
    font-size: 25px;
    font-weight: 200;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}    

#Slider .h2--small .heading-line--1{
    position: absolute;
    display: block;
    top: 33%;
    margin-left: 20px;
    z-index: 11;
    font-family: futura-pt;
    font-style: Regular;
    text-transform: uppercase;
    height: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 894px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 75px;
    letter-spacing: normal;
    font-size: 25px;
    font-weight: 500;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}

#Slider .content_subtitle{
    position: absolute;
    display: block;
    top: 53%;
    margin-left: 20px;
    z-index: 9;
    font-family: futura-pt;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 320px;
    height: 87px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 25px;
    letter-spacing: 0px;
    font-weight: 400;
    font-size: 18px;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}

#Slider .button--inline{
    position: absolute;
    display: block;
    top: 84%;
    margin-left: 20px;
    z-index: 8;
    background-color: rgba(0, 0, 0, 0);
    font-family: "News Cycle";
    text-transform: uppercase;
    height: auto;
    width: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: nowrap;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 23px;
    letter-spacing: 2px;
    font-weight: 700;
    font-size: 18px;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
    border-width: 0px;
    border-radius: 0px;
}
}


/***********


/* Small devices (portrait tablets and large phones, 600px and up) */
u/media only screen and (max-width: 768px) and (min-width: 600px){
#Slider .swiper-button-prev,
#Slider .swiper-button-next{
 top: 35%;
 background: none;
 color: #FFFFFF;
 opacity: 0;
}

#Slider .h2--small .heading-line--0{
    position: absolute;
    display: block;
    top: 40%;
    margin-left: 20px;
    z-index: 11;
    font-family: futura-pt;
    font-style: Regular;
    text-transform: uppercase;
    height: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 894px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 75px;
    letter-spacing: normal;
    font-size: 50px;
    font-weight: 200;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}

#Slider .h2--small .heading-line--1{
    position: absolute;
    display: block;
    top: 53%;
    margin-left: 20px;
    z-index: 11;
    font-family: futura-pt;
    font-style: Regular;
    text-transform: uppercase;
    height: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 894px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 75px;
    letter-spacing: normal;
    font-size: 50px;
    font-weight: 500;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
} 

#Slider .content_subtitle{
    position: absolute;
    display: block;
    top: 68%;
    margin-left: 20px;
    z-index: 9;
    font-family: futura-pt;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 579px;
    height: 87px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 29px;
    letter-spacing: 0px;
    font-weight: 400;
    font-size: 24px;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}

#Slider .button--inline{
    position: absolute;
    display: block;
    top: 85%;
    margin-left: 20px;
    z-index: 8;
    background-color: rgba(0, 0, 0, 0);
    font-family: "News Cycle";
    text-transform: uppercase;
    height: auto;
    width: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: nowrap;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 23px;
    letter-spacing: 2px;
    font-weight: 700;
    font-size: 20px;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
    border-width: 0px;
    border-radius: 0px;
}

#Slider .button--inline .b8{
    color: #EF8524;
}
}

/* For tablet devices 768px to 992px */
u/media only screen and (max-width: 992px) and (min-width: 768px){
#Slider .swiper-button-prev,
#Slider .swiper-button-next{
 top: 38%;
 background: none;
 color: #FFFFFF;
 opacity: 0;
}

#Slider .h2--small .heading-line--0{
    position: absolute;
    display: block;
    top: 45%;
    margin-left: 20px;
    z-index: 11;
    font-family: futura-pt;
    font-style: Regular;
    text-transform: uppercase;
    height: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 894px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 75px;
    letter-spacing: normal;
    font-size: 60px;
    font-weight: 200;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}

#Slider .h2--small .heading-line--1{
    position: absolute;
    display: block;
    top: 58%;
    margin-left: 20px;
    z-index: 11;
    font-family: futura-pt;
    font-style: Regular;
    text-transform: uppercase;
    height: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 894px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 75px;
    letter-spacing: normal;
    font-size: 60px;
    font-weight: 500;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
} 

#Slider .content_subtitle{
    position: absolute;
    display: block;
    top: 72%;
    margin-left: 20px;
    z-index: 9;
    font-family: futura-pt;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 579px;
    height: 87px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 29px;
    letter-spacing: 0px;
    font-weight: 400;
    font-size: 24px;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}

 .button--inline{
    position: absolute;
    display: block;
    top: 85%;
    margin-left: 20px;
    z-index: 8;
    background-color: rgba(0, 0, 0, 0);
    font-family: "News Cycle";
    text-transform: uppercase;
    height: auto;
    width: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: nowrap;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 23px;
    letter-spacing: 2px;
    font-weight: 700;
    font-size: 20px;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
    border-width: 0px;
    border-radius: 0px;
}

.button--inline .b8{
    color: #EF8524;
}
}

/* Large devices (laptops/desktops, 992px and up) */
u/media only screen and (max-width: 1200px) and (min-width: 992px) {
#Slider .swiper-button-prev,
#Slider .swiper-button-next{
 top: 45%;
 background: none;
 color: #FFFFFF;
 opacity: 0;
}

#Slider .h2--small .heading-line--0{
    position: absolute;
    display: block;
    top: 50%;
    margin-left: 20px;
    z-index: 11;
    font-family: futura-pt;
    font-style: Regular;
    text-transform: uppercase;
    height: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 894px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 75px;
    letter-spacing: normal;
    font-size: 60px;
    font-weight: 200;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}

#Slider .h2--small .heading-line--1{
    position: absolute;
    display: block;
    top: 58%;
    margin-left: 20px;
    z-index: 11;
    font-family: futura-pt;
    font-style: Regular;
    text-transform: uppercase;
    height: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 894px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 75px;
    letter-spacing: normal;
    font-size: 60px;
    font-weight: 500;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
} 

#Slider .content_subtitle{
    position: absolute;
    display: block;
    top: 68%;
    margin-left: 20px;
    z-index: 9;
    font-family: futura-pt;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: normal;
    width: 579px;
    height: 87px;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 29px;
    letter-spacing: 0px;
    font-weight: 400;
    font-size: 24px;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
}

#Slider .button--inline{
    position: absolute;
    display: block;
    top: 77%;
    margin-left: 20px;
    z-index: 8;
    background-color: rgba(0, 0, 0, 0);
    font-family: "News Cycle";
    text-transform: uppercase;
    height: auto;
    width: auto;
    color: rgb(255, 255, 255);
    text-decoration: none;
    white-space: nowrap;
    min-height: 0px;
    min-width: 0px;
    max-height: none;
    max-width: none;
    text-align: left;
    line-height: 23px;
    letter-spacing: 2px;
    font-weight: 700;
    font-size: 20px;
    transform-origin: 50% 50%;
    opacity: 1;
    transform: translate(0px, 0px);
    visibility: visible;
    border-width: 0px;
    border-radius: 0px;
}

#Slider .button--inline .b8{
    color: #EF8524;
} 



</style>
</head>
<body>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/swiper-bundle.min.css">
<!-- Slider main container -->
<div class="swiper-container">
  <!-- Additional required wrapper -->
  <ul class="swiper-wrapper">
    <!-- Slides -->
    <li class="swiper-slide">
    <div>
        <video 
source src="//nyside2.internet.dk/wp-content/uploads/2022/03/moviefront720.mp4" type="video/mp4" lazyload="//nyside2.internet.dk/wp-content/uploads/2022/03/moviefront720.mp4" ></video>
    <div class="video-overlay"> </div>
    <h2 class="h2 content-copy__title h2--small"><span class="heading-line heading-line--0">Forretningsorienteret</span>
    <span>
        <strong class="heading-line heading-line--1">
            bureau
        </strong>
    </span>
    </h2>
        <div class="b2 b2--spread content_subtitle">
            <p>
                Stærkt team med fokus på strategi og kreativitet der engagere og aktiver mennesker på deres kunderejse
            </p>
        </div>
    <div class="button hero-content-cta z4 button--inline">
            <a href="https://nyside2.internet.dk/?page_id=37">
                <span class="b8 z2">
                Se hvordan vi gør 
                </span>
                <i class="fas fa-long-arrow-alt-right">
                </i>
            </a>
        </div>
    </div>
    </li>
    <li class="swiper-slide">
      <div>
        <video source src="//nyside2.internet.dk/wp-content/uploads/2022/03/Frontmovie2_720.mp4" type="video/mp4" lazyload="//nyside2.internet.dk/wp-content/uploads/2022/03/Frontmovie2_720.mp4"></video>
        <div class="video-overlay"></div>
        <h2 class="h2 content-copy__title h2--small"><span class="heading-line heading-line--0">Fra kr. 2.980,- / mdr.</span>
        <span>
            <strong class="heading-line heading-line--1">
                Den fulde løsning
            </strong>
        </span>
        </h2>
        <div class="b2 b2--spread content_subtitle">
            <p>
                Nyt kreativt webdesign, der løfter din virksomhed og øger effekten af din indsats
            </p>
        </div>
    <div class="button hero-content-cta z4 button--inline">
            <a href="https://nyside2.internet.dk/about/">
                <span class="b8 z2">
                Interesseret - så klik 
                </span>
                <i class="fas fa-long-arrow-alt-right">
                </i>
            </a>
    </div>

      </div>
    </li>
  </ul>

  <!-- If we need navigation buttons -->
  <div class="swiper-button-prev"></div>
  <div class="swiper-button-next"></div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://unpkg.com/[email protected]/swiper-bundle.min.js"></script>
<script>
var swiper = new Swiper('.swiper-container', {
  loop: true,
  slidesPerView: 1,
  centeredSlides: true,
  autoplay: {
    delay: 5000,
    autoplayDisableOnInteraction: false,  
  },
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },

 /* ON INIT AUTOPLAY THE FIRST VIDEO */
  on: {
    init: function () {
      console.log('swiper initialized');
      var currentVideo =  $("[data-swiper-slide-index=" + this.realIndex + "]").find("video");
      currentVideo.trigger('play');
    },
  },
});

/* GET ALL VIDEOS */
var sliderVideos = $(".swiper-slide video");

/* SWIPER API - Event will be fired after animation to other slide (next or previous) */
swiper.on('slideChange', function () {
  console.log('slide changed');
  /* stop all videos (currentTime buggy without this loop idea - no "real" previousIndex) */
  sliderVideos.each(function( index ) {
    this.currentTime = 0;
  });

  /* SWIPER GET CURRENT AND PREV SLIDE (AND VIDEO INSIDE) */
  var prevVideo =  $("[data-swiper-slide-index=" + this.previousIndex + "]").find("video");
  var currentVideo =  $("[data-swiper-slide-index=" + this.realIndex + "]").find("video");
  prevVideo.trigger('stop');
  currentVideo.trigger('play');
});
</script>
</body>
</html>

I am building a twitter clone with react.js. And I was adding icons by passing in the function but when i call it in the function the page goes blank

my app works fine when it’s like this:

function SidebarOption({ text, Icon }) {
  return (
    <div >
        <h2>{text}</h2>      
    </div>
  )
}

but when i add th <Icon/> like below the page goes blank

function SidebarOption({ text, Icon }) {
  return (
    <div >
        <h2>{text}</h2>
        <Icon /> {*when I add this the app page goes blank*}
    </div>
  )
} 

I have tried setting the “Homepage”:”.” but that didn’t work.

Can’t get cookie during _app initialization with getInitialProps

I’m using next-cookies to store auth credentials from user session, however, I can’t get them during app initialization -let’s say, the user refreshes the page or comes back later-, however, after app has been initialized -or user has loged in-, I get them navigating in the app.

This is important, because I want to fetch some initial data to be available in to the redux store from the beginning.

// pages/_app.js

import { useStore } from '../store/store';
import nextCookie from 'next-cookies';


    function MyApp({ Component, pageProps }) {
      const Layout = Component.layout || MainLayout;
      const store = useStore(pageProps.initialReduxState); // custom useStore method to init store
      const pageTitle = Component.title || pageProps.title || 'Título de la página';
    
      return (
        <Provider store={store}>
          <Layout pageTitle={pageTitle}>
            <Component {...pageProps} />
          </Layout>
        </Provider>
      );
    }
    
    export default MyApp;
    
    MyApp.getInitialProps = async (ctx) => {
      const { token, user } = nextCookie(ctx);
      /* TO DO
        the idea is to get cookie from the server side
        and pass it to the client side, if the cookie is
        active, initial data will be triggered from the
        initializers
      */
    
      return { pageProps: { token, user } };
    };

Check it out:

enter image description here

Is it a better way or native option to get the cookie without having to a different cookie dependency?

Btw, I already have a middleware that protects routes from non authenticated user which works fine:

// pages/_middleware.js

export function middleware(req) {
  const activeSession = req.headers.get('cookie');
  const url = req.nextUrl.clone();

  if (activeSession) {
    if (req.nextUrl.pathname === '/login') {
      url.pathname = '/';
      return NextResponse.redirect(url);
    }
    return NextResponse.next();
  }

  url.pathname = '/login';
  return NextResponse.rewrite(url);
}

Best way to debug javascript while there is no error message for reading non-existing field from an object

const ball = {
    x: canvas.width / 2,
    y: canvas.height / 2,
    size: 10,
    speed: 4,
    dx: 4,
    dy: -4
}

// draw ball on canvas 
function drawBall() {
    ctx.beginPath();
    ctx.arc(ball.x, ball.y, ball.xize, 0, Math.PI * 2);
    ctx.fillStyle = '#0095dd';
    ctx.fill();
    ctx.closePath();
}

I’m trying to draw a ball using canvas.

ctx.arc(ball.x, ball.y, ball.xize, 0, Math.PI * 2);

This line calls arc() and tries to read ball.size by access ball.xize. It’s a typo.
In languages I’m familiar with, typos like this result in error messages that can help quickly identify the cause. There is none with javascript. What is the canonical way to debug javascript in such cases? Do we have to read and verify each and every line like what I did here?