Angular Typescript first time display all the items of an array, after only the new ones base on the creation date > connection date

The problem is, first time when we land on the home-page, there are displayed all the news, and after we add a new news, in the end we need to have only the news with the creation date >= connection date. The array with the new news is properly set, but is not updated in the Html, because we still receive the news with the creation date < connection date.

ngOnInit() {

        this.anonymous = true;

        this.authentificationService.getInfosUtilisateur$()

            .subscribe(infosUser => {

                this.displayExternalTools = !!infosUser.profile;

                if (infosUser.profile !== undefined && infosUser.profile !== 'UTL_ANONYME') {

                    this.getActualites(); // I'm getting all the news with this function

                }

            }

            );



        // Subscribe to the newNewsAdded event

        this.actualiteService.newActualite.subscribe((newActualiteItem: Actualite) => {

            this.checkForNewNews(newActualiteItem); //Here I'm adding the new items.

        });

        this.displayModalIfNeeded();

    }

Get News function:

 getActualites() {

        this.actualiteService.getAll().subscribe(actualites => this.actualites = actualites);

    }

This is the function when a new news is added, we only keep the news with the creation date > connection date. And the array is displayed properly in the console.log, the are only the new news.

checkForNewNews(newNewsItem: Actualite) {

        const initialNewsLength = this.actualites.length;



        // Add the new news item to the array

        this.actualites.push(newNewsItem);



        const updatedNewsLength = this.actualites.length;

        if (updatedNewsLength > initialNewsLength) {

            const newActualites = this.actualites.filter(newsItem => {

                const newsItemDate = new Date(newsItem.dateCreation);

                return newsItemDate >= this.connectionDate;

            });

            if (newActualites.length > 0) {

                this.actualites.splice(0, this.actualites.length, ...newActualites);

            }

            console.log(this.actualites);

            this.accueilModalService.resetModalDisplayCount();



        }

    }

Html modal populated by actualites array:

<div class="slider-modal-container" *ngIf="modalVisible">

        <app-accueil-modal [actualitesItems]="actualites" (closeModal)="closeModal()"></app-accueil-modal>

      </div>

React router dom v6 state issue

I migrated from router v5 to 6, and I am not sure if that or something along the way caused, that my on button click routing doesn’t update the state anymore. Maybe some advice if it works a little different now or what could be the issue?

Here is my button:

<Button
          onClick={() => {
            navigate('/componentB', {
              state: {
                filters: [
                  {
                    name: 'id',
                    value: rowData.id,
                  },
                ],
              },
            });
          }}
        >
          Button
</Button>

rowData is coming from the renderer, that part works fine…

and here is my network request payload:

{
    "filters": [],
}

It redirects, but the state is not updating.
What could be the problem?

What is this small box on the bottom left of my sites screen that shows the screen size, and how do I remove it?

Apologies if this is a very simple question but I have no idea what this little screen size info box is called or how to remove it, countless hours of googling and I can’t find any reference to it. Seems like some sort of JavaScript debug feature but I need it removed from my site before making it live. It appears in every browser, desktop or mobile on the bottom left corner of the page and shows the current screen size.

For some more info about my environment, I’m running a Laravel PHP project on an Ubuntu 22.04 server.

Thanks!

enter image description here

Cannot read properties of null (reading ‘useCallback’)

I have this error: Cannot read properties of null (reading ‘useCallback’) when I try to use the useConnectWallet() function with web3 onboard and react js.

Here is my code in App.js with react:

import logo from './logo.svg';
import './App.css';

import React from 'react'
import { init, useConnectWallet, useWallets } from '@web3-onboard/react'
import injectedModule from '@web3-onboard/injected-wallets'
import { ethers } from 'ethers'

const API_KEY = "<API_KEY>";
const rpcUrl = `https://eth-sepolia.g.alchemy.com/v2/${API_KEY}`;

const injected = injectedModule()

// initialize Onboard
init({
  wallets: [injected],
  chains: [
    {
      id: "0xaa36a7",
      token: "ETH",
      label: "Ethereum Sepolia"
      ,
      rpcUrl,
    },
  ],
});


function App() {
  const [{ wallet, connecting }, connect, disconnect] = useConnectWallet()
  const connectedWallets = useWallets();
  return (
    <div>
      <button
        disabled={connecting}
        onClick={() => (wallet ? disconnect(wallet) : connect())}
      >
        {connecting ? "connecting" : wallet ? "disconnect" : "connect"}
      </button>
    </div>
  );
}

export default App;

This is a screenshot of what I receive:
the error

Maximum depth exceeded issue in React.useEffect

useEffect(() => {
    setLoading(true);
    const unsubscribe = onAuthStateChanged(auth, (res) => {
      if (res) {
        setUser(res);
      } else {
        setUser(null);
      }
      setError("");
      setLoading(false);
    });
    return unsubscribe;
  }, []);

How can I rewrite this code snippet without causing the Maximum depth issue mentioned?

Trying to convert chafrtjs to image PDF

I have created an HTML page that includes charts I have created charts using ChartJS
Which is running perfectly fine
but when I am trying to convert that HTML to pdf that chart is not visible after pdf conversion

JS



var farm_score = document.getElementById('farm_score').innerHTML;
farm_score = farm_score.replace(/'/g, '"');
final_farm_score = JSON.parse(farm_score)

const chartWidth = document.querySelector('.chartBox').getBoundingClientRect().width-46;
const ctx = document.getElementById('farm_score_data').getContext('2d');
const gradientSegment = ctx.createLinearGradient(0, 0, chartWidth, 0);
gradientSegment.addColorStop(0.25, 'red');
gradientSegment.addColorStop(0.50, 'DarkOrange');
gradientSegment.addColorStop(0.75, 'lightgreen');
gradientSegment.addColorStop(1, 'green');

var remain_fs = 900 - final_farm_score['farm_score']


    // setup
    const data = {

      datasets: [{
        label: 'Weekly Sales',
        data: [final_farm_score['farm_score'], remain_fs],
        backgroundColor: [
          gradientSegment,
          'rgba(239, 239, 239, 1)'
        ],

        borderWidth: 0,
        cutout:'90%',
        circumference:180,
        rotation:270
      }]
    };


    //gaugeChartText

    const gaugeChartText = {
        id : 'gaugeChartText',
        afterDatasetsDraw(chart, args, pluginOptions){
            const {ctx, data, chartArea: {top, bottom, left, right, width, height}, scales: {r} }= chart;
            ctx.save();
            const xCoor  = chart.getDatasetMeta(0).data[0].x;
            const yCoor  = chart.getDatasetMeta(0).data[0].y;
            const score = data.datasets[0].data[0];


            let rating ;
            if(score<=300) {rating = 'D';}
            if(score >300 && score <=499) {rating = 'D';}
            if(score >= 500 && score <=649) {rating = 'C';}
            if(score >= 650 && score <=749) {rating = 'B';}
            if(score >= 750 && score <=900) {rating = 'A';}
            if(score>900) {rating = 'A';}

            let ratingcolor;
            if(score<=300) {ratingcolor = 'red';}
            if(score >300 && score <=499) {ratingcolor = 'red';}
            if(score >= 500 && score <=649) {ratingcolor = 'DarkOrange';}
            if(score >= 650 && score <=749) {ratingcolor = 'lightgreen';}
            if(score >= 750 && score <=900) {ratingcolor = 'green';}
            if(score>900) {rating = 'green';}



            function textLabel(text, x, y, fontSize, textBaseLine, textAlign, color){

              ctx.font = `${fontSize}px sans-serif`;
              ctx.fillStyle = color;
              ctx.textBaseLine = textBaseLine;
              ctx.textAlign = textAlign;
              ctx.fillText(text, x, y);
            }

            textLabel('300', left, yCoor+3, 7, 'top', 'left', '#666');
            textLabel('900', right, yCoor+3, 7, 'top', 'right','#666');
            textLabel(score, xCoor, yCoor-10, 15, 'bottom', 'center', '#666');
            textLabel(rating, xCoor, yCoor-30, 20, 'bottom', 'center', ratingcolor);


        }
    }


    // config
    const config = {
      type: 'doughnut',
      data,
      options: {
      aspectRatio:1.5,
      plugins:{
      legend:{
        display:true
      },
      tooltip:{
      enabled:false
      }
      }
      },

      plugins:[ gaugeChartText ]
    };

    // render init block
    const myChart = new Chart(
      document.getElementById('farm_score_data'),
      config
    );





CSS

* {
        margin: 0;
        padding: 0;
        font-family: sans-serif;
      }


      .chartBox {
        width: 120px;
        height:80px;
        padding: 20px;
        background: white;
      }

HTML

<div class="chartBox"><canvas id="farm_score_data"></canvas></div>

After google i found that i have to convert the js chart to image
I am unable to do it
I any can help

postgreSQL query only users that their id is in the array

I’m using postgreSQL as my database for node.js app, I’m given an array of id’s for example [“1″,”2″,”3”], and I want to query only users that their id is include in this array
so it going like this

        if (ids){
            users = await pool.query(`SELECT * FROM users WHERE id IN ($1:csv)`, [members])
        }

I’m using pool.query on nodejs, but this command shown here is not working so I don’t exactly knows how to do that, thanks for any help

IOS- Show keyboard on input focus

I have an input box in react, I have passed the focus prop to make the input focused when someone lands on the component.

On Android, it works well, it focuses the input and pops up the keyboard.

On iOS, it does not work well, it focuses the input but does not shows the keyboard implicitly. I need to click on the input again to pops the keyboard.

I want that as soon as the user lands on the page, the keyboard shows up.

Here is the code: https://github.com/ritikbanger/react18-input-otp/blob/main/src/lib/index.jsx

Here is code sand box for the same: https://codesandbox.io/s/react18-input-otp-0nxzx7?file=/src/App.js

I have tried the following solutions but does not worked:

  1. IOS show keyboard on input focus
  2. displaying keyboard in Safari iOS after focus on input after page loads (modal shows) in Angular
  3. How do I focus an HTML text field on an iPhone (causing the keyboard to come up)?
  4. show keyboard on input focus without user action

Bulk Disabling of Chart.js Legends

I have written the chart.js code as follows.
Clicking on the legend section will invalidate the respective data.

var myRadarChart = new Chart(ctx, {
    type: 'bar',
    data: {
        
        labels:  ['2023-06-22', '2023-06-23', '2023-06-26', '2023-06-27', '2023-06-28', '2023-06-29', '2023-06-30', '2023-07-03', '2023-07-04', '2023-07-05', '2023-07-06', '2023-07-07', '2023-07-10'],
        datasets: [
            
        {
            label: "A",
            data: [-0.1, 0.03, -0.07, -0.1, 0.14, -0.44, -0.03, 0.24, 0.17, -0.03, -0.27, -0.2, 0.03],
            backgroundColor: ['rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)'],
            borderColor: ['rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)', 'rgba(0, 72, 255, 0.2)'],
            borderWidth: 1
        },
            
        {
            label: "B",
            data: [0.31, -0.42, 0.14, 0.11, 0.09, -0.23, -0.08, 0.22, -0.08, 0.11, 0.08, -0.27, 0.19],
            backgroundColor: ['rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)'],
            borderColor: ['rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)', 'rgba(30, 0, 255, 0.2)'],
            borderWidth: 1
        },  
        ] 
        },
    options: {
        plugins: {
            title: {
                display: true,
                text: 'Chart.js Bar Chart - Stacked'
            },
        },
        responsive: true,
        scales: {
            xAxes: [{
                stacked: true,
            }],
            yAxes: [{
                stacked: true
            }]
        },
        legend: {
            position: 'bottom'
        }
    }

The graphs displayed are as follows.
enter image description here

What I want to do is create a button in HTML and disable legend A and B at the same time.
I can add a button as follows, and in the undateChart() function, I can describe the process to disable all legends, but I don’t know how to describe it.

<input id="button1" type="button" value="change" onclick="updateChart()">

I created a function as follows, but it did not work.

function updateChart(){
    myRadarChart.legend.hidden = true;
    myRadarChart.update();
};

how to make a dynamic output using jsf and ajax

I have a dropdown list of bank account numbers, each number has an available balance. what I want to do is when I pick a number from the list it shows an output box saying “Available balance is x”. my only concern for now is the front end so I just want to print a random number each time.

I tried using outputbox in JSF but the problem is the box is always there, I just want it if I picked a number.

corresponding CSS filter attributes for Konva filter(Brightness, contract, Saturation, value)

I have a use-case to draw high-quality images preview with some dynamic filters(Brightness, contrast, Saturation, value), as the image quality is so high, I can’t use Konva directly. I have tried original images with css Filter which is performant. is there any way to map Konva filter value to CSS filter attributes.

e.g.
image.contrast(aa) => css filter contrast(bb)

Is it possible to implement a smooth transition from text painted in one color to an animated gradient?

On the page, there is white-colored text with a button positioned below it. Additionally, an animated gradient is applied to fill the text. When the button is clicked, the -webkit-text-fill-color property becomes transparent, resulting in an abrupt change of the text color to match the gradient.

Here’s what it looks like: https://codepen.io/hvyjhqnt-the-vuer/pen/poQdaLQ

Is it possible to achieve a smooth transition from white to the gradient?
(the -webkit-text-fill-color property does not support transition directly)

Datatables lengthMenu backdrop not covering whole page

I’m using datatables 1.10.25, but i’m having an issue that i’ve never seen before.

When I click on the ‘Page Lenght’ menu, a backdrop shows up, but it is only covering the div it is in, instead of covering the whole page.

this is the code I’m using:

$('#tbl-workspaces').DataTable({
    dom: 'Bfrtip',
    fixedHeader: true,
    lengthChange: false,
    lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
    bPaginate: false,
    order: [[1, "asc"]],
    buttons: [
        'pageLength',
        {
            extend: 'excelHtml5',
            exportOptions: {
                columns: [1, 2, 3]
            }
        }
    ],
    columnDefs: [
        { orderable: false, targets: [0, 4] }
    ]
});

How can I make the backdrop cover the whole page?