Using MUI modern version

According to the mui docs they provide a modern folder with components written for modern browsers which they suggest could be used to target just those browsers. How can I (or do I not need to?) setup webpack so that it rewrites imports of the form import {Box} from "@mui/material" (as advised by option 2 in the docs using babel-plugin-direct-import) to use the modern version? Ideally, without having to change the import in each file to the form import Box from "@mui/material/modern/Box" What about producing a separate version for the modern browsers to serve it to those browsers?

Sorry to ask such a ‘how do I’ style question, but googling mui and modern wasn’t a very productive search :-).

Remove value from nested array item react native

i have below array format

[
{
  "category": "c8kr0cv012vtr8vm3iqg",
  "subcategories": [
    "c8kr3d7012vtr8vm3jm0",
    "c8kr3d7012vtr8vm3jlg",
    "c8kr3d7012vtr8vm3jk0",
    "c8kr8h7012vtr8vm3m5g",
    "c8tjghovq0ahq4ccf980",
    "c8kr3nn012vtr8vm3jog",
    "c8kr3nn012vtr8vm3jo0",
    "c8kr3nn012vtr8vm3jp0"
  ]
},
{
  "category": "c8kr0cv012vtr8vm3ivg",
  "subcategories": [
    "c8kr3d7012vtr8vm3jm0",
    "c8kr3d7012vtr8vm3jlg",
    "c8kr3d7012vtr8vm3jk0",
    "c8kr8h7012vtr8vm3m5g",
    "c8tjghovq0ahq4ccf980",
    "c8kr3nn012vtr8vm3jog",
    "c8kr3nn012vtr8vm3jo0",
    "c8kr3nn012vtr8vm3jp0"
  ]
},
{
  "category": "c8kr0cv012vtr8vm3is0",
  "subcategories": [
    "c8kr3d7012vtr8vm3jm0",
    "c8kr3d7012vtr8vm3jlg",
    "c8kr3d7012vtr8vm3jk0",
    "c8kr8h7012vtr8vm3m5g",
    "c8kr3nn012vtr8vm3jog",
    "c8kr3nn012vtr8vm3jo0",
    "c8kr3nn012vtr8vm3jp0"
  ]
},
{
  "category": "c8kr0cv012vtr8vm3ir0",
  "subcategories": [
    "c8kr3d7012vtr8vm3jm0",
    "c8kr3d7012vtr8vm3jlg",
    "c8kr3d7012vtr8vm3jk0",
    "c8kr8h7012vtr8vm3m5g",
    "c8tjghovq0ahq4ccf980",
    "c8kr3nn012vtr8vm3jog",
    "c8kr3nn012vtr8vm3jo0",
    "c8kr3nn012vtr8vm3jp0"
   ]
  }
]

I want to remove value from subcategory array for example c8tjghovq0ahq4ccf980

i tried below code

tempPayload.some(function (a) {
    return a.subcategories.some(function (b, i, bb) {
        if (b === 'c8tjghovq0ahq4ccf980) {
            bb.splice(i, 1);
            return true;
        }
    });
});

but it is not working any idea how can i resolve this ?

Sorting not working for MUI Data Grid: Data Grid sortComparator giving undefined

I am trying to sort data with nested values in a data grid
But getting undefined on sortComparator of Data Grid Columns

Code:
Column Data Setup:

   { 
    headerName: 'Title',
    field: `${this.props.type}.title`,
    width: 500,
    type: "string",
    renderCell: (valueReceived) => this.getImageorVideoLogo(valueReceived.row),
    sortComparator: this.titleSorting
   }


titleSorting = (a,b)=>{
       console.log(a);
       console.log(b);
}

Data Grid:

               <DataGrid
                    rows={rowsDataGrid}
                    columns={columnsDataGrid}
                    components={{
                        Toolbar: this.getSearchTextField
                    }}
                    pageSize={5}
                    rowsPerPageOptions={[5]}
                   
                    // checkboxSelection
                    // disableSelectionOnClick
                    autoHeight
                />

Problem both console print undefined
Ideally it should give either the whole row a and row b or atleast row a column data and row b column data

knockout and applyBindings — why is there no scope?

I am new to knockout, so going to fire a lot of questions. But I’m not new to data binding. So I am knocking my head on the difference between my expectations and reality. Here is a very basic question about applyBindings.

It looks like applyBindings has the parameter “view model”, which is to me the domain object graph (as javascript objects) plus perhaps additional helper things added for the purpose of the view creation. But what I am completely missing at first is the scope of the bindings! I expected this to be applied to the current parent DOM element. But no, it is applied globally, in the entire page!

So is the expectation that in one HTML document there can only ever be one view model? This is very surprising to me! How am I supposed to create a single page web app where I have one panel showing the address book, another panel showing my appointments, another panel showing one loan application to review, and yet another showing the underwriting of another loan? They are all completely different things, am I really supposed to link them all into a single view model???

In my expectation, you bind a javascript object to a DOM element, and everything in there renders it. With every new nested DOM element, the focus object may change. It may be flowing out of some foreach binding from the parent’s object. But then two sibling (or cousin) DOM elements might be sitting side by side and having completely different view model, and also a different life cycle. Like while I am in my underwriting workflow, I quickly need to bring up an address book or my calendar. All of it in a single page app. There should be no global interference between different view models used by different unrelated DOM elements.

And yet here we are with knockout I see it has only one ko.applyBindings(viewModelObject) for a the entire page.

What am I missing? What is preventing us from modifying ko.applyBindings to take two arguments, the view model-object and the DOM element in which to show it? I could try doing that, but I am afraid if knockout has been designed in this global mindset, there might be lots of issues running the knockout machinery more than once on the same page?

How to search and replace key and value of nested object using javascript

I need to search and replace value from a nested object using javascript. I am explaining the object below.

let jsonObj = {
    "service":[
        {
            "name":"restservice",
            "device":"xr-1",
            "interface-port":"0/0/2/3",
            "interface-description":"uBot testing for NSO REST",
            "addr":"10.10.1.3/24",
            "mtu":1024
        }
    ],
    "person": {
    "male": {
      "name": "infinitbility"
    },
    "female": {
      "name": "aguidehub",
      "address": {
           "city": "bbsr",
           "pin": "752109"
      }
    }
  }
}

In the above nested object I need to search the key and replace the value. Here my requirement is in the entire object it will search for the key name and where ever it is found it will replace the value as BBSR. In the above case there are 3 place where name key is present so I need to replace the value accordingly using Javascript.

how can i display the array data from the local storage in card design using javascript [closed]

I have developed the online ticket booking platform for the movies, using html, javascript, bootstrap, css, php. I am stuck on this part

How can I display the array data from the local storage in card design and how can I update the particular array value and also delete the array object using javascript.
enter image description here

enter link description here

Metamask Get user profile image and username

enter image description here

I saw this project, and as you can see they are some meta data like the user image and the username of the user. I want to get the user profile picture URL. I don’t want to generate the profile picture myself, currently im removing the “0x” and get the first to 5th charecters. I’m using ethers.js to do this.

Application.js not working in React/Rails/Webpacker set up

I’ve seen this issue several times before in production when deploying to Heroku; however, mine is breaking in development.

app/views/layouts/application.html.erb:

<!DOCTYPE html>
<html>
  <head>
    <title>List</title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
    <%= stylesheet_pack_tag 'application' %>
  </head>

  <body>
    <%= yield %>
  </body>
</html>

app/javascripts/packs/application.js:

// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("bootstrap")
import "bootstrap/dist/css/bootstrap"
require("./hello_react");

// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)

package.json:

{
  "name": "list",
  "private": true,
  "dependencies": {
    "@babel/preset-react": "^7.17.12",
    "@popperjs/core": "^2.11.5",
    "@rails/actioncable": "^6.0.0-alpha",
    "@rails/activestorage": "^6.0.0-alpha",
    "@rails/ujs": "^6.0.0-alpha",
    "@rails/webpacker": "4.3.0",
    "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
    "bootstrap": "^5.1.3",
    "jquery": "^3.6.0",
    "popper.js": "^1.16.1",
    "prop-types": "^15.8.1",
    "react": "^18.1.0",
    "react-dom": "^18.1.0",
    "turbolinks": "^5.2.0"
  },
  "version": "0.1.0",
  "devDependencies": {
    "webpack-dev-server": "^4.9.0"
  }
}

Console Error:

GET http://localhost:3000/packs/js/application-cfda2abe0e08e379b521.js net::ERR_ABORTED 404 (Not Found)

Visual cues:

Neither bootstrap nor sample “hello react” application are showing.

Troubleshooting attempts:

rails webpacker: compile

https://bobbyhadz.com/blog/react-module-not-found-cant-resolve-popper-js#:~:text=To%20solve%20the%20error%20%22Module,and%20restart%20your%20development%20server.

config.assets.compile = true in config/environments/production.rb

Setup:

Rails version: 6.0.5

Ruby version: 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]

Node version: v16.15.0

Yarn version: 1.22.18

OS: Monterey

Following this tutorial:

https://stevepolito.design/blog/rails-react-tutorial/

I want to reflect real time changed user nickname when chatting?

The previous chat data contains the pre-change nickname, so it is not reflected in real time when changing the nickname.
What method should I use to make the nickname change in real time even the chat before changing the nickname?.

Do I have to change the nickname information in the chat data every time I change my nickname?

Firebase.usersRef
  .doc(Firebase.currentUser.email)
  .update({'nickname': nickname})
  .then(() ⇒ {
    Firebase.chatsRef
      .where('user.name', '==', Firebase.currentUser.email)
      .get()
      .then((querySnapshot) ⇒ {
        querySnapshot.forEach(doc ⇒ 
          // Changing the nickname
        )
      })
  })
  .catch(err => console.log(err));

Read the page DOM within React-based Chrome extension

I’m trying to create a chrome extension (using React) which reads the content of the currently open tab. (This is essentially for a form of manual web-scraping).

However I cant seem to get this to work.

Previously I’ve added this to my manifest.json:

    "permissions": [
        "cookies",
        "activeTab"
    ],
    "background": {
        "service_worker": "background.js"
    },
    "content_scripts": [{
        "matches": ["<all_urls>"],
        "js": ["content.js"]
      }],

And had my content.js. script be listening to a chrome.runtime.onMessage() event and then call this through my UI (chrome.runtime.sendMessage()).

However this doesn’t work as it gives an error saying
Could not establish connection. Receiving end does not exist.
This is because you can only call events that are declared in background.js not content.js.

My current idea is to create an event in background.js that then calls a content script, which then returns the data, but I’m not confident in this approach.

I’d appreciate any advice! Thanks.

How to get values from chrome.storage in a forEach loop?

I am creating an extension that stores selected text in local and retrieves that value and prints it in an ongoing list.
Each time the text is selected and added, it is added to the noteList.

    if(note.menuItemId === "addNote") {
        let noteText = note.selectionText       //noteText = selected note text
        chrome.storage.sync.set({'noteList': noteText})

Now this selected text has to be get from the local storage and printed in a list format in a way that everytime the user sets a new value a new listitem is created with that new text.

    let textArea = document.getElementById('textArea')     //textArea inside a list element

        chrome.storage.sync.get('noteList', function(updateNote){
        let noteListArray = new Array();
        list.innerHTML = '';
        textArea.value = String(updateNote.noteList)
        noteListArray.push(textArea.value)
        
        noteListArray.forEach(function(item){
            let list = document.createElement("list")
            let text = document.createTextNode(item)
            list.appendChild(text)
            document.getElementById("notesList").appendChild(list); 
        })

Now the problem is, I am not able to create a new list item. How should I proceed in this case.

Best way to render a list based on object properties?

I am fetching a list of cover from the DB and using the following code to group them by categories.

const covers = this.query.coverImageOptions || [];
return mapValues(groupBy(covers, 'category'),
    clist => clist.map(cover => omit(cover, 'category')));
}

The output of the above code is something like this:

{
    "art": [{
            "name": "Art 1",
            "source": "https://blabla.jpeg",
            "thumbnail": "https://blabla.jpeg",
        },
        ...
    ],
    "bubbles": [{
            "name": "Bubbles 1",
            "source": "https://blabla.jpeg",
            "thumbnail": "https://blabla.jpeg",
        },
        ...
    ],
    "gradient": [{
            "name": "Gradient 1",
            "source": "https://blabla.jpeg",
            "thumbnail": "https://blabla.jpeg",
        },
        ...
    }

But now I want to render a list of each category and its respective covers, but I am unsure of how to proceed, for example I think that I could use for...in to create subarrays and the map over them like so,

{
    covers.categories.map(category => ( 
      <CoverSection
        key={"cover-" + category}
        title={category}
      >
        {// iterate over each cover in the category}
      <CoverSection/>
    ))
}

but perhaps there is a simpler way?