Layout.tsx does not work as it should on all pages

The code that I put in console.log() to show the page path only appears in the “pages.tsx” file (src/app/pages.tsx) and the others that are in (src/page/Login) are not appearing in the console.

layout.tsx code:

'use client';

import { Inter } from 'next/font/google';
import { usePathname } from 'next/navigation';
import './globals.css';
import { checkIsPublicRoute } from '@/functions/check-is-public-route';

const inter = Inter({ subsets: ['latin'] })

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {

  const pathname = usePathname();
  console.log("caminho:", pathname)
  const isPublicPage = checkIsPublicRoute(pathname!)
  console.log(isPublicPage)

  return (
    <html lang="en">
      <body className={inter.className}>{children}</body>
    </html>
  )
}

When I navigate between the pages I created, nothing appears in the end but on the main page of next it appears:

caminho: /
layout.tsx:19 false
layout.tsx:17 caminho: /
layout.tsx:19 false
layout.tsx:17 caminho: /
layout.tsx:19 false
layout.tsx:17 caminho: /
layout.tsx:19 false

Regardless of the route I take, it doesn’t capture what the layout is defining

Pass data with asynchronous method from a service to a component Angular

i am working in a Login method in my service that passes data to components when the user login the app. This login method makes a http request and in case of success, it calls the setAuthentication method to update the properties i want to share.

But when i want to use this properties in a component, for example a dashboard page with the name of the user, using

  public currentUser = this.authService.currentUser

I am not getting the updated property values, just null.

This is my service code:

  public currentUserAuth:User | null =  null
  public currentUser:User | null =  null
  public currentState:authStatus = authStatus.Cheking
  

  public loginUser(loginInterface: loginInterface){
    const url = `${this.basicURL}/login`
    const body = {email: loginInterface.email, password1: loginInterface.password1}
    return this.http.post<loginResponse>(url, body)
    .pipe
    (map(({user, token, currentUser}) => this.setAuthentication(user, token, currentUser!)),
    catchError(err => throwError(() => err.error.message))
    )
  }

  public setAuthentication(userPayload:User, token:string, currentUser: User){
    this.currentUserAuth = userPayload
    this.currentState = authStatus.Authenticated
    this.currentUser = currentUser
    localStorage.setItem('token', token)
    
    return true
  }

I appreciate any help

Trouble Achieving Full Container Width in Vuetify App Layout

I just want to get started and setup a simple app layout with Vuetify.

Code:

<template>
  <v-app>
    <v-container>
      <!-- Header -->
      <v-app-bar app color="primary">
        <v-app-bar-nav-icon></v-app-bar-nav-icon>
        <v-toolbar-title>My Vuetify App</v-toolbar-title>
        <v-spacer></v-spacer>
        <v-btn text>Home</v-btn>
        <v-btn text>About</v-btn>
        <v-btn text>Contact</v-btn>
      </v-app-bar>

      <!-- Main Content -->
      <v-main>
        <v-container fluid>
          Hello World!
        </v-container>
      </v-main>
    </v-container>
  </v-app>
</template>

My issue is that the main content will not take up the full width, and I also want the text/content to be aligned to the left and to have the background color from the default theme. How can I achieve this?

Image:

enter image description here

Thanks in advance.

Matching letter spacing and wrapping for different fonts with CSS on hover effect

I’m facing a peculiar issue with CSS and font styling that I hope to get some insights on. I have implemented an effect where the font of a text element changes on hover. The challenge is that when the font changes, the new font has different letter spacing and wrapping, causing it to sometimes wrap to a new line. This change in wrapping results in the font no longer being hovered over, which causes a glitch where it reverts back to the original font.

Here’s a basic outline of what I’m trying to achieve:

Text is displayed in Font A.
On hover, the text changes to Font B.
The spacing and wrapping of Font B should match that of Font A, preventing the text from shifting or wrapping to a new line.
I’ve considered adjusting the tracking (letter-spacing) of the fonts to make them more closely match, but I’m unsure about the reliability and cross-browser compatibility of this approach.

Questions:

Is there a CSS-only solution to ensure that different fonts have matching letter spacing and wrapping behavior?
Would it be more effective to use a JavaScript package that programmatically converts each word to the new font while honoring the original line breaks and spacing? If so, any recommendations for such a package?
Here’s a snippet of my current CSS for reference:

.my-text {
  font-family: 'Font A';
}

.my-text:hover {
  font-family: 'Font B';
}

Any advice or suggestions would be greatly appreciated!

How to fetch in HTML from API pod with ClusterIP

So I’m running a front-end (lighttpd) container with simple HTML code where I try to fetch a name from another pod which serves as my node.js API, I can use curl to connect to the API from the lighttpd pod but the URL can’t be resolved from the HTML code when I run it my browser.

I have found out why that is from this post, but now I’m stuck trying to figure out how to handle this then.. Is there a way to resolve the URL from within the pod instead of the browser, or how do I do this with a NodePort alternatively?

    <script>
      // fetch user from API
      fetch("http://nodejs-service:8888/user")
        .then((res) => res.json())
        .then((data) => {
          // get user name
          const user = data.name;
          // display user name
          document.getElementById("user").innerText = user;
        });
    </script>

I have tried to put the IP of the worker node there, but that doesn’t work either and I think that address can change, too, so that’s not a good solution.

Is there a shorter/better way to read in browser javascript from a websocket a (binary) png image and continuously update it on the web page

With some pain (not really a javascript coder am I) I’ve carved following piece of code that continuously and as fast as it makes sense to display it (ie not faster than frame rate) reads a png image binary data from a websocket and displays it on the web page where this javascript resides.

To me this seems like quite a lot of complex code for such simple task.

Do I really need the FileReader and the URL here?

And never mind the long code and complexity, is this the most efficient way to do this in javascript?


const canvas = document.getElementById("canvas");
const context = canvas.getContext("2d");


socket.onmessage = function(message) {
    var reader = new FileReader();
    reader.readAsArrayBuffer(message.data);
    reader.addEventListener("loadend", function(e) {
        data = new Uint8Array(e.target.result);  
        myimage.src = URL.createObjectURL(new Blob([data.buffer], { type: 'image/png' })); 
    });

    myimage = new Image();
    myimage.onload = () => {
        requestAnimationFrame(async () => {
            context.drawImage(myimage, 0, 0, canvas.width, canvas.height);
            requestMore();
        })
    };

}

Cookies to y react frontend

The cookies set by my server instance are not being received by my front end, which is hosted on an AWS bucket.

Despite implementing cookie functionality on the server and configuring traffic redirection from the bucket to my domain name, the cookies do not work as expected in the deployed environment.

Interestingly, the setup functions correctly when tested on localhost during development.

I’m trying do a button in a responsive layout

I’m trying do a button in a responsive layout. It needs to be hidden sometimes and show itself when the screen is small, I see a code that do it with vanilla js. But i’m using typescript, the problem it is in the typing typescript. Can someone help me with that?
thecode

function Menu(e){
    let list = document.querySelector('ul');
    e.name === 'menu' ? (e.name = "close",list.classList.add('top-[80px]') , list.classList.add('opacity-100')) :( e.name = "menu" ,list.classList.remove('top-[80px]'),list.classList.remove('opacity-100'))
}

the autoplay doesnt autoplay

I added this audio to auto play on my website and made it like this to turn the volume lower, but now it only starts playing when I update the code(I like add or remove something and the code updates) but not when I enter the site

image of code I stole

I want it to auto play and have a lower volume

Menu Button in Typescript

I’m trying do a button in a responsive layout. It needs to be hidden sometimes and show itself when the screen is small, I see a code that do it with vanilla js. But i’m using typescript, the problem it is in the typing typescript. Can someone help me with that?

The code:

function Menu(e){
      let list = document.querySelector('ul');
      e.name === 'menu' ? (e.name = "close",list.classList.add('top-[80px]') , list.classList.add('opacity-100')) :( e.name = "menu" ,list.classList.remove('top-[80px]'),list.classList.remove('opacity-100'))
    }

The button:

<button className={styles.burgerButton} onClick={}></button>

I need the button call the function rightly.

(Re-)enable IntelliJ IDEA’s notification to run npm install after clicking “do not show again”

Intellij IDEA has this very nice feature to show a notification when the package.json has changed to ask if it should run npm install (or whatever package manager you are using).

I used this happily for many years. But some weeks ago I accidentally clicked on the “do not show again” button in the notification. And since then I try to re-enable this feature again…

In the settings there is “Appearance & Behavior > Notifications > Don’t ask again notifications” – but this list is empty. And I also checked the list of system notifications and didn’t find one that sounds like it. I also searched “Languages & Frameworks > JavaScript” without finding anything.

Any hint?

Optional chaining causing TypeError

I was surprised by the following behaviour:

const a = {};
a?.b.c; // throws TypeError: Cannot read properties of undefined (reading 'c')

My intention was to use this expression for when a optionally contains b, but if b is present it is expected to contain c. I had expected the expression a?.b.c to evaluate to undefined, and not throw. What expression should I have used?

Datasource mat-table is not updating

I have a function that trigger when I sort the table deepens of a column I click but the data is not updating.
This is the function and the table code:

<table mat-table #table [dataSource]="dataSourceMD" matSort (matSortChange)="getRowMaximoTable($event)" matTableExporter #exporter="matTableExporter" #sortMD="matSort" class="tr_table">

    <ng-container *ngFor="let disCol of displayedColumnsMD; let colIndex = index"
        matColumnDef="{{disCol}}" [sticky]="isIn(disCol)">
        <th mat-header-cell *matHeaderCellDef mat-sort-header>
            <div [innerHTML]="displayedColumnsNamesMD[colIndex]"></div>
        </th>
        <td mat-cell *matCellDef="let element"  [style.background-color]="element[disCol+'Color']" [style.color]="element[disCol+'Texto']">
            <div *ngIf="element[disCol]" [innerHTML]="element[disCol]"></div>
            <div *ngIf="!element[disCol] && !isIn(disCol)" [innerHTML]="'-'"></div>
        </td>
    </ng-container>

    <ng-container *ngFor="let filCol of displayedFilterColumnMD; let colIndexF = index"
        matColumnDef="{{filCol}}" [sticky]="colIndexF<3">
        <th mat-header-cell *matHeaderCellDef [style.text-align]="center" [attr.colspan]="1">
            <mat-form-field class="columnas" floatLabel='never'>
                <input matInput placeholder="Filtro" type="text"
                    [(ngModel)]='filterTableMD[displayedColumnsMD[colIndexF]]'
                    name="displayedColumnsMD[colIndexF]"
                    (keyup)="hanlerOnChangeFilter($event, 'MD',displayedColumnsMD[colIndexF])">
                <button mat-button *ngIf="filterTableMD[displayedColumnsMD[colIndexF]]"
                    (click)="handlerClearFilterField('MD',displayedColumnsMD[colIndexF])" matSuffix
                    mat-icon-button aria-label="Clear">
                    <mat-icon class="material-icons-outlined">close</mat-icon>
                </button>
            </mat-form-field>
        </th>
    </ng-container>          

    <tr mat-header-row *matHeaderRowDef="displayedColumnsMD; sticky: true"></tr>
    <tr mat-header-row *matHeaderRowDef="displayedFilterColumnMD"></tr>
    <tr mat-row [ngClass]="{ 'maximo-row': i == indexMaximoMD }" *matRowDef="let row; columns: displayedColumnsMD; let i = index"></tr>

</table>

function:

getRowMaximoTable(event?: MatSort) {
    let originalArrayData = [ ...this.dataSourceMD.data ];

    const valoresArrayASortear = originalArrayData.slice(0, -4);
    const valoresArrayFijos = originalArrayData.slice(-4);
    const sortedArray = this.dataSourceMD.sortData(valoresArrayASortear, this.dataSourceMD.sort);

    this.dataSourceMD.data = [...sortedArray, ...valoresArrayFijos];
}

I want to update the data correctly when i click of one header columns

Error : Cannot read properties of null (reading ‘querySelector’) [duplicate]

Hi i’m trying to build uploadfile form with javascript i used other web page and its worked when i copied code to main index file it had error and i cant fix it
i used i youtube video to learn uploadfile form and i did it right but when i want to copy form section to my main file getting error in secound querySelector

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Home Page </title>
        <link href="css/main-style.css" rel="stylesheet" type="text/css">
        <link rel="stylesheet" href="css/fontawesome/css/all.min.css">
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <script src="js/bootstrap.bundle.min.js"></script>
        <link type="image/png" sizes="96x96" rel="icon" href="/images/icon.png">
        <link rel="stylesheet" href="/css/jquery.dataTables.min.css">
        <script src="/js/jquery.min.js"></script>
        <script src="/js/jquery.dataTables.min.js"></script>
        <script src="script.js"></script>

                
    </head>
    <body class="loggedin">
        <nav class="navbar navbar-dark bg-dark fixed-top">
            <div class="container-fluid">
      <a href="./logout.php" class="btn btn-danger">Log Out</a>

            <button class="btn btn-warning" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasTop" aria-controls="offcanvasTop">Message Board</button>
              <button class="btn btn-dark navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar" aria-label="Toggle navigation">
              <span class="navbar-toggler-icon"></span>
              </button>
              <div class="offcanvas offcanvas-end text-bg-dark" tabindex="-1" id="offcanvasDarkNavbar" aria-labelledby="offcanvasDarkNavbarLabel">
                <div class="offcanvas-header">
                  <button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
                </div>
                <div class="offcanvas-body">
                  <ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
                    <li class="nav-item">
                      <a class="nav-link active" aria-current="page" href="./home.php">Home</a>
                      <a class="nav-link" aria-current="page" href="./profile.php">Profile</a>
                                        </li>
                                  
                      <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                          Records
                        </a>
                      </li>
                  </ul>
                </div>
              </div>
            </div>
          </nav>
          <br><br>
            <div class="offcanvas offcanvas-top" tabindex="-1" id="offcanvasTop" aria-labelledby="offcanvasTopLabel">
            
                <div class="offcanvas-body"></div>
            </div>        
        <div class="content">
        
                <div class="container">
        <div class="row border">
            <div class="col border">
                
            </div>
            
            <div class="col border">
                <form action="#">
                    <input type="file" class="file-input" name="file-input">
                    <i class="fas fa-cloud-upload-alt" style="margin-top:20px;font-size: 30px;"></i>
                </form>
            <br>
            <section class="progress-area"></section>
            <section class="uploaded-area">
            <table class="table">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
    </tr>
  </thead>
  <tbody class="table-group-divider">
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
  </tbody>
</table>
            </section>
            </div><br>
        
            </div>
    </div>    
            
        </div>
        
    </body>
</html>

js file were error is happening(secound line):

const form=document.querySelector("form"),
fileInput=form.querySelector(".file-input"),
progressArea=document.querySelector(".progress-area"),
uploadedArea=document.querySelector(".uploaded-area");

How can I use the google-cloud vision API in my browser-based web app

I am making a website with a p5 canvas that uses your webcam and displays it on the canvas. I am using the ml5 image classifier of MobileNet, and I also want it to display the results from google vision. I found the node.js package @google-cloud/vision, and as node.js isn’t compatible with the browser, I had trouble making it work. Can you help me?

I tried using webpack, with this config:

const path = require('path');
const nodeExternals = require('webpack-node-externals');
const fs = require('fs');

module.exports = {
    entry: './node_modules/@google-cloud/vision/build/src/index.js',
    target: 'web',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    module: {
        rules: [
            {
                test: /(fs|require)/,
                loader: 'loader.js',
            },
            {
                test: /.js$/,
                loader: 'babel-loader',
                exclude: /(fs|require|node_modules)/,
            },
        ],
    },
    resolve: {
        fallback: {
            stream: require.resolve('stream-browserify'),
            buffer: require.resolve("buffer"),
            crypto: require.resolve("crypto-browserify"),
            assert: require.resolve("assert"),
            path: require.resolve("path-browserify"),
            querystring: require.resolve("querystring-es3"),
            os: require.resolve("os-browserify"),
            url: require.resolve("url"),
            https: require.resolve("https-browserify"),
            http: require.resolve("stream-http"),
            fs: require.resolve('browserify-fs'),
            child_process: require.resolve('cross-spawn'),
            zlib: require.resolve("browserify-zlib"),
        },
        modules: [
            'node_modules',
        ],
    },
    externals: [nodeExternals()],
    mode: 'production',

};

I expected to be able to import the bundle.js into my html, and then use the ImageAnnotator function as if it was already imported. Instead, I received errors that fs and child-process were not defined. I couldn’t fix that error, so I tried other bundlers like rollup, parcel, and browserify, but none of them worked. I tried using the require.js library of r.js but that didn’t work either.
To view my code, the website is at:
Github Website