Why is a matrix3d transformation scale snapping back to original position in google chrome?

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Level Two</title>
</head>

<body>
    
<div id="interface">
    
<div id="welcomeToLevelTwo" onclick="navigateLevelTwo()">
    
Click To Navigate Level 
</div>  
    
    
</div>  
    
<script>
function navigateLevelTwo(){
    
    document.getElementById('interface').innerHTML='<div id="mySpaceShip"><svg id="spaceShipEntry" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" width="1000" height="1000" viewBox="0 0 1296 1728"><defs><style>.cls-1,.cls-14,.cls-2{fill:#fff;}.cls-1,.cls-10,.cls-11,.cls-12,.cls-13,.cls-14,.cls-15,.cls-2,.cls-8,.cls-9{stroke:#000;}.cls-1,.cls-10,.cls-11,.cls-12,.cls-13,.cls-14,.cls-15,.cls-16,.cls-2,.cls-8,.cls-9{stroke-miterlimit:10;}.cls-1,.cls-9{stroke-width:1.24px;}.cls-2{stroke-width:0.38px;}.cls-3{font-size:100px;font-family:MyriadPro-Regular, Myriad Pro;}.cls-4{letter-spacing:-0.01em;}.cls-5{letter-spacing:0.01em;}.cls-6{letter-spacing:0em;}.cls-7{letter-spacing:0.01em;}.cls-10,.cls-8,.cls-9{fill:blue;}.cls-8{stroke-width:1.04px;}.cls-10{stroke-width:0.93px;}.cls-11,.cls-12,.cls-13{fill:#ed1e79;}.cls-11{stroke-width:0.92px;}.cls-12{stroke-width:1.09px;}.cls-13{stroke-width:0.82px;}.cls-14{stroke-width:1.76px;}.cls-15,.cls-16{fill:#006837;}.cls-15{stroke-width:1.33px;}.cls-16{stroke:lime;stroke-width:0.86px;}</style></defs><g id="rightSpikesEntry"><polygon class="cls-1" points="780.64 726.25 320.16 372.43 912.06 738.47 780.64 726.25"/><polygon class="cls-1" points="908.87 735.79 448.39 381.97 1040.29 748.02 908.87 735.79"/><polygon class="cls-1" points="1037.09 745.33 576.62 391.51 1168.52 757.56 1037.09 745.33"/><polygon class="cls-1" points="781.63 737.56 290.82 1047.94 913.62 737.37 781.63 737.56"/><polygon class="cls-1" points="910.19 739.75 419.38 1050.13 1042.18 739.55 910.19 739.75"/><polygon class="cls-1" points="1038.75 741.93 547.94 1052.31 1170.74 741.74 1038.75 741.93"/><polygon class="cls-1" points="1164.4 741.72 703.92 387.9 1295.82 753.95 1164.4 741.72"/><polygon class="cls-1" points="1292.62 751.26 832.15 397.44 1424.05 763.49 1292.62 751.26"/><polygon class="cls-1" points="1165.38 753.03 674.57 1063.41 1297.38 752.84 1165.38 753.03"/><polygon class="cls-1" points="1293.95 755.22 803.14 1065.6 1425.94 755.02 1293.95 755.22"/><polygon class="cls-1" points="1422.51 757.4 931.7 1067.78 1554.5 757.21 1422.51 757.4"/></g><g id="leftSpikesEntry"><polygon class="cls-1" points="466.07 717.21 926.54 1071.03 334.64 704.98 466.07 717.21"/><polygon class="cls-1" points="337.84 707.66 798.32 1061.48 206.42 695.44 337.84 707.66"/><polygon class="cls-1" points="209.62 698.12 670.09 1051.94 78.19 685.89 209.62 698.12"/><polygon class="cls-1" points="465.08 705.89 955.89 395.51 333.09 706.09 465.08 705.89"/><polygon class="cls-1" points="336.52 703.71 827.33 393.33 204.53 703.9 336.52 703.71"/><polygon class="cls-1" points="207.96 701.52 698.77 391.14 75.97 701.72 207.96 701.52"/><polygon class="cls-1" points="82.31 701.73 542.79 1055.56 -49.11 689.51 82.31 701.73"/><polygon class="cls-1" points="-45.91 692.19 414.56 1046.01 -177.34 679.97 -45.91 692.19"/><polygon class="cls-1" points="81.32 690.42 572.13 380.04 -50.67 690.62 81.32 690.42"/><polygon class="cls-1" points="-47.24 688.24 443.57 377.86 -179.23 688.43 -47.24 688.24"/><polygon class="cls-1" points="-175.8 686.05 315.01 375.67 -307.79 686.25 -175.8 686.05"/></g><polygon class="cls-2" points="1296.5 1702.2 1.5 1702.2 1.5 1054.66 506.5 1012.9 804 1012.55 1296.5 1054.66 1296.5 1702.2"/><text class="cls-3" transform="translate(24.22 1671.09)"><tspan class="cls-4">L</tspan><tspan x="45.7" y="0">uc</tspan><tspan class="cls-5" x="145.6" y="0">k</tspan><tspan x="193.8" y="0">y </tspan><tspan class="cls-6" x="262.09" y="0">G</tspan><tspan x="327.19" y="0">old </tspan><tspan class="cls-7" x="483.29" y="0">G</tspan><tspan x="548.69" y="0">aming</tspan></text><g id="blue" onclick="startSpaceShipEntry()"><rect class="cls-8" x="704.65" y="1288.48" width="37.57" height="144"/><rect class="cls-9" x="669.17" y="1110.57" width="60.52" height="79.3"/><polygon class="cls-9" points="771.96 1318.22 786.04 1302.57 779.78 1254.04 742.22 1196.13 743.78 1250.91 764.13 1263.43 771.96 1318.22"/><polygon class="cls-9" points="601.17 1165.74 614.54 1152.55 624.2 1215.77 660.83 1196.13 660.83 1244.13 608.46 1226.56 601.17 1165.74"/><rect class="cls-8" x="660.83" y="1311.96" width="37.57" height="144"/><rect class="cls-10" x="660.83" y="1196.13" width="81.39" height="118.96"/><polygon class="cls-9" points="645.17 1045.87 701.52 1111.61 751.61 1042.74 701.17 1107.09 645.17 1045.87"/></g><g id="pink"><rect class="cls-11" x="961.68" y="1283.78" width="33.06" height="126.72"/><rect class="cls-12" x="930.45" y="1127.22" width="53.26" height="69.79"/><polygon class="cls-12" points="1020.9 1309.95 1033.3 1296.18 1027.79 1253.48 994.73 1202.52 995.12 1237.47 1014.02 1261.74 1020.9 1309.95"/><polygon class="cls-12" points="870.61 1175.77 882.38 1164.16 890.88 1219.8 923.11 1202.52 924.1 1230.74 877.02 1229.29 870.61 1175.77"/><rect class="cls-11" x="923.11" y="1304.44" width="33.06" height="126.72"/><rect class="cls-13" x="923.11" y="1202.52" width="71.62" height="104.68"/><polygon class="cls-12" points="909.33 1070.29 958.92 1128.14 1003 1067.53 958.61 1124.16 909.33 1070.29"/></g><g id="frontOfShip"><polygon class="cls-14" points="668.57 757.53 577.24 757.46 547.65 729.28 570.82 695.83 677.92 696.81 697.12 729.28 668.57 757.53"/><polygon class="cls-14" points="555.91 738.53 547.65 729.28 563.52 697.7 684.25 698.19 698.35 728.36 688.96 736.58 626.08 729.28 555.91 738.53"/><polyline class="cls-14" points="578.33 757.03 626.08 729.56 669.24 756.44"/><g id="opacityEntry"><path class="cls-15" d="M542.61,696l4.67-3.8c17.43-4.8,43.19-15.45,81.62-15.29,29,.11,57,8.1,72.86,11.63,1.11,16.35-.61-8.91.5,7.44Z"/><polygon class="cls-15" points="681.08 696.42 696.39 721.71 702.26 695.99 681.08 696.42"/><polygon class="cls-15" points="542.61 696.64 549.26 723.27 565.89 696.42 542.61 696.64"/><polygon class="cls-16" points="594.98 689.8 619.33 689.44 619.33 684.45 619.34 678.77 594.98 689.8"/><line class="cls-16" x1="633.45" y1="685.61" x2="619.05" y2="685.72"/><polyline class="cls-16" points="627.53 693.8 650.41 693.8 650.41 684.08 627.53 693.8 627.21 682.65"/></g></g></svg></div>';
    
    
}   
    
function startSpaceShipEntry(){
    
    document.getElementById('rightSpikesEntry').style.transition='transform 3s';
    document.getElementById('leftSpikesEntry').style.transition='transform 3s';
    document.getElementById('frontOfShip').style.transition='transform 3s';
    document.getElementById('frontOfShip').style.transform="matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,.5)";
    
    
    /*document.getElementById('rightSpikesEntry').style.transform="matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,310,0,0,1)";document.getElementById('leftSpikesEntry').style.transform="matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,-310,0,0,1)";*/
    
    
}   
</script>   
</body>
</html>

Click the to navigate text, and the click the blue character to recreate the issue of the object snapping back to original position after a matrix3d transformation in startSpaceShipEntry(). I noticed this was the case only when I added a scale, it wasn’t an issue when I was manipulating just the x and y values. It works fine in Firefox, and has worked PERFECTLY in the past in google chrome. Has there been any recent changes to effect this on chrome?

Syntax Error to import components react native

I tried to import components from a separate file in react native learning but they all get errors, I’ve looked for solutions in several forums and communities but I can’t find a solution, is there something wrong with my syntax?

the Problem :
this is my problem at my project can you help some one solution,

ERROR  [Error: undefined Unable to resolve module ./src/Components/MenuBar from D:PROGRAMMINGBelajarJavaScriptReact Navivekesehatan_uiApp.js:
None of these files exist:
  * srcComponentsMenuBar(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)  * srcComponentsMenuBarindex(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)  1 | import React, { useState, useEffect } from "react";
  2 | import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
> 3 | import MenuBar from "./src/Components/MenuBar";
    |                      ^
  4 | const App = () => {
  5 |   const mainBlue = "#0082F7";
  6 |   const mainBlack = "#34354e";]
error: Error: Unable to resolve module ./src/Components/MenuBar from D:PROGRAMMINGBelajarJavaScriptReact Navivekesehatan_uiApp.js: 

App.js

this is my code in App. js I have imported the file correctly in the directory that has been pointed to, namely MenuBar.js but still error

import React, { useState, useEffect } from "react";
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
import MenuBar from "./src/Components/MenuBar";
const App = () => {
  const mainBlue = "#0082F7";
  const mainBlack = "#34354e";
  return (
    <View style={{ flex: 1 }}>
      <View style={{ flex: 1 }}></View>
      <MenuBar />
    </View>
  );
};
const styles = StyleSheet.create({
  iconBtn: {
    alignItems: "center",
    justifyContent: "center",
    // backgroundColor: "blue",
    flex: 1,
  },
});

export default App;

on MenuBar.js

import React from "react";
import { Text, View } from "react-native";
import Icon from "react-native-vector-icons/Ionicons";

const MenuBar = () => {
  return (
    <View
      style={{
        flexDirection: "row",
        backgroundColor: "#fff",
        elevation: 3,
        paddingTop: 10,
        paddingBottom: 10,
      }}
    >
      <TouchableOpacity style={styles.iconBtn}>
        <Icon name="home" size={22} color={mainBlue} />
        <Text style={{ fontSize: 12, color: mainBlue }}>Home</Text>
      </TouchableOpacity>
      <TouchableOpacity style={styles.iconBtn}>
        <Icon name="calendar" size={22} color={mainBlack} />
        <Text style={{ fontSize: 12, color: mainBlack }}>Jadwal</Text>
      </TouchableOpacity>
      <TouchableOpacity style={styles.iconBtn}>
        <Icon name="chatbubble-ellipses" size={22} color={mainBlack} />
        <Text style={{ fontSize: 12, color: mainBlack }}>Pesan</Text>
      </TouchableOpacity>
      <TouchableOpacity style={styles.iconBtn}>
        <Icon name="person" size={22} color={mainBlack} />
        <Text style={{ fontSize: 12, color: mainBlack }}>Profile</Text>
      </TouchableOpacity>
    </View>
  );
};

export default MenuBar;


[myDirectory][1]

Syntax Error

bcrypt.compare isn’t using the arguments I’m providing

I have a function that compares the email and password of the one provided on a sign in page. The function finds one document in a database with the provided email, then compares the password using bcrypt.compare(). The only problem is I keep getting the error UnhandledPromiseRejectionWarning: Error: data and hash arguments required. Below is my function, any ideas why I’m getting the error? I have a feeling it has something to do with bcrypt trying to compare the passwords before the document is found:

const validateLogin = () => {
        Dev.findOne({ email: providedEmail }).then(
            async (devBody) => {

                if (
                    await bcrypt.compare(
                        providedPassword,
                        stringifiedBody.password
                    )
                ) {
                    console.log("That's them!");
                }
            }
        );
    };

Note: providedEmail and providedPassword are both variables assigned to req.body which gets the inputs provided by the user.

Making a clock that takes 2560ms to complete a revolution in JavaScript

I’m trying to make a clock for a Libet task – a cognitive task used by psychologists. By convention these clocks take 2560 ms to complete a revolution. Mine seems to be running quite a lot slower and I can figure out why.

I have made an example of the issue here: https://jsfiddle.net/Sumoza/re4v7Lcj/8/

On each iteration of a setInterval with a 1ms delay, I increase the angle of rotation of the hand by (Math.PI*2)/2560, i.e. 1/2560th of a circle in radians. So, incrementing one of these each ms should complete the circle in that number of ms. As you can see from the clock, this runs a fair bit slower. Can anyone shed any light as to why. Interestingly, *10 seems to look a lot closer to what I want – but that doesn’t make much sense to me so I’m wary of the fix. Relevant JS from the fiddle below. Thanks for any help.

var time = 0;
var rad_tick = (Math.PI*2)/2560; //radians per tick: last number is ms per revolution

// Draw Clock
const clock = document.getElementById('clock')
const clock_ctx = clock.getContext('2d')
clock_ctx.translate(clock.width/2, clock.height/2);
radius = (clock.height/2) * 0.7;

function drawClock() {
    clock_ctx.clearRect(-clock.width/2, -clock.height/2, clock.width, clock.height);
    clock.style.backgroundColor = 'transparent'; 
    clock_ctx.beginPath();
    clock_ctx.arc(0, 0, radius, 0 , 2 * Math.PI);
    clock_ctx.stroke();
}

drawClock();

// Draw Hand
const hand = document.getElementById('hand')
const hand_ctx = hand.getContext('2d')
hand_ctx.translate(hand.width/2, hand.height/2);

function drawHand(time){
    hand_ctx.clearRect(-hand.width/2, -hand.height/2, hand.width, hand.height);
    hand_ctx.beginPath();
    hand_ctx.moveTo(0,0);
    hand_ctx.rotate(time);
    hand_ctx.lineTo(0, -radius*0.9);
    hand_ctx.stroke();
    hand_ctx.rotate(-time);
}

function drawTime(){
    time+=rad_tick;//*10
    drawHand(time)
}

var intervalId = setInterval(drawTime, 1);

How do you call a function inside a module.exports = function () in another class?

In the following example, simply putting module.exports = {save} on the jsFileName.js file functions is not an option here, due to limitations on my codebase. Is this possible to access the function from the export, inside of callFunctionFromAboveFile.js shown below? See the below example of how I’d like to access that function. I’ve searched all the other answers to questions similar but they all mention using the exports differently as I stated in my first line above.

If there is a way to access it as it is shown, please share your answer or details as to why it’s not possible. Also, other ways to handle this would be helpful but I can’t change the class up much given the limitation to the codebase.

jsFileName.js

module.exports = function (JsFileName) {
    JsFileName.save = function (stuff) {}
}

callFunctionFromAboveFile.js

const JsFileName = require('jsFileName');
// TODO I'm not sure how this would call the save() w/out using exports differently.
// TODO I have to use exports as I've posted it in jsFileName.js

Send data from QR scanning client to server

I’m new to fetch/post/get thing and trying to figure out a way to solve this problem.
Currently i have a client that is a QR scanner.
This qr scanner digests a link and splits it into variables. These variables are then supposed to be sent to the proxy which in turn requests from the server. This in turn will return specific information based on the variables from the server to the proxy. this information will then be sent from proxy to client and later be displayed on the same page the QR scanner is initiated from.

The proxy is run on localhost:9094 and the client is run on localhost:3000

The issue i’m having is that I can’t seem to find a way send over my variables from the client to the proxy.

My QR client:

//OnScan this method is called
handleScan = data => {
if (data) {
    //Splitting the link 
    const trailingData = data.split(/[?]/).pop();
    let arr = trailingData.split(/.w+=/).filter(Boolean);

    //Sending the array of variables to another function
    this.getOutletInfo(arr);
    
  }
}

getOutletInfo(arr)
{
fetch('http://localhost:9094/getOutletInfo',{mode:'cors'},
  {
      method: "GET",
      data: {
        outletId: arr[3],
        providerCode: arr[1]
      }
  })
  .then(function(response) {
    return response.json();
  })
  .then(function(myJson) {
    console.log(myJson);
  });
}

The proxy:::

 let app = require('express')();
 let server = require('http').Server(app);
 app.use(bodyParser.json());       // to support JSON-encoded bodies
 app.use(methodOverride()); 
 server.listen('9094', 'localhost', function () {
     console.log("App listening on port 9094");
 });

  //..code..

 //Should be app.post but is .get for now. When sending request to server with the 
 //message below, the response shall be added to the client that is run on 
 //localhost:3000.
 app.get('/getOutletInfo', function (req, res) {
    res.header('Access-Control-Allow-Origin', '*');
    let message = {
        "outletId": req.body.outletId,
        "providerCode": req.body.providerCode
    };
    console.log("DEBUG" + " " + req.outletId);
    //This method below handles the connection between proxy and server - works as 
    //intended
    handleSynchronousRequest(message, "APP_GET_OUTLET_STATUS_REQUEST", res);
});

Help and explanation would be highly appreciated!

How to enable and disable google analytics in Next.js app?

I’ve enabled google analytics using the following script method in my _app.js.

<Script src={`https://www.googletagmanager.com/gtag/js?id=${myMeasurementId}`} strategy='afterInteractive' />
<Script id="google-analytics" strategy='afterInteractive'>
      {`
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', '${myMeasurementId}');
      `}
</Script>

I also created the following two functions:

export const pageview = (url, origin) => {
  console.log("pageView sent");
  window.gtag('config', myMeasurementId, {
      path_url: url,
  })
}

export const event = ({ action, category, label, value }) => {
  window.gtag('event', action, {
    event_category: category,
    event_label: label,
    value: value,
  })
}

“pageview” notifies google analytics whenever a user views a page and “event” can be called along with any react event such as onClick or onSubmit.

This all works to enable google analytics but I’d like to be able to disable it if a user decides to opt out.

Referencing this https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out I’ve tried adding {window[‘ga-disable-GA_MEASUREMENT_ID’] = true;} inside the id=”google-analytics” script tag to no avail. I still see the page_view event in my Google Analytics debugger plugin. I also still see the event registered in https://tagassistant.google.com/ and on google analytics itself. Considering privacy laws in the EU I would imagine there is a relatively simple way to disable and enable google analytics but I’ve you to find a good solution. If anyone knows, please lend a hand!

React library peer dependency conflict

I’m creating a small library to power a few of my projects.

I found that i was getting issues inside the client apps with multiple conflicting versions of react when importing my library. This led me to setting both react and react-dom under peer dependencies in the library package.json which fixed the problem.

However, I am trying to run a sandbox environment via a webpack bundler to test and play with components within the library repo as i am working on it (instead of using npm link), and now I am having an issue whereby react is no longer being detected as a local dependency.

Here is my webpack config.
FWIW, when building out the components for production use I am exporting modules via tsconfig, and not using webpack at all. But i’m finding it difficult to resolve this situation of maintaining a test environment :/

const path = require('path');
const webpack = require('webpack');
const HtmlWebPackPlugin = require('html-webpack-plugin');

const isDevelopment = process.env.NODE_ENV !== 'production';

module.exports = {
  mode: isDevelopment ? 'development' : 'production',
  entry: path.resolve(__dirname, './sandbox/web/index.tsx'),
  module: {
    rules: [
      {
        test: /.tsx?$/,
        exclude: /node_modules/,
        use: ['babel-loader', 'ts-loader'],
      },
      {
        test: /.(s(a|c)ss)$/,
        use: ['style-loader', 'css-loader', 'sass-loader'],
      },
      {
        test: /.svg?$/,
        loader: 'svg-url-loader',
        options: {
          limit: 10000,
        },
      },
    ],
  },
  resolve: {
    extensions: ['.js', '.jsx', '.tsx', '.ts'],
    alias: {
      src: path.resolve(__dirname, 'src'),
      components: path.resolve(__dirname, 'src/components'),
      hooks: path.resolve(__dirname, 'src/hooks'),
      themes: path.resolve(__dirname, 'src/themes'),
      types: path.resolve(__dirname, 'src/types'),
      utils: path.resolve(__dirname, 'src/utils'),
      'react-native$': 'react-native-web',
    },
  },
  output: {
    path: path.resolve(__dirname, './sandbox/web'),
    filename: 'bundle.js',
  },
  devtool: 'inline-source-map',
  watchOptions: {
    poll: true,
    ignored: '/node_modules/',
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: path.resolve(__dirname, './sandbox/web/index.html'),
      filename: 'index.html',
    }),
    new webpack.IgnorePlugin({
      resourceRegExp: /^./native$/,
      contextRegExp: /src$/,
    }),
  ],
  devServer: {
    historyApiFallback: {
      index: '/',
    },
  },
};

A single payload.js for all nuxt generate’d routes when data is the same

I have a NuxtJS site with only one page /pages/matrix/index.vue but quite a lot of dynamic routes pointing to this page, each route using the same set of data. When generating a static build for deployment on Netlify, the dist folder currently reaches ~1.2 GB, consisting of

  • 3125 .html files in dist/matrix (occupying ~39% of the space)
  • 3125 folders for payload.js files in dist/_nuxt/static/[random]/matrix/ in subfolders for routes (occupying ~61% of the space)

Those 61% are 3125 copies of a 220kB payload.js with exactly the same set of data: [{}], while only the route changes:

__NUXT_JSONP__("/matrix/place2/time3,time14,time29", (function(a, b, ...) {
    return {
        data: [{ /* data does not change */ }],
        fetch: {},
        mutations: void 0
    }
}("nor", "does", "this")));

I wonder if there is a way to reduce this redundancy by somehow extracting the data part? Reducing ~665 MB to just 220kB sounds alluring.

Some more background:

Routes are /matrix, /matrix/place1 or /matrix/place8/time1,time7,time18. When generating, I pull all data from a headless CMS and feed it to my page component via the payload option. First, I used File System Routing and imported the pages/matrix/index.vue like this:

// pages/matrix/_places/index.vue
<script>
  import Index from '../index'
  export default Index
</script>

which felt wrong but worked. I blamed this approach to the “duplication” of those payload files (frankly without completely understanding the mechanics of static generation). I now switched to extendRoutes with this nuxt.config.js setting:

router: {
  extendRoutes (routes, resolve) {
    routes.push(
      {
        name: 'matrix-place-times',
        path: '/matrix/:place/:times',
        component: resolve(__dirname, 'pages/matrix/index.vue')
      },
      {
        name: 'matrix-place',
        path: '/matrix/:place',
        component: resolve(__dirname, 'pages/matrix/index.vue')
      }
    )
  }
}

The amount of payload files spread across route subfolders stays the same.
Any advice on this? Using Nuxt v2.15.7.

Converting 1 array of objects into a nested array of array of objects

Say I have this:

var arr = [
    {type:"orange", title:"First"},
    {type:"orange", title:"Second"},
    {type:"banana", title:"Third"},
    {type:"banana", title:"Fourth"}
];

And I’d like to get to this.

[[{type:"orange", title:"First"},
{type:"orange", title:"Second"}],

[{type:"banana", title:"Third"},
{type:"banana", title:"Fourth"}]]

I’ve seen a lot for getting to this:

{orange: 
[[{type:"orange", title:"First"},
{type:"orange", title:"Second"}], 
banana: 
[{type:"banana", title:"Third"},
{type:"banana", title:"Fourth"}]}

But it doesn’t help my situation, I need it to be arrays inside an array.
Any help will be greatly appreciated

destructure property row 0 in react redux

Hope you all are doing well, I am new to Redux, I can do dispatch function without parameters but I never dispatch functions with parameters , I am trying to implement my redux method but it is occurring an error

enter image description here

Here is the code of Action

productAction.js

import axios from 'axios';
import {
    GET_PRODUCTS_BY_CATEGORY_REQUEST,
    GET_PRODUCTS_BY_CATEGORY_SUCCESS,
    GET_PRODUCTS_BY_CATEGORY_SUCCESS_FAIL,

    CLEAR_ERRORS
} from '../Constrants/ProductConstrants.js'
export const getProductByCategory = (value) => async(dispatch)=>{
    console.log(value)
    try {
        dispatch({type: GET_PRODUCTS_BY_CATEGORY_REQUEST})
        const{ data } = await axios.get('/api/v1/catproduct',{value})
        console.log(data)
        dispatch({
            type: GET_PRODUCTS_BY_CATEGORY_SUCCESS,
            payload: data
        })

    } catch (error) {
        dispatch({
            type:GET_PRODUCTS_BY_CATEGORY_SUCCESS_FAIL,
            payload: error.response.data.message
        })
    }
}

Here is the code of Reducer

productReducer.js

import {
    GET_PRODUCTS_BY_CATEGORY_REQUEST,
    GET_PRODUCTS_BY_CATEGORY_SUCCESS,
    GET_PRODUCTS_BY_CATEGORY_SUCCESS_FAIL,

    CLEAR_ERRORS
} from '../Constrants/ProductConstrants.js'
export const productReducer  = (state = { products : []},action)=>{
    switch(action.type){
        case GET_PRODUCTS_BY_CATEGORY_REQUEST:
            return {
                loading: true,
                products: []
            }
        case GET_PRODUCTS_BY_CATEGORY_SUCCESS:
            return{
                loading: false,
                rows: action.payload.rows,
            }
            case GET_PRODUCTS_BY_CATEGORY_SUCCESS_FAIL:
                return {
                    loading: false,
                    error: action.payload
                }
                case CLEAR_ERRORS:
            return {
                ...state,
                error: null
            }
            default:
            return state
    }
}

Here is the code where i would like to get data

itemList.jsx

import React, { useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux';
import { getProductByCategory } from '../../services/Action/productAction'

const ItemList = (props) => {
    const itemId = props.myData

    const dispatch = useDispatch();

    const { rows } = useSelector(state => state.products);
    console.log(rows)

    useEffect(() => {
        dispatch(getProductByCategory(itemId));

    }, [dispatch])

Сreating a file with text input into it

I’m started learning nodejs and faced the following problem. It is necessary to create a file in which there is conditionally nothing, and when it is created, a greeting is displayed, with a suggestion for the subsequent input of text (any) which, in turn, will be saved in the created file. Text input continues until the thread is stopped via ctrl+c, and when pressed, displays the farewell text (sry my eng ^_^)

Gave a couple of examples

const fs = require('fs');
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });

fs.appendFile('server.txt', greeting, function (err) {
  if (err) return console.log(err);
  console.log('Appended!');
});

const greeting = rl.question('Hi user, what your name? ', (answer) => {
  console.log(`Hi ${answer}, nice to meet you! Сontinue...`);
  rl.on('line', (input) => {
    console.log(`Your thoughts: ${input}`);
  });
});

let data = rl.on('line', (input) => {
  console.log(`Received: ${input}`);
});

let hi = 'Hi user, what your name? ';

newFunction();
function newFunction () {
  fs.writeFile(
    'greteng.txt',
    hi,
    {
      encoding: 'utf8',
      flag: 'w',
      mode: 0o666,
    },
    (err) => {
      if (err) console.log(err);
      else {
        console.log('File written successfullyn');
        console.log('The written has the following contents:');
        console.log(fs.readFileSync('greteng.txt', 'utf8'));
      }
    },
  );
}

newFunction(data);

snapshot of text possible but not video

I’m new to React, here i am using html2canvas to take a snapshot of a video, simply i have a button ‘take a snapshot’ and div which contains < h1>this text is viewable< / h1> and under that live stream, but as you can see from picture below when i click that button it only takes snapshot of that h1 text and video shows blank, any idea why video is blank ? so my code is working thats why text is viewable

image:

enter image description here

video.js:

import { Height } from '@material-ui/icons';
import React, { useRef, useEffect, useState } from 'react';
import { loadPlayer } from 'rtsp-relay/browser';

const StreamVideo = () => {
  const canvasRef = useRef(null);

  useEffect(() => {
    if (!canvasRef.current) throw new Error('Ref is null');

    loadPlayer({
      url: 'ws://localhost:.../api/stream',
      canvas: canvasRef.current,
    });
  
  }, []);


  return (
    <div style={{ border: '5px solid red' }}>
      <canvas ref={canvasRef} style={{ width: '100%', height: '100%' }} />
    </div>
  );
};

export default StreamVideo;

here using that :

  <button onClick={createPicHandle}>take a snapshot</button>

          <div ref={ref}>
            <h1>this text is viewable</h1>

            <StreamVideo />
          </div>

          {pic ? (
            <img src={pic} style={{ width: '100%', height: 'auto' }} alt="" />
          ) : null}

if needed here is nodejs:

const express = require('express');
const app = express();

const { proxy, scriptUrl } = require('rtsp-relay')(app);

const handler = proxy({
  url: `rtsp://....:.../Streaming/Channels/101`,
 
  verbose: false,
  transport: 'tcp',
});

app.ws('/api/stream', handler);

app.get('/', (req, res) =>
  res.send(
    `hg`,
  
  ),
);

app.listen(5000);