MUI linear determinate update progress state

I have a modal that does some async logic submitting to a database.

My LinearDeterminate component looks like this (using MUI):
MUI Progress

import { useEffect, useState } from "react";
import Box from "@mui/material/Box";
import LinearProgress from "@mui/material/LinearProgress";

export default function LinearDeterminate({ doneSoFar, allData }) {
  const [progress, setProgress] = useState(0);

  useEffect(() => {
    const timer = setInterval(() => {
      setProgress((prevProgress) => {
        if (prevProgress >= 100) {
          return 0;
        }
        return (doneSoFar / allData.length) * 100;
      });
    }, 500);

    return () => {
      clearInterval(timer);
    };
  }, []);

  return (
    <Box sx={{ width: "100%", mt: 2 }}>
      <LinearProgress variant="determinate" value={progress} />
    </Box>
  );
}

I’m using it in this modal:

import LinearDeterminate from "./LinearDeterminate";

export default function MyModal() {
  const data = []; // my data here
  let done = 0;

  const handleFunc = async () => {
    try {
      const promises = [];
      for (const row of data) {
        // some logic here
        done++; // incrementing done when every row is done
      }

      await Promise.all(promises);
    } catch (error) {}
  };
  return <LinearDeterminate doneSoFar={done} allData={data} />;
}

The problem is that the progress bar isn’t moving at all. When console logging done it is incrementing correctly. What am I doing wrong here?

activate Sepolia testnet on geth

12.0 on windows to connect sepolia testnet.
and i got this error:
enter image description here

i ran this command:
geth –syncmode light –http –http.api eth,net,engine,admin –authrpc.jwtsecret ./consensus/prysm/jwt.hex console

how can i connect the sepolia testnet(light syncmode) on geth successfully?

i just wanna check the account balance which i got test sepolia ether from the sepolia faucet.

React.js Image Path Error: Cannot Load Image File – How to Resolve?

I hope you all will be well.
I have a little bug in my code that I cannot resolve for 2 days.
the error is about the path of images in the assets folder which are not recognized by react

The error in the console is like
GET http://localhost:5173/assets/1.jpg/1.jpg 404 (Not Found)

List of images from which I want to access the img attribute within the dictionary.

const images = [ { img: "../assets/code.jpg", title: "Title 1", description: "Lorem ipsum dolor sit amet consectetur adsit amet consectetursit amet consectetur ad ad", }, ];
I want to access those data (images, title, description) here.
good to know: title and description are working properly

<div className="cardsSection"> <div> <img src={images[0].img} alt="image" /> <h2your text`>{images[0].title}


{images[0].description}

`

Thanks in advance for the solutions.

../assets/code.jpg
./assets/code.jpg
assets/code.jpg
.components/assets/code.jpg

The path is React/.NavBar/src/components where my components exist.
The path is React/.NavBar/src/assets/code.jpg where my image exists.

I also tried in the same folder in the components folder but doesn’t work.

Screen Sharing along with the video call P2P connection

I am stuck in the scenario, i am trying to implement video calling along with screen share but my video stream gets replaced by my screenShare stream.

here is the github repo: https://github.com/sanjay07sharma/webRTC-videoCall/commit/b7589dd7d9175647bc3eb64f853678c8c1d1c4b2

I was able to establis p2p connection, where i am ables too see both users stream in one ROOM_ID
when the peer who started the stream shares the screen, its video stream gets replaced screenStream.

so suppose User A and User B are connected in same room when User A shares screen User A video gets replaced by Screen A.

i am looking for the way i can stream both video and screen along with the video stream of the peer.

tut49.html:27 Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML’) why? my code is-

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Strings and String Methods</title>
</head>
<body>
    <div class="container">
        <h1>Lorem ipsum dolor sit.</h1>
        <div id="conteint"></div>
        <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Incidunt aspernatur itaque excepturi dolor, ab dicta. Mollitia tempora rem deleniti, nemo consectetur quos enim unde consequatur. Ipsum libero dolor alias cum, ducimus labore minus beatae.</p>
    </div>
    <script>
        document.getElementById('Conteint').innerHTML="<h3> this is an h3 heading </h3>"

    </script>
</body>
</html>

type here


where is the problem, I can’t fix
please help, the problem is tut49.html:27 Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML’) why? please do a final review and check

Using an addEventListener instead of inline ‘onclick’ event in the img tag

I’m looking to use one JavaScript event listener to trigger these modal windows instead of applying one ‘onclick’ events for multiple images.

    <div class="full-img-modal">
        <img src="img/gallery-images/gallery-img-01.jpg" alt="" id="full-img">
        <span class="close-gallery fa-solid fa-circle-xmark" onclick="closeFullImgModal()"></span>
    </div>

    <div class="img-gallery">
        <img src="img/gallery-images/gallery-img-01.jpg" alt="" class="img-thumb" onclick="openFullImgModal(this.src)">
        <img src="img/gallery-images/gallery-img-02.jpg" alt="" class="img-thumb" onclick="openFullImgModal(this.src)">
        <img src="img/gallery-images/gallery-img-03.jpg" alt="" class="img-thumb" onclick="openFullImgModal(this.src)">
        <img src="img/gallery-images/gallery-img-04.jpg" alt="" class="img-thumb" onclick="openFullImgModal(this.src)">
        <img src="img/gallery-images/gallery-img-05.jpg" alt="" class="img-thumb" onclick="openFullImgModal(this.src)">
        <img src="img/gallery-images/gallery-img-06.jpg" alt="" class="img-thumb" onclick="openFullImgModal(this.src)">
        <img src="img/gallery-images/gallery-img-07.jpg" alt="" class="img-thumb" onclick="openFullImgModal(this.src)">
        <img src="img/gallery-images/gallery-img-08.jpg" alt="" class="img-thumb" onclick="openFullImgMo
dal(this.src)">
    </div>


<script>
    const fullImgModal = document.querySelector('.full-img-modal');
    const fullImg = document.querySelector('#full-img');
    const closeGallery = document.querySelector('.close-gallery');

    function openFullImgModal(photo) {
        fullImgModal.style.display = "flex";
        fullImg.src = photo;
    }

    function closeFullImgModal() {
        fullImgModal.style.display = "none";
    }

    window.addEventListener('click', function(event) {
        if (event.target == fullImgModal) {
        fullImgModal.style.display = "none";
        }
    });
</script>

GitHub link:
https://github.com/rovingCondor/photo-gallery.git

Creating a responsive UI in React Native

I’m very new to React Native and also, application development in general. I set out on creating an application and I’m currently working on it’s home screen. I’ve been trying to make the screen’s UI responsive and been testing it across different devices however, I’ve been encountering multiple issues. I’ve attached the code and screenshots below for reference.

  return (
    <View style={styles.root}>
      <View style={styles.container}>
        <View style={styles.containerVertical}>
          <TouchableOpacity onPress={onAcademicsPressed} style={styles.buttonVerticalSmall}>
            <Image source={Academics} resizeMode="contain" style={styles.buttonImage} />
          </TouchableOpacity>
          <TouchableOpacity onPress={onTravelPressed} style={styles.buttonVerticalSmallOther}>
            <Image source={Travel} resizeMode="contain" style={styles.buttonImage} />
          </TouchableOpacity>
        </View>
        <View style={styles.containerVerticalLarge}>
        <TouchableOpacity onPress={onEatPressed} style={styles.buttonVerticalLarge}>
          <Image source={Eat} resizeMode="contain" style={styles.buttonImage} />
        </TouchableOpacity>
        </View>
      </View>
      <View style={styles.containerLarge}>
        <TouchableOpacity onPress={onPlayPressed} style={styles.buttonHorizontalLarge}>
          <Image source={Play} resizeMode="contain" style={styles.buttonImage} />
        </TouchableOpacity>
      </View>
    </View>
  );
};

const styles = StyleSheet.create({
  root:{
    flex: 1,
    backgroundColor: '#FCFCFC',
  },
  container:{
    flex: 0.6,
    flexDirection: 'row',
    marginHorizontal: 16,
    marginVertical: 16,
  },
  containerVertical:{
    flex: 0.5,
    flexDirection: 'column',
    marginRight: 16,
  },
  containerVerticalLarge:{
    flex: 0.5,
  },
  buttonVerticalSmall:{
    flex: 0.5,
    borderRadius: 8,
    overflow: 'hidden',
    marginBottom: 16,
  },
  buttonVerticalSmallOther:{
    flex: 0.5,
    borderRadius: 8,
    overflow: 'hidden',
  },
  buttonVerticalLarge:{
    flex: 1,
    borderRadius: 8,
    overflow: 'hidden',
  },
  containerLarge:{
    flex: 0.4,
    marginHorizontal: 16,
  },
  buttonHorizontalLarge:{
    flex: 1,
    borderRadius: 8,
    overflow: 'hidden',
  },
  buttonImage:{
    flex: 1, 
    width: '100%',
    height: '100%',
  },
});

Screenshot here

Here’re the issues I’ve been facing:

  • None of the buttons have rounded corners despite setting borderRadius
  • The spacing between the large horizontal button and the other buttons is greater than 16 despite setting the margin to 16
  • The horizontal button doesn’t scale properly on some devices

Can someone guide me through this ? Any help would be much appreciated

Detecting if a class exists in CSS to apply style to another element

Here is some CSS:

/* on a laptop probably */
@media only screen and (pointer:fine) and (max-device-height: 620px) {
    #root:has(.projects) ~ body {
        overflow: auto; /* ig let them scroll to see */
    }
}   

Here is what I expect: when we are on a laptop (pointer: fine) and the height of the window is 620px or less, if #root has .projects under it (we are on the projects page) then set overflow: auto to let them scroll the page (because the projects page’s height is 620px).

I know the mistake is here:

#root:has(.projects) ~ body

Why is this not working, and how can I do what I want to do?

I have an database file but I’m having this issue: SQLITE_CANTOPEN: unable to open database file

When a run the node.js server it’s ok. But when I try run the person GET route, it returns a empty json array and logs: SQLITE_CANTOPEN: unable to open database file.
I don’t undersatand why can’t the database file be oppend.

I have the following .js and .db files on my directory:

The database files:

/api/database/databse.db

/api/database/connection.js

//This is the connection.js

const sqlite3 = require('sqlite3').verbose();

exports.open = (database) => {
    database = new sqlite3.Database(database, (err) => {
        if (err) {
            return console.error(err.message);
        }
    });

    return database;
}

exports.close = (database) => {
    database.close((err) => {
        if (err) {
            return console.error(err);
        }
    });
}

The Model file:

/api/model/UserModel.js

const database = require('../database/connection');

class Person {
    constructor (id, firstName, lastName, birthdate, height, weight) {
        this.id = id || 0;
        this.firstName = firstName || "none";
        this.lastName = lastName || "none";
        this.height = height || 0;
        this.weight = weight || 0;
        this.birthdate = birthdate ? new Date(birthdate) : "none";
    }

    // [...] getter functions that calculates and concatenates datas
}

// [...] annother databse function, not used yet (register function)

function getEveryone () {
    return new Promise((resolve, reject)=>{
        let everyone = [];

        const sql = "SELECT * FROM person;";
        const db = database.open('./database/database.db');
        
        db.all(sql, [], (err, rows) => {
            if (err) {
                reject(JSON.stringify({message : `Erro: ${err.message}`}));
            }

            rows.forEach(row => {
                const id = row.id;
                const firstName = row.firstName;
                const lastName = row.lastName;
                const height = row.height;
                const weight = row.weight;
                const birthdate = row.birthdate;
                everyone.push(new Person(id, firstName, lastName, height, weight, birthdate));
            });
        });

        database.close(db);
        resolve(everyone);
    });
}

module.exports = {
    Person,
    getEveryone,
    register
}

The Controller file:

/api/controller/PersonController.js

const Person = require('../model/PersonModel');

async function getEveryone (req, res) {
    try {
        const everyone = await Person.getEveryone();
        console.log(`Everyone on Controller: ${everyone}`);
        
        res.writeHead(200, {'Content-Type': 'application/json'});
        res.end(JSON.stringify({everyone}));
    } catch (error) {
        res.writeHead(500, {'Content-Type': 'application/json'});
        res.end(JSON.stringify({"startStats" : `Reporte o ocorrido! Ocorreu o seguinte erro: ${error}`}));
    }
}

module.exports = {
    getEveryone
}

And the server.js file

/api/server.js

const http = require('http');
const { getEveryone } = require('./controller/PersonController');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res)=>{
    const url = req.url;

    if (req.method == 'GET') {
        switch (url) {
            case "/api/person":
                getEveryone(req, res);
                break;
        }
    } else if (req.method == 'POST') {
        switch (url) {
            case "/api/person":
                res.writeHead(201, {'Content-Type': 'application/json'});
                res.end(JSON.stringify({"startStats" : "Cadastro realizado com sucesso!"}));
                break;
        }
    } else {
        res.writeHead(404, {'Content-Type': 'application/json'});
        res.end(JSON.stringify({"startStats" : "Rota não encontrada!"}));
    }
});

server.listen(port, hostname, ()=>{
    console.log(`Servidor rodando em http://${hostname}:${port}/`);
});

On this part of the API, I want to get all the table person’s lines.

I have already tried to change the database path, on PersonModel.js for '../database/database.db' or './../database/database.db'. But I had even gotten the same error.

So first, I want to open the databse file and then see if the API is querying right.

How to check validity of strings to a set of numerical masks?

I have an input field that I need to check validity of the input.

The input needs to be 4 digits with the following masks:

08## and 09##, 4###, 5###, 6###, 7###

String examples:

"1234" // invalid
"abcd" // invalid
"5000" // valid
"0810" // valid

What is a regex that I can use to check the strings validity?

Something like:

regex.test('1234')

How do I make it so after i declare a tag in a text-field: the text overlays said tag and continues on letting me type?

So i want the text to write over the declared tag made by the user. I want it to overlap/cover it. I thought about making div appear in javascript when the user finishes their tag the characters “var mytagname;” along the semicolon which establishes the end of tag name. so everything inside their then is transferred to a javascript div and is popped off from the input field. that same value is returned to the field and popped from the background so the user can delete/edit the tag. of course along some hacky css. but I don’t know if I’m making this way to complicated or if it will work. im still familiarizing myself with the corral of javascript dom

ive tried googling to see if there any problems or pieces of the problem on the internet but their is none.

I wanted to try my solution my maybe my thinking is over complicating the solution.

Sortablejs, how can I set id on dynamic list

I’m using the Sortablejs library for the drag/ drop/ reorganize feature and I’m having trouble setting id’s on a dynamic list on start up.

I am able to set id’s after updating the list with the onChange function, but none of the onstart/onload/etc functions seem to be working for me. Any help would be appreciated. Thank you.

<script>
    import Sortable from "svelte-sortable";

    //svelte store array that will be of unknown length
    import { items } from "../store/links";

   //Sortable Options
    const options = {
        animation: 150,
        dataIdAttr: "data-id",
        onChange: function (evt) {
            [].forEach.call(
                evt.from.getElementsByClassName("sortable_item"),
                function (el, index) {
                    el.setAttribute("id", index);
                }
            );
        },
    };
</script>


<Sortable items={$items} let:item {options}>
    <div class="sortable_item">
        {item.item}
    </div>
</Sortable>