How to do in right way small React JS App [closed]

There is an app, like Scrum game

enter image description here

every developer can select card with task difficulty estimation and unveil it for another devs in Scrum room.

FrontEnd Apps communicate with each other with backend Node.js script via WebSocket.

FrontEnd App is built with jQuery and it works well.

I was tasked to rebuild it with React JS.
I started with cards and stacked almost immediately.

Question is how to build App architecture to not use huge and deep global state but use component dependent states?

My approach :

class scrumPoker {

constructor() {

    this.selfCardStates = [
        { n : 1, value : 0, state : 'inactive' },
        { n : 2, value : 1, state : 'inactive' },
        { n : 3, value : 10, state : 'inactive' },
        { n : 4, value : 50, state : 'inactive' },
    ];
    this.cardRefs = [];
    this.selfCardStates.map( ( card, i ) => {
        this.cardRefs[i] = useRef( null );
    } );
    this.tools = toolBox = new toolBoxClass();

}

renderSingleCard = ( cardState ) => {

    const [ card, setCard ] = useState( cardState );
    const state = ( card.state == 'inactive' ) ? 'active' : 'unveiled';

    return (
        <div key={card.n} ref={this.cardRefs[card.n]} className="single-card"
             onClick={ () => {
                setCard( { n: card.n, value: card.value, state: state } );
                this.cardRefs[card.n].current.className = 'single-card ' + state;
             } }>
            <div className="card-n">{card.n}</div>
            <div className="card-value">{card.value}</div>
            <div className="card-state">{card.state}</div>
        </div>
    );

}

renderCards = () => {

    let cards = [];
    cards = this.selfCardStates.map( ( cardState, i ) => {
        return this.renderSingleCard( cardState, i )
    } );

    return (
        <div className="cards-box">{cards}</div>
    );

}

renderMainPage = function() {
    return (
        <React.Fragment>
            <this.renderCards />
            <div className="test-box">
                <button onClick = { () => {
                    this.selfCardStates = [
                        { n : 4, value : 20, state : 'active' },
                        { n : 3, value : 30, state : 'active' },
                        { n : 2, value : 50, state : 'active' },
                        { n : 1, value : 100, state : 'active' },
                    ];
                } }>test</button>
            </div>
        </React.Fragment>
    );
}

}

I expect to update state of all of 4 cards by button click, so I expect to see new cards set, but nothing happens.

cardRefs is used for CSS manipulating, it is secondary stuff.

Where is the convenience of React JS and how to re-build class to have ability to rebuild Cards set in reactive way by button click ( or Websocket answer receiving in real App ) ?

I do not understand how to organize my App to have flexibility with states manipulation and not to build large deep-nested almost global State ?

In terms of this App it means will be added another modules ( to create room, to handle WS requests, to add / remove user etc. ) and I do not see how to complete it without large deep-nested State.

How to structure App in right way ?

404 on create_intent via solidus_stripe gem

Trying to integrate v3 intents , followed the readme but i keep getting thoses errors on js side :

Feature Policy: Skipping unsupported feature name “payment”. v3:1:78187
Feature Policy: Skipping unsupported feature name “payment”. v3:1:78325
Feature Policy: Skipping unsupported feature name “payment”. v3:1:178554

and when i submit the test card informations :

POSThttps://_my_web_site_url.com/stripe/create_intent [HTTP/1.1 404 Not Found 897ms]

I keep searching for what kind of integration error i could’ve done but nothing , i have the feeling it lack a memeber of the posting url
all mentions in stripe’s doc are specifying a version in them .

i’am running

rails 5.2.6 on ruby 2.7 with:
solidus (2.10.5)
solidus_api (= 2.10.5)
solidus_backend (= 2.10.5)
solidus_core (= 2.10.5)
solidus_frontend (= 2.10.5)
solidus_sample (= 2.10.5)
solidus_api (2.10.5)
solidus_stripe (4.2.0)


config.static_model_preferences.add(
Spree::PaymentMethod::StripeCreditCard,
'stripe_env_credentials',
secret_key:'sk_test_aksdhflkajsgdflkuasgdf',
publishable_key: 'pk_test_kjhga;lihglkashglasd',
stripe_country: 'FR',
v3_elements: false,
v3_intents: true,
)

And the stripe static conf has been selected in the backend’s payment page .

THanks in advance for reading / helping .

On page load Accordion tab open

I am working with a WordPress site and I am using an accordion addon. I would like for the first accordion tab to be open when a user loads the page. How/where can I do that? Is it in the backend of the site somewhere?

Also, do I need to be using javascript or jquery for this?

Thanks!

Cannot read property of undefined (reading ‘remove’) after appending child in ul

I don’t know what is wrong with this code. When I append app child to the tag and when I try to click the delete button of the appended child it shows me this error.

if you have a solution then provide me or give me suggestion to do this task

Cannot read properties of undefined (reading ‘remove’).

You can check the code as well.

HTML Code.

<!DOCTYPE html>
<html>
  <head>
    <title>Javascript + DOM</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
  </head>
  <body>
    <h1>Shopping List</h1>
    <p id="first">Get it done today</p>
    <input id="userinput" type="text" placeholder="enter items" />
    <button id="enter">Enter</button>
    <ul>
      <li class="bold red" random="23">
        Notebook <button class="deleteButton">Delete</button>
      </li>
      <li>Jello <button class="deleteButton">Delete</button></li>
      <li>Spinach <button class="deleteButton">Delete</button></li>
      <li>Rice <button class="deleteButton">Delete</button></li>
      <li>Birthday Cake <button class="deleteButton">Delete</button></li>
      <li>Candles <button class="deleteButton">Delete</button></li>
    </ul>
    <script type="text/javascript" src="script.js"></script>
  </body>
</html>

JavaScript Code.

var button = document.getElementById("enter");
var input = document.getElementById("userinput");
var ul = document.querySelector("ul");
var li = document.querySelector("li");
var deleteButton = document.getElementsByClassName("deleteButton");
var liAll = document.querySelectorAll("li");

function inputLength() {
  return input.value.length;
}

function createListElement() {
  var li = document.createElement("li");
  li.appendChild(document.createTextNode(input.value));

  const returnedLi = createDeleteButtonElement(li);

  ul.appendChild(returnedLi);
  input.value = "";
  strikeThroughOnClick();
  deleteOnClick();
}

function createDeleteButtonElement(li) {
  var button = document.createElement("button");
  button.appendChild(document.createTextNode("Delete"));
  button.classList.add("deleteButton");
  li.appendChild(button);
  return li;
}

function addListAfterClick() {
  if (inputLength() > 0) {
    createListElement();
  }
}

function addListAfterKeypress(event) {
  if (inputLength() > 0 && event.keyCode === 13) {
    createListElement();
  }
}

function strikeThrough(i) {
  liAll[i].classList.contains("done")
    ? liAll[i].classList.remove("done")
    : liAll[i].classList.add("done");
}

function deleteItem(i) {
  //   console.log();
  liAll[i].remove();
  //   this.parentNode.remove();
}

function deleteOnClick() {
  for (let i = 0; i < deleteButton.length; i++) {
    deleteButton[i].addEventListener("click", () => deleteItem(i));
  }
  return deleteButton;
}

function strikeThroughOnClick() {
  for (let i = 0; i < liAll.length; i++) {
    liAll[i].addEventListener("click", () => strikeThrough(i));
  }
  return liAll;
}

button.addEventListener("click", addListAfterClick);

input.addEventListener("keypress", addListAfterKeypress);

strikeThroughOnClick();
deleteOnClick();

HTML5 video: Get textTracks from youtube, netflix, etc when there are no children elements

Looking at the documentation for HTMLMediaElement.textTracks, it looks like subtitle/caption tracks should be nested under <video> elements. This allows you to call .textTracks on a video reference to get access to subtitles/captions.

I’ve found a number of smaller sites where this works and is setup as expected (ie: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track). However, on bigger sites like Netflix and Youtube, this doesn’t appear to work. In fact, their video elements typically have no children at all from what I can see.

This returns an empty list for a call like document.querySelector("video").textTracks:
enter image description here

Is there not a standard way of handling subtitles/captions? Can someone explain why big sites do this differently from the documentation above, and if there’s another easy way to access their subtitles/captions? I’d like to build a browser extension that reacts based off of the captions in a video.

React Native useEffect works on file save

I am developing a video chat app using react-native-voximplant, everything works, but when the app loads first time, the login functionality is happening inside the useEffect. So, the problem is, when my HomeScreen mounts, the useEffects’ should fire and I should get logged in voximplant sdk and now if I tap on call icon, the following is shown in the console:

When HomeScreen mounts:

LOG Client: emit: no handlers for event: AuthResult
LOG Error while trying to login to voximplant:  {"code": 491, "name": "AuthResult", "result": false}
LOG Client: emit: no handlers for event: ConnectionEstablished

Now when I tap on call to make a call:

// after a second...

WARN Possible Unhandled Promise Rejection (id: 0):
"NOT_LOGGED_IN"

Now when I hit save (ctrl+s), I get logged in and now if I make a call, it works! I don’t know what I am doing wrong here. Is something wrong with useEffect or I’m doing something wrong?

The HomeScreen code:

import {Voximplant} from 'react-native-voximplant';

const HomeScreen = () => {
  const voximplant = Voximplant.getInstance();

  useEffect(() => {
    const signInToVoximplant = async () => {
      try {
        const fqUsername = '...'; // credentials are correct, don't worry about them.
        const password = '...';
        await voximplant.login(fqUsername, password);
      } catch (error) {
        console.log('Error while trying to login to voximplant: ', error);
      }
    };
    signInToVoximplant();
  }, []);

  useEffect(() => {
    const connect = async () => {
      const status = await voximplant.getClientState();
      if (status === Voximplant.ClientState.DISCONNECTED) {
        await voximplant.connect();
      } else if (status === Voximplant.ClientState.LOGGED_IN) {
        console.log('[INFO] VOXIMPLANT CONNECTED');
        return;
      }
    };
      connect();
    }, []);
  }
  
  return ...

The call will only work if I hit ctrl+s i.e. save the file, otherwise it will throw Unhandled Promise rejection... because it is not logged in, however I have written/provided the login inside the useEffect.

display sticky div if within viewport

I am basing my code off of this thread Displaying a div once its within the viewport

I have a parent div that is half way down the page, within that parent div I want to display a sticky footer div, but only when viewport is showing parent div. I have tried 4 different tutorials so far with no luck.

page structure is this

HEADER

HERO

CONTENT RIGHT-SIDE(id=”wrap-vs”)

CONTENT-FULL-WIDTH

FOOTER

So when RIGHT-SIDE is within view, I want to display a sticky div within it, you can’t see RIGHT-SIDE when page loads, you need to scroll down to it, also when we are below it, I want to sticky div to go away.

This is my code so far

//HTML
<div id="wrap-vs">
    <div class="tabs">
        right-side content sticky div
    </div>
</div>
 
//CSS
#wrap-vs{
    height: 100%;
    background-color: yellow;
}

.tabs {
    position: fixed;
    bottom: 0;
}

// JS

var targetdiv = document.querySelector('.tabs');
console.log(targetdiv);
targetdiv.style.display = "none";

function CheckIfVisible(elem, targetdiv){
        
        var ElemPos = elem.getBoundingClientRect().top;
        targetdiv.style.display = (ElemPos > 0 && ElemPos < document.body.parentNode.offsetHeight)?"block":"none";
    }
    
    window.addEventListener("onscroll", function(){
        var elem = document.querySelector('#wrap-vs');
        
        CheckIfVisible(elem, targetdiv);
    });
    

866-517-1058 Chase Bank customer service

Chase customer service is available at five different phone numbers. Their general customer support number is 866-517-1058. You can contact this number 24 hours a day, seven days a week. The average waiting time is 20 minutes. It is best to call at 9:05 am.

To get targeted help, you can contact numbers specifically for mobile banking, freedom cards, and lost cards. You can also find a separate number for international customer service. Calling a targeted help number will increase the chances of resolving your problem fast.

For mobile banking concerns, call 866-517-1058. This number has a hold time of about 20 minutes. It is preferable to call this number at 10:15 a.m. To quickly get a live person, dial 0.

Contact 866-517-1058 for freedom card concerns. It takes 50 minutes or even longer for someone to answer the phone. This can be a real pain, so try to call at 10:15 a.m. for the shortest possible hold time.

Contact866-517-1058 for lost cards. On average, the waiting time is 20 minutes. Calling this number is free of charge, and it is most time-efficient to dial it at 9:45 a.m.

International callers can contact 866-517-1058. At the time of writing, the hold time was 20 minutes. This number is not toll-free. It is best to call it at 10:15 a.m.

how do I delay the exiting from a function in javaScript? [duplicate]

my problem is that I need to wait a bit before returning the value.
the function is returning the variable x before the var updates (or at least I think that it’s the problem).

var x; //now it's undefined
  con.connect(function(err) {
    if (err) throw err;
    con.query("SELECT * FROM usrs", function (err, result) {
      if (err) throw err;
      x= result; //trying to update x
  });
});
  return x; //returns undefined(because it doesn't have enough time to change so it stays like it was at the beginning)

defaultExpandAllRows antd table react with fetch not working

i use Ant Design table as ui

what’s wrong with my code, table using local data can be automatically expanded, but it’s different for the results from fetch can’t automatically expand with the same code

what am i missing here?

i can’t explain with good language, look at my sandbox https://codesandbox.io/s/defaultexpandallrows-antd-table-f1okb

this code will automatically expand

  const data = [
  {
    key: 55,
    name: "John Brown sr.",
    xchildren: [
      { key: 73, address: "New York No. 2 Lake Park" },
      { key: 46, address: "New York No. 2 Lake Park" },
    ],
  },
];

 <Table
      dataSource={data}
      defaultExpandAllRows={true}
      key={data.key}
      expandable={{
        expandedRowRender: (record) => (
          <Table pagination={false} dataSource={record.xchildren}>
            <Column title="Address" dataIndex="address" key="address" />
          </Table>
        ),
      }}
    >
      <Column title="name" dataIndex="name" key="key" />
    </Table>

this will not automatically expand table

fetch = () => {
    fetch(`https://api.jsonbin.io/b/61e6fd62ba87c130e3eaa7ef`)
      .then((res) => res.json())
      .then((data) => {
        console.log(data);
        this.setState({
          dataJSON: data,
        });
      });
  };

  <Table
           <Table
      dataSource={dataJSON}
      defaultExpandAllRows={true}
      key={data.key}
      expandable={{
        expandedRowRender: (record) => (
          <Table dataSource={record.xchildren}>
            <Column
              pagination={false}
              title="Address"
              dataIndex="address"
              key="address"
            />
          </Table>
        ),
      }}
    >
      <Column title="name" dataIndex="name" key="key" />
    </Table>

full code

import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import { Table,version } from "antd";
const { Column } = Table;

const data = [
  {
    key: 55,
    name: "John Brown sr.",
    xchildren: [
      { key: 73, address: "New York No. 2 Lake Park" },
      { key: 46, address: "New York No. 2 Lake Park" },
    ],
  },
];

class App extends React.Component {
  state = {
    dataJSON: [],
  };

  componentDidMount() {
    const { pagination } = this.state;
    this.fetch({ pagination });
  }

  fetch = () => {
    fetch(`https://api.jsonbin.io/b/61e6fd62ba87c130e3eaa7ef`)
      .then((res) => res.json())
      .then((data) => {
        console.log(data);
        this.setState({
          dataJSON: data,
        });
      });
  };

  render() {
    const { dataJSON } = this.state;
    return (
      <>
      antd version: {version}
      <p>will automatically expand</p>
        <Table
          dataSource={data}
          defaultExpandAllRows={true}
          key={data.key}
          expandable={{
            expandedRowRender: (record) => (
              <Table pagination={false} dataSource={record.xchildren}>
                <Column title="Address" dataIndex="address" key="address" />
              </Table>
            ),
          }}
        >
          <Column title="name" dataIndex="name" key="key" />
        </Table>
        <hr />
        <p> will not automatically expand</p>
        <Table
          dataSource={dataJSON}
          defaultExpandAllRows={true}
          key={data.key}
          expandable={{
            expandedRowRender: (record) => (
              <Table dataSource={record.xchildren}>
                <Column
                  pagination={false}
                  title="Address"
                  dataIndex="address"
                  key="address"
                />
              </Table>
            ),
          }}
        >
          <Column title="name" dataIndex="name" key="key" />
        </Table>
      </>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("container"));

thank you…

Why does my website keep showing old index.html, style.css, app.js…?

I have a problem that I can’t solve. I’m new to web-developing, and I coded my first web-site, bought a domain and hosting, and added my files to the public.html folder.

Whenever I change the code, either in css or js and delete the previous files in the public.html folder and then add new ones under the same name with which the code was changed, when I load the site, either by phone or desktop the site looks and all elements remain the same that I haven’t changed the code at all, if I change the names of the html, css and js files, I link them and insert them that way, it only shows me a list of files in the public.html folder. The only time the code update works is when I open the site in incognito mode for browsers.

My assumption is that there are some problems with cookies and cached data, but even when I delete them in browser, the code is not updated but the site uses old files.

Does anyone know some solution to my problem, otherwise I use domain and hosting from hostinger and I haven’t changed any settings in domen and hosting since I bought it.

Thank you all.

Error: querySrv ENOTFOUND _mongodb._tcp.cluster0.kspub.mongodb.net

my web app cannot connect to mongo dB atlas and it shows me the following error

Failed to connect to the database :Error: querySrv ENOTFOUND _mongodb._tcp.cluster0.kspub.mongodb.net
2022-01-18T16:58:59.817138+00:00 app[web.1]: (node:34) UnhandledPromiseRejectionWarning: Error: querySrv ENOTFOUND _mongodb._tcp.cluster0.kspub.mongodb.net
2022-01-18T16:58:59.817138+00:00 app[web.1]: at QueryReqWrap.onresolve [as oncomplete] (dns.js:210:19)
2022-01-18T16:58:59.817139+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)

error message

even though it works locally and connects to the database, here is my code
https://github.com/yara121/mern-app/blob/main/server/src/app.js

How to read Blob synchronously in Javascript?

I’m writing a chrome extension to intercept WebSocket traffic, by hooking the function WebSocket.send, like:

var _send = WSObject.send
WSObject.send = function (data) {
    arguments[0] = my_hook_function(data)
    _send.apply(this, arguments)
}

function my_hook_function(data) {
    // how to read the data here synchronously?
    return data
}

The my_hook_function should be synchronous. The type of data is Blob, I can’t find a synchronous API for reading the Blob. Google says there is FileReaderSync but I tried in console and this class does not exist.

How to solve it?