cannot find module ‘next/router’ or its corresponding type declarations

Currently having some problems with my NextJS app.

I get the error below. Which is really weird, because my code runs perfectly with no errors.

import { useRouter } from 'next/router';
// Cannot find module 'next/router' or its corresponding type declarations.

However, I get the error above in my IDE, this error is stopping my turbo build and yarn build commands to run, causing me to be unable to be able to push to production.

I have restarted my ts server, uninstalled next, updated to latest version and ran yarn to install everything again.

I’ve made an example repository on GitHub. https://github.com/MonkeeMan1/test

This is happening for all my next imports.
Cannot find module 'next/router' or its corresponding type declarations.ts(2307)
Cannot find module 'next/link' or its corresponding type declarations.ts(2307)
Cannot find module 'next/image' or its corresponding type declarations.ts(2307)

Package.json
https://hatebin.com/ylujtdhtht

I have tried using moduleResolution node, as well as node16

node results in my local package cachetesting to not be found, so it is unable to be imported. And node16 results in nextjs import errors.

Ag-grid pivot avoid column aggregation

I have an Ag-grid pivot table with row groups and column defs.
Is there a way to hide the “Total” column while still having an expandable pivot column groups and the same aggFunc for the row groups?

Example:
The current state
The current state

What I want
What I want

Code:

const gridOptions = {
  columnDefs: [
    { field: 'country', rowGroup: true, enableRowGroup: true },
    { field: 'athlete', rowGroup: true, enableRowGroup: true },
    { field: 'sport', pivot: true, enablePivot: true },
    { field: 'year', pivot: true, enablePivot: true },
    { field: 'gold', aggFunc: 'sum' },
    { field: 'silver', aggFunc: 'sum' },
    { field: 'bronze', aggFunc: 'sum' },
  ],
  defaultColDef: {
    maxWidth: 140,
    filter: true,
    resizable: true,
  },
  autoGroupColumnDef: {
    minWidth: 180,
  },
  pivotMode: true,
  pivotColumnGroupTotals: 'before',
};

Thanks!

jQuery slider is not moving divs

I have tried looking at other stacks but couldn’t find any help. Basically my slider isn’t moving and the divs are stacked on one another. I am using bxslider My code:

console.log("slider code loaded")
 jQuery('.slider').bxSlider({
  autoControls: true,
  auto: true,
  pager: true,
  slideWidth: 600,
  mode: 'fade',
  captions: true,
  speed: 1000
});

(function($) {
  $.fn.slider = function(options) {
    // default settings
    var settings = $.extend({
      speed: 1000,
      pause: 3000
    }, options);
    var slider = this;
    var slides = slider.find('.slide');
    var currentSlide = 0;
    // show first slide
    jQuery(slides[currentSlide]).fadeIn(settings.speed);
    // loop through slides
    setInterval(function() {
      // hide current slide
      jQuery(slides[currentSlide]).fadeOut(settings.speed);
      // move to next slide
      currentSlide++;
      if (currentSlide >= slides.length) {
        currentSlide = 0;
      }
      // show next slide
      jQuery(slides[currentSlide]).fadeIn(settings.speed);
    }, settings.pause);
    return this;
  };
}(jQuery));
<link rel="stylesheet" href="https://cdn.jsdelivr.net/bxslider/4.2.12/jquery.bxslider.css">
<script "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script "text/javascript" src="https://cdn.jsdelivr.net/bxslider/4.2.12/jquery.bxslider.min.js"></script>
<!-- Load jQuery -->
<script src="js/jquery.min.js"></script>

<!-- Load slider script with jQuery as dependency -->
<script src="js/jquery-slider.js"></script>
<!-- Load CSS file -->
<link rel="stylesheet" href="css/jquery-slider.css">

<div class="slider">
    <h2>Slide One</h2>
    <h2>Slide Two</h2>
    <h2>Slide Three</h2>
</div>

I can see that “slider code loaded” is logged and no errors in console. But nothing seems to be happening. Can anyone please help me out? Thanks in advance.

How To create a multi Level Dropdown NavBar in React-bootstrap using Map?

I needed some help spawning multi-level dropdowns in the React-bootstrap navbar with Maps.

I have a constant.js file that contains all the data that I want to dynamically populate in the NavBar dropdown

export const navLinks = [
{
    id: "transactions",
    title: "Transactions",
    children: [
        {
            id: 'transactions/LotAssignment',
            title: 'Lot Assignment Maintenance',
            component: <LotAssignmentMaintenance />
        },
        {
            id: 'transactions/ShopOrder',
            title: 'Shop Order Maintenance',
            children: [
                {
                    id: 'shopOrder/Print',
                    title: 'Shop Order Print',
                    component: <ShopPrint />
                },
            ]
        },
        {
            id: 'transactions/Lot',
            title: 'Lot Maintenance',
            component: <LotMaintenance />
        }
    ]
},
  ];

Notice that it still has children data inside the children, which I want to output into a multi-level dropdown

and then, I have the below component called Navigation.jsx which I use Map to create the Navbar dropdown

import React from "react";
import { Navbar, Nav, Container, NavDropdown } from "react-bootstrap";
import { navLinks } from "../constants/index.js";
import { Route, Routes, Link, BrowserRouter } from "react-router-dom";

export const Navigation = () => {
  return (
    <BrowserRouter>
      <Navbar bg="dark" variant="dark" expand="lg">
        <Container>
          <Navbar.Brand as={Link} to="/"></Navbar.Brand>
          <Navbar.Toggle aria-controls="basic-navbar-nav" />
          <Navbar.Collapse id="basic-navbar-nav">
            <Nav className="ms-auto">
              {navLinks.map((nav, index) => {
                if (!nav.children) {
                  return (
                    <Nav.Link as={Link} to={`${nav.id}`} key={nav.id}>
                      {nav.title}
                    </Nav.Link>
                  );
                } else if (nav.children) {
                  console.log(nav.children.child);
                  return (
                    <NavDropdown
                      key={nav.id}
                      title={nav.title}
                      id="basic-nav-dropdown"
                    >
                      {nav.children.map((dropdown, idx) => (
                        <NavDropdown.Item
                          key={dropdown.id}
                          as={Link}
                          to={`${dropdown.id}`}
                        >
                          {dropdown.title}
                        </NavDropdown.Item>
                      ))}
                    </NavDropdown>
                  );
                } else {
                }
              })}
            </Nav>
          </Navbar.Collapse>
        </Container>
      </Navbar>

      <Routes>
        {navLinks.map((nav, index) => {
          if (!nav.children) {
            return <Route path={nav.id} element={nav.component} key={nav.id} />;
          } else {
            return nav.children.map((child, idx) => (
              <Route path={child.id} element={child.component} key={child.id} />
            ));
          }
        })}
      </Routes>
    </BrowserRouter>
  );
};

the code output is below

navbarDropdown

The problem is, for the part that still has children,
the dropdown is not created, the expected output is like below.

Thanks in Advance 🙂

expected Output

Javascript execute code from a single tab

The requirement is to execute the event listener on a single tab only. The event listener is an API which should be triggered through one tab when multiple browser tabs are opened. What is the best approach to do so?

Tried LocalStorage and StorageEvent but this seems to cause race condition

When I click on my useNavigate it reloads my page and wipes the state i gave it. How do i prevent this

I have a page that has a pediatric and a adult version to access these i have two buttons that link to the same page but just i send a different state so I can load the page depending on what state it was previously sent. The problem is my pediatric navigate reloads the page on button press and causes the the location.state to be null

    const handleNavigate = (e) => { console.log(algorithms[e]); navigate('/medical/aha-algorithms/algorithms', {state: {...algorithms[e]}}) }
    
    return(
        <div className='homepage-container'>
            <Grid2 item xs={12} md={4} sx={{width: '100%'}}>
                <Grid2 item xs={12} md={4} sx={{width: '100%'}}>
                    <Card 
                        sx={pageButtons}
                        onClick={() => handleNavigate('pediatric')}
                    >
                        <CardContent sx={buttonConent}>
                            <Typography variant="h6" sx={{textAlign: 'center', color: 'white'}} mb={2}>PEDIATRIC</Typography>
                        </CardContent>
                    </Card>
                </Grid2>
                <Grid2 item xs={12} md={4} sx={{width: '100%'}}>
                    <Card 
                        sx={pageButtons}
                        onClick={() => handleNavigate('adult')}
                    >
                        <CardContent sx={buttonConent}>
                            <Typography variant="h6" sx={{textAlign: 'center', color: 'white'}} mb={2}>ADULT</Typography>
                        </CardContent>
                    </Card>
                </Grid2>
            </Grid2>
        </div>
    )

i was expecting the above on both button presses to show the page at /medical/aha-algorithms/algorithms and have a state for each item

here is the code from the algorithms page

export default function Algorithms() {
    const location = useLocation(); 
    console.log(location)

    const navigate = useNavigate() // to move to the page with specific pdfs in it 
    return(
        <h1>Algorithms</h1>
    )
}

Any way to both pass form data and fun a fetch command with the same button press?

I might be going about this entirely the wrong way, but I’m working off of whatever tutorials I can find and am still getting acquainted with javascript, so I may very well have missed something obvious. I’ve tried everything I can think of and I’m completely out of ideas. I will detail what I’ve tried below. First, the problem:

I have a form, and I am trying to:

  1. Pass the contents of the form to a php script, which does some processing and then amends it to an html file, feed.html, then
  2. update a div to reflect the contents of feed.html, without having to completely refresh the page.

Here is the form and the div I want to update:

<div id="feed"></div>

<form onsubmit="return sendData()" id="tincan">
  <textarea id="shoutAperture" name="shoutAperture"></textarea>
  <!--<input type="submit" id="shout" name="shout" value="SHOUT">-->
  <button id="shout" name="shout">SHOUT</button>
</form>

(I have also tried it with <input type="submit"> instead of a button in case that made any difference, thus the commented-out code.)

Here are the scripts I have, which so far just collect the contents of the textarea and pass them to shout.php:

async function summonFeed() {
  let file = "feed.html";
  let summons = await fetch(file);
  let feed = await summons.text();
  document.getElementById("feed").innerHTML = feed;
}
summonFeed();

function sendData() {
  let data = new FormData(document.getElementById("tincan"));
  fetch("shout.php", {
    method: "POST",
    body: data,
  });
  return false;
}

It successfully passes the form data to my php script and, from there, to feed.html, and when there is text in the feed.html file it does successfully show up on page load, but I can’t get it to refresh dynamically. So far, no matter what I’ve tried, I have only been able to get the “feed” div to update upon hard refreshing the page (control-clicking the refresh button in Firefox; it does nothing when I simply click refresh). I have tried:

  • calling multiple functions in form onsubmit (I tried separating them with &, &&, ,, and ; as indicated by various decade-old forum threads). This usually made it update the url in the address bar instead of actually passing my data to the php script.
  • adding a .then command to function sendData () either calling the summonFeed script or just wholesale repeating all of its code. (Nothing happens.) (I admit I don’t think I’ve fully grasped the mechanics of .then, despite my best efforts.)
  • creating a third function which runs sendData and summonFeed, and calling that from the form instead of sendData. (Nothing happens, or it just updates the url instead of passing the data to my php file.)
  • creating a separate onClick function that just runs summonFeed again when the button is pressed (It still calls the old version of the file from before the php script updated it; when I hard refresh the page the changes appear.)

I think that’s all I tried, but I have been at this for hours and may have forgotten some things. Any suggestions would be deeply appreciated!

How do I append an image after clicking a button and remove it on every other click in a container within JS?

I’m trying to create a mushroom log where a container populates with a unique group of images after pressing different buttons.

An image appears after clicking the first button, but it doesn’t go away after clicking again. What do I need to change in order for the image to disappear on every other click or on other button clicks?

HTML:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mushroom Log</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <h1>Mushroom Log</h1>
    <br>
    <section id="container"></section>
    <h2>Select a Mushroom Type</h2>
    <br>
    <button type="button" class="button1">Light-Spored Gilled Mushrooms</button>
    <button type="button" class="button2">Brown-Spored Gilled Mushrooms</button>
    <button type="button" class="button3">Dark-Spored Gilled Mushrooms</button>
    <button type="button" class="button4">Polypores and Crust-Fungi</button>
    <button type="button" class="button5">Puffballs, Earthballs, and Earthstars</button>
    <button type="button" class="button6">Jelly-like Fungi</button>
</body>
<script src="app.js"></script>

</html>

Javascript:

const btn1 = document.querySelector('.button1');

function lightSpored() {
    let beenCalled = false;
    if (!beenCalled) {
        beenCalled = true;
        btn1.addEventListener('click', () => { container.append(fungi1) });
    } else {
        container.innerHTML = ' ';
        beenCalled = false;
    }
}

lightSpored();

Android Webview Pass Data using HTML Tag

I have a webview inside one of my android fragments.

When I type some text in my android fragment and click a button on a the android fragment, I am able to set an Webview tag’s .value or .innerhtml to that text using Android webView.evaluateJavascript(see below).

And looking at the web view, it I can confirm visually see setting the .value or setting the .innerhtml is working.

However, after these are done, I want to fire some of my webview’s code to read that .value or .innerhtml text and do some operation with it. However, it seems like the web view does not find any data in the .value or .innerhtml.

Does anyone know why it is not updating?

Sample code on android side:

        binding.webview.evaluateJavascript(
            "document.getElementById('test-target').innerHTML='$message';"
             + "document.getElementsByClassName('send-button')[0].click()"
                ){} 

Pseudo code on web view side:

  1. On the send-button onClickListner, I want to read the ‘test-target’.innerhtml and do an operation with it. But it does not find anything, even when I have visually verified that the .innerHTML has been set by the android code from evaluateJavascript().

On Scroll Text – When page is reloaded is causing a big shift(jump)

I am trying to create a marquee text that moves when the page is scrolled, at the moment I am getting the functionality but for e.g if I reload the page at a certain position the text is shifting(jumping) too much giving a not so desirable effect.
This is the codepen link : https://codepen.io/endritibra-the-flexboxer/pen/xxyZJbb
This is the code:

<div class="marqueeContainer">

  <div class="marqueeText">
    <h1>Endrit</h1>
    <h1>As</h1>
  </div>
  <div class="marqueeText">
    <h1>Artan</h1>
  </div>
  
  
</div>

<div class="container">
  <h2>Hahahahahah</h2>
  <h2>Hahahahahah</h2>  
<h2>Hahahahahah</h2>  
<h2>Hahahahahah</h2> 
 <h2>Hahahahahah</h2>
  <h2>Hahahahahah</h2> 
 <h2>Hahahahahah</h2>
  <h2>Hahahahahah</h2> 
 <h2>Hahahahahah</h2>
  <h2>Hahahahahah</h2>
  <h2>Hahahahahah</h2>
</div>
<div class="marqueeContainer">
  <div class="marqueeText">
    <h1>Endrit</h1>
    <h1>As</h1>
  </div>
  <div class="marqueeText">
    <h1>Artan</h1>
  </div>
  
  
</div>
.marqueeContainer{
  display:inline-flex;
  width:100%;
  overflow:hidden;
}

.marqueeText{
  min-width:100%;
  display:inline-flex;
}

.marqueeText *{
  margin:0 1rem;
}
const marqueeContainer=document.querySelectorAll(".marqueeContainer");
const marqueeText=document.querySelectorAll(".marqueeText");

document.addEventListener('scroll',()=>{

marqueeContainer.forEach((item)=>{
  
  
              window.requestAnimationFrame(() => {

  
  function animate(itm,calcSpeed){
                    itm.style.transform = `translateX(${calcSpeed}px)`;

  }
  let itemsrc=item.getBoundingClientRect().y;
                console.log(itemsrc)
  marqueeText.forEach((itms)=>{
      animate(itms,itemsrc)

  })
  
})
})
  
})

The functionality is there, I mean when I scroll with mouse the text moves but if I want to reload the page and I am in certain position on the page if then I scroll the text jumps a lot, giving a bad effect.“

Does setting a javascript variable with an OR work similar to an if?

I’m studying recursion, and I came across an example of using the Fibonacci sequence and it talked about the concept of memoization. In that, it has a variable that is declared with an OR (||). I’m a little confused by that.

Here is the code:

fib = (number, storage) => {
    storage = storage || {}; //<--This is what I'm asking about

    if (storage[number]){
        return storage[number];
    } 
    if (number <= 1){ //<--second question 
        return 1;
    } 
    return storage[number] = fib(number -1, storage) + fib(number-2, storage);
}

Is my understanding correct that when this is called the first time, it assigns an empty object to storage, since storage isn’t passed in the first time, and doesn’t yet exist? Then on subsequent calls, since storage is something (an object), it just goes with the first option and assigns storage and ignores the OR?
Also, separate question, but as this function doesn’t explicitly stop at 0, why does it in fact stop at zero? Why doesn’t it just continue indefinitely into negative numbers?

adding three.js to phoenix live view project

I’m trying to add three.js as a dependency to my Phoenix Project.

At the moment, I’ve vendored a minified three.js version in /assets/vendor/three.min.js

From there I added the following to my app.js:

import * as THREE from "../vendor/three.min.js";

window.THREE = THREE;

let Hooks = {};
Hooks.ThreeInit = {
  mounted() {
    if (this.el.dataset.initialized === "false") {
      this.initThreeScene();
      this.el.dataset.initialized = "true";
    }
  },
  initThreeScene() {
    // Initialize your three.js scene here, using `THREE` object.
    // For example:
    const scene = new THREE.Scene();
    const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
    const renderer = new THREE.WebGLRenderer();

    renderer.setSize(window.innerWidth, window.innerHeight);
    this.el.appendChild(renderer.domElement);

    const geometry = new THREE.BoxGeometry();
    const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
    const cube = new THREE.Mesh(geometry, material);

    scene.add(cube);
    camera.position.z = 5;

    const animate = function () {
      requestAnimationFrame(animate);

      cube.rotation.x += 0.01;
      cube.rotation.y += 0.01;

      renderer.render(scene, camera);
    };

    animate();
  }
};

// other alpine stuff here

let liveSocket = new LiveSocket("/live", Socket, {
  params: {_csrf_token: csrfToken},
  hooks: Hooks,
  dom: {
    onBeforeElUpdated(from, to) {
      if (from._x_dataStack) {
        window.Alpine.clone(from, to)
      }
    }
  }
})

// connect if there are any LiveViews on the page
liveSocket.connect()

The live view I am trying to render the 3D cube over is as follows:

defmodule PortfolioWeb.ThreeJSLive do
  use Phoenix.LiveView

  def mount(_params, _session, socket) do
    {:ok, socket}
  end



  def render(assigns) do
    ~L"""
    <h1>Hello, World!</h1>
    <div id="three-container" phx-hook="ThreeInit"></div>
    """
  end
end

At the moment, the only thing that renders is the Hello World

Any help in figuring out what the issue is would be greatly appreciated <3

How to resolve a an Object Promise in this

I cannot get a value to output in :value="myFunction(cur_path)" no matter what. It’s always an object Promise even though I’ve tried different ways to await the value from the async function. async fetch_dpids(x) gets data from the API, I call that function in another function called async myFunction(x) to await the value and output it through :value="" in the Vue HTML tags.

  <k-accordion>
    <k-accordion-item title="Best Paths">
        <div>
          <k-property-panel v-for="(path, index) in content">
            <k-accordion-item :title=format_title(index,path['cost'])>
              <k-property-panel-item v-for="(cur_path, path_index) in path['hops']"
                                     v-if="content" :name="String(path_index)" :value="myFunction(fetch_dpids, cur_path)" :key="path_index">
              </k-property-panel-item>
            </k-accordion-item>
          </k-property-panel>
        </div>
      </k-accordion-item>
  </k-accordion>
</template>
<!-- :name="String(path_index)" holds the # count;  
      :value="cur_path" holds the switch/interface; e.g. 00:00:00:00:00:00:00:03
      -->
<script>
 module.exports = {
   props: ["content"],
   methods: {
    format_title(index, cost){
      return "Path " + index + ", cost: " + cost + ", hops: ";
    },
    
    async fetch_dpids(x) {
      try {
          const response  = await fetch('/api/myAPI/topology/v3/interfaces');
          const data      = await response.json();
          const dpids = Object.entries(data.interfaces).map(([key, value]) => {
            let item = key;
            if (item == x) { // troubleshooting
                console.log(item + "HERE <-------");
              }
            if (value.name) {
              item = `${value.name} - ${item} - ${value.mac}`;
            }
            return item;
          });
          this.dpids = dpids;
      } catch (error) {
          console.error(error);
      }
    },
    async myFunction(fetch_dpids, x) { //recent addition
      const result = await fetch_dpids(x);
      return result; // logs the resolved value of the Promise
  }
   }, // end of method block here
    
   data () {
     return {
       display: false,
       paths: [],
       headers: ["dpid"],
       rows: [this.content]
     }
   }
   
 }


</script>```

[Console log][1]
[object Promise][2]


  [1]: https://i.stack.imgur.com/OpX7r.png
  [2]: https://i.stack.imgur.com/msDgV.png

How to prevent v-model from being truth/false in an input checkbox (vue)

I currently am creating a filter popup with a list of checkboxes. On default, there should be some items selected and some not selected. I have these checkboxes connected to an object array using v-model. My problem is that when I deselect and select an item, instead of passing the object value it passes in true/false. My code is below:

<template>
    <v-card>
        <v-card-title>
            <span class="headline">Filter Headers</span>
        </v-card-title>
        <v-card-text>
            <div class="column" v-for="(header, index) in allHeaders" :key="index">
                <input
                v-model="filteredHeaders[index]"
                type="checkbox"
                :id="index"
                >
                <label :for="index"
                >{{ header.text }}</label>
            </div>
            <p class="ml-5 mt-10"> {{ filteredHeaders }} </p>

        </v-card-text>

    </v-card>    
</template>

<script>
    export default {

        props: {
            headers: Array,
            allHeaders: Array,
        },
        computed: {
            updatedTitleOnly() {
                var titleOnly = [];
                var objectPlaceholder = {};
                console.log(this.filteredHeaders);
                    if(this.filteredHeaders.length > 0) {
                        for(var i = 0; i < this.filteredHeaders.length; i++) {
                            objectPlaceholder = this.filteredHeaders[i];
                            console.log(objectPlaceholder);

                            // titleOnly.push(objectPlaceholder.text)
                        }
                }
                    return titleOnly;
            }
        },
        data() {
            return {
                updateCheck: [],
                filteredHeaders: this.headers,
            }
        },

    };
</script>

<style>
    .column {
        display: inline-block;
        width: 50%;
        box-sizing: border-box;
        padding: 0 10px;
    }
</style>

As you can see, I use a prop called allHeaders to get the list of all possible headers. Then I use a for-loop to create a checkbox for each header and assign the value of each checkbox to a value in a new array called filteredHeaders. What I want is to have these checkboxes determine what values go inside filteredHeaders. With my current code, the values get removed properly, but when I try to add them back instead of adding that object value, I get “true” or “false”.

I am not sure what to do next.