Integrating a vue.js project into existing html-based code

im a beginner when it comes to vue.js and inexperienced in web-development in general.

I’ve been tasked with remaking a a part of a page on a website of one of our clients.

One of the most important requirements for me was that the project should be easy to integrate into existing code and should be able to accept various arguments (like props in vue.js do)

I’ve finished the project but I’m currently quite lost on how I should proceed with creating a deployable component. I originally thought that it would be really easy to turn my project into a standalone component that would then take some arguments via props like this. .

However after searching on the internet it doesn’t appear that straightforward anymore.

The best option I came up with so far is uploading my project to npm to make it easily installable and then provide some instructions on how to integrate it into code. However, that process could vary heavily depending on which type of html and js the client uses.

Another option would be hosting the component on github pages and then providing an iframe to it, however it seems like that would make passing down arguments to the component require a separate api.

Is there something really obvious that I’m missing here? What options do I have to create a reusable component that can be just inserted into existing code, regadless of the framework?

Any help would be greatly appreciated!

Thank you in advance.

I’ve tried looking up similar questions but the answers seem to be rather obscure and utilize some odd packages via cdns

Close icon doesnt’t change in hamburger menu on mobile devices

I’m trying to fix some strange issue which appears on mobile devices.
The problem is that when the user select link from the dropdown menu the close icon stucks and doesn’t change with the hamburger menu icon. But when the user clicks on the hamburger menu and after that close the menu, then the close icon has been changed correctly with the hamburger menu icon.

Here is the code I’m using:

App.jsx

import React, { Suspense, useEffect, useState } from 'react';
import { Navigate, Route, Routes } from 'react-router';
import { useTranslation } from 'react-i18next';
import './i18n'
import Header from './components/Header';

import './App.css';

const App = () => {
  const [hideMain, setHideMain] = useState(false);
  const [isOpen, setIsOpen] = useState(false);
  const [isMobile, setIsMobile] = useState(false);
  const [selectedItem, setSelectedItem] = useState(localStorage.getItem("i18nextLng"));
  const { t } = useTranslation();

  const toggleClass = (e) => {
    setIsOpen(!isOpen);
    setHideMain(!hideMain);
  };

  useEffect(() => {
    if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
      setIsMobile(true);
    }
  }, []);

  return (
    <div className="app">
      <Suspense fallback={null}>
        <header className="top-navbar">
          <Header isMobile={isMobile} isOpen={isOpen} toggleClass={toggleClass} selectedItem=    {selectedItem} setSelectedItem={setSelectedItem} />
        </header>
      </Suspense>
    </div>
  )
}

export default App;

Header.js

import { useEffect, useState } from "react";
import { Link, NavLink, useNavigate } from "react-router-dom";
import {
  Button,
  Row,
  Col,
  DropdownItem,
  DropdownMenu,
  DropdownToggle,
  Nav,
  Navbar,
  UncontrolledDropdown,
  Collapse,
  NavItem
} from "reactstrap";
import i18next from "i18next";
import { useTranslation } from "react-i18next";
import Logo from '../../images/logo.png';
import { links } from "../../constants";
import './header.scss';
import { scrollToTop } from "../../utils";

function Header({ isMobile, isOpen, toggleClass, selectedItem, setSelectedItem }) {
  const { t } = useTranslation();
  const navigate = useNavigate();

  const navigateToContact = () => {
    navigate('/contact');
  };

  useEffect(() => {
    if (isMobile && document.querySelectorAll('.container-fluid')[1]) {
      document.querySelectorAll('.container-fluid')[1].classList.add("px-0");
    }
  }, [isMobile, isOpen])

  return (
    <>{!isMobile ? (<div className="container-fluid px-0">
      <div className="mb-3">
        <nav className="navbar navbar-expand-lg py-0">
          <div className="container-fluid">
            <NavLink onClick={scrollToTop} to="/truck-covers" className={`navbar-brand text-start ${!isMobile ? 'ms-4' : ''}`}>
              <img src={Logo} alt="Pokrivala.net logo" className="w-50" />
            </NavLink>
            <div className="d-flex align-items-center justify-content-end collapse navbar-collapse" id="navbars-host">
              <div className="social-icons me-3 text-end">
                <Link to="https://www.facebook.com/brezentiruse" target="_blank">
                  <i className="fa-brands fa-facebook fs-4 mx-1 my-2 text-dark"></i>
                </Link>
                <Link to="https://www.facebook.com/CreativeIdeaGroup/?fref=ts" target="_blank">
                  <i className="fa-brands fa-facebook fs-4 text-dark"></i>
                </Link>
              </div>
              <Button size="sm" color="dark" className="cursor-default me-2" outline>
                <i className="fa fa-phone my-2 px-2" />+359 887 614 031
              </Button>
              <Button color="dark" size="sm" className="cursor-default me-2" outline>
                <i className="fa fa-phone my-2 px-2" />+359 877 614 029
              </Button>
              <Button onClick={() => { scrollToTop(); navigateToContact(); }} color="dark" size="sm" className="location-link me-2" outline>
                <Link className="text-dark text-decoration-none" to="/contact">
                  <i className="fa-solid fa-location-dot my-2 px-2" />{t('city')}
                </Link>
              </Button>
              <Button color="dark" size="sm" outline className="cursor-default" href="mailto:[email protected]">
                <i className="fa-solid fa-envelope my-2 px-2" />[email protected]
              </Button>
              <Navbar expand="sm" className="py-0">
                <Nav className="ms-auto" navbar>
                  <UncontrolledDropdown setActiveFromChild className="cursor-pointer">
                    <DropdownToggle
                      caret
                      className="nav-link"
                      tag="a"
                    >
                      {selectedItem.toLocaleUpperCase()}
                    </DropdownToggle>
                    <DropdownMenu>
                      {selectedItem !== "en" && <DropdownItem
                        href="#"
                        tag="a"
                        onClick={() => {
                          i18next.changeLanguage('en');
                          setSelectedItem(localStorage.getItem("i18nextLng"));
                        }}
                      >
                        EN
                      </DropdownItem>
                      }
                      {selectedItem !== "bg" && <DropdownItem
                        href="#"
                        tag="a"
                        onClick={() => {
                          i18next.changeLanguage('bg');
                          setSelectedItem(localStorage.getItem("i18nextLng"));
                        }}
                      >
                        BG
                      </DropdownItem>}
                      {selectedItem !== "ro" && <DropdownItem
                        href="#"
                        tag="a"
                        onClick={() => {
                          i18next.changeLanguage('ro');
                          setSelectedItem(localStorage.getItem("i18nextLng"));
                        }}
                      >
                        RO
                      </DropdownItem>
                      }
                    </DropdownMenu>
                  </UncontrolledDropdown>
                </Nav>
              </Navbar>
            </div>
          </div>
        </nav>
        <nav className="navbar navbar-expand-md navbar-dark bc-blue">
          <div className="collapse navbar-collapse align-items-center justify-content-center" id="navbarCollapse">
            <ul className="navbar-nav ml-auto">
              <li className="nav-item d-flex collapse navbar-collapse" id="navbars-host">
                {links.map((element, i) => {
                  return (
                    <Col key={i}>
                      <NavLink
                        to={element.to}
                        className={({ isActive }) =>
                          isActive ? 'fw-bold' : ''
                        }
                      >
                        {t(element.name)}
                      </NavLink>
                    </Col>
                  )
                })}
              </li>
            </ul>
          </div>
        </nav>
      </div>
    </div>) :
      <Navbar expand="md" className={`small ${isOpen ? 'bc-blue' : ''}`}>
        {!isOpen &&
          <>
            <NavLink onClick={scrollToTop} to="/truck-covers" className="navbar-brand text-start">
              <img src={Logo} alt="Pokrivala.net logo" className="w-50" />
            </NavLink>
            <Navbar expand="sm" className="py-0 px-0 mt-5 me-2 text-end">
              <Nav className=" ms-auto" navbar>
                <UncontrolledDropdown setActiveFromChild className="cursor-notAllowed">
                  <DropdownToggle
                    caret
                    className="nav-link pointer-events-none"
                    tag="a"
                  >
                    {selectedItem.toLocaleUpperCase()}
                  </DropdownToggle>
                  <DropdownMenu>
                    {selectedItem !== "en" && <DropdownItem
                      href="#"
                      tag="a"
                      onClick={() => {
                        i18next.changeLanguage('en');
                        setSelectedItem(localStorage.getItem("i18nextLng"));
                      }}
                    >
                      EN
                    </DropdownItem>
                    }
                    {selectedItem !== "bg" && <DropdownItem
                      href="#"
                      tag="a"
                      onClick={() => {
                        i18next.changeLanguage('bg');
                        setSelectedItem(localStorage.getItem("i18nextLng"));
                      }}
                    >
                      BG
                    </DropdownItem>}
                    {selectedItem !== "ro" && <DropdownItem
                      href="#"
                      tag="a"
                      onClick={() => {
                        i18next.changeLanguage('ro');
                        setSelectedItem(localStorage.getItem("i18nextLng"));
                      }}
                    >
                      RO
                    </DropdownItem>
                    }
                  </DropdownMenu>
                </UncontrolledDropdown>
              </Nav>
            </Navbar>
            <div className="d-flex flex-column align-items-center text-start">
              <Row className={`${isMobile ? '' : 'my-3'}`}>
                <Col md="12" className={`${!isMobile ? '' : 'mt-3 mb-2'}`}>
                  <Button size="sm" color="dark" className="cursor-default me-2" outline>
                    <i className="fa fa-phone my-2 px-2" />+359 887 614 031
                  </Button>
                </Col>
                <Col className={`${!isMobile ? '' : 'mb-2'}`}>
                  <Button color="dark" size="sm" className="cursor-default me-2" outline>
                    <i className="fa fa-phone my-2 px-2" />+359 877 614 029
                  </Button>
                </Col>
              </Row>
            </div>
            <div className="d-flex flex-column align-items-center text-start">
              <Row>
                <Col md="12" className={`${!isMobile ? '' : 'mb-2'}`}>
                  <Button color="dark" size="sm" className="location-link me-2" outline>
                    <Link className="text-dark text-decoration-none" to="/contact">
                      <i className="fa-solid fa-location-dot my-2 px-2" />{t('city')}
                    </Link>
                  </Button>
                </Col>
                <Col className={`${!isMobile ? '' : 'mb-2'}`}>
                  <Button color="dark" size="sm" outline className="cursor-default">
                    <i className="fa-solid fa-envelope my-2 px-2" />[email protected]
                  </Button>
                </Col>
              </Row>
            </div>
            <div className="d-flex flex-column align-items-center text-start social-icons">
              <Link to="https://www.facebook.com/brezentiruse" target="_blank">
                <i className="fa-brands fa-facebook fs-4 mx-1 my-2 text-dark"></i>
              </Link>
              <Link to="https://www.facebook.com/CreativeIdeaGroup/?fref=ts" target="_blank">
                <i className="fa-brands fa-facebook fs-4 text-dark"></i>
              </Link>
            </div>
          </>
        }
        <div className={`menuToggle ${isOpen ? 'close' : ''}`} onClick={(e) => toggleClass(e)}>
          <input type="checkbox" />
          <span></span>
          <span></span>
          <span></span>
        </div>
        <Collapse isOpen={isOpen} navbar>
          <Nav className="menu" navbar>
            {links.map((element, i) => {
              return (isOpen && <NavItem
                onClick={({ target }) => {
                  target && target?.classList.toggle('active')
                  toggleClass(false);
                }}
                key={i}>
                <NavLink to={element.to}>
                  {t(element.name)}
                </NavLink>
              </NavItem>)
            })}
          </Nav>
        </Collapse>
      </Navbar >
    }
    </>
  )
};

export default Header;

header.scss

.cursor-pointer {
  cursor: pointer;
}

.cursor-default {
  cursor: default;

  &:hover {
    cursor: default;
  }
}

// .cursor-notAllowed {
//   cursor: not-allowed;
// }

// .pointer-events-none {
//   pointer-events: none;
// }

.bc-blue {
  background-color: #407AC7;

  &.small {
    position: fixed;
    height: 100%;
    width: 100%;

    .container-fluid {
      .navbar-expand-sm {
        .container-fluid:nth-child(2) {
          padding-left: 0;
          padding-right: 0;
        }
      }
    }

    .navbar-brand {
      position: absolute;
      top: 3%;
    }

    li {
      padding: 15px 0;
      width: 100%;

      &:hover::after,
      &:focus::after {
        background: #eee;
      }

      a {
        font-size: 14px;
      }
    }
  }

  .active {
    a {
      font-weight: bold;
    }

    >.col>a {
      font-weight: bold;
    }
  }

  .col {
    line-height: 100%;
  }

  a {
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    text-transform: uppercase;
    overflow: hidden;
    width: 115px;
    line-height: 1.45;
    white-space: pre-line;
    letter-spacing: 1px;
  }
}

.location-link:hover {
  background-color: #000 !important;

  a {
    color: #fff !important;
  }
}

.menuToggle {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 7%;
  right: 5%;
  z-index: 1;
  -webkit-user-select: none;
  user-select: none;

  &.close {
    top: 3% !important;
  }

  input {
    display: flex;
    width: 40px;
    height: 32px;
    position: absolute;
    cursor: pointer;
    opacity: 0;
    z-index: 2;

    a {
      text-wrap: wrap;
    }
  }

  span {
    display: flex;
    width: 27px;
    height: 2px;
    margin-bottom: 5px;
    position: relative;
    background: #36383F;
    border-radius: 12px;
    z-index: 1;
    transform-origin: 16.65px 2px;
    transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1), background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1), opacity 0.55s ease;

    &:first-child {
      transform-origin: 0% 0%;
    }
  }
}

.menuToggle .menuToggle span .menuToggle span:nth-last-child(2) {
  transform-origin: 0% 100%;
}

.menuToggle input:checked~span {
  opacity: 1;
  transform: rotate(45deg) translate(-3px, -1px);
  background: #36383F;
}

.menuToggle input:checked~span:nth-last-child(3) {
  opacity: 0;
  transform: rotate(0deg) scale(1, 1);
}

.menuToggle input:checked~span:nth-last-child(2) {
  transform: rotate(-45deg) translate(0, -1px);
}

.menu {
  position: absolute;
  -webkit-font-smoothing: antialiased;
  transform-origin: 0% 0%;
  top: 53%;
  left: 50%;
  transform: translate(-50%, -52%);
  transition: transform 0.3s cubic-bezier(0.77, 0.2, 0.05, 1.0);
  width: 100%;

  li {
    padding: 15px 0;
    transition-delay: 2s;

    &.active {

      &:focus,
      &:active {
        &::before {
          content: '';
          opacity: 50%;
        }
      }

      color: #fff;
      font-weight: bold;
      background-color: #2E6DBF;
    }
  }
}

.menuToggle input:checked~ul {
  transform: none;
}

To solve this issue I added to change the toggle state to false when the user selects item from the menu.

 <Collapse isOpen={isOpen} navbar>
   <Nav className="menu" navbar>
      {links.map((element, i) => {
         return (isOpen && <NavItem
            onClick={({ target }) => {
            target && target?.classList.toggle('active')
            toggleClass(false); // here
            }}
        key={i}>
           <NavLink to={element.to}>
             t(element.name)}
           </NavLink>
   </NavItem>)
      })}
  </Nav>
</Collapse>

Thank you in advance!

Querying MongoDB Rest API via HTTP’s request

i am trying to query the MongoDB Rest API using Custom HTTP Endpoints and i am getting the ‘404’ Error.

I created the following endpoint for ‘GET’ requests:

fetch('https://eu-west-2.aws.data.mongodb-api.com/app/application-0-dhdvm/endpoint/mydatabase/', {
method: 'GET',
mode: 'no-cors',
cache: 'no-cache',
headers: {
    "Content-Type": "application/json",
},

Do i have to use an API key to have access to the API ? What is missing to have access to my database ?

Put text and image side by side and aligned vertically with the navbar

I want the text to be side by side with the image aligned with the nav bar logo. But it seems like the image is taking up all the space, I didn’t add a smaller width, because I want the image to be that size but with the text next to it. What should I do, guys? why the image is not inside the HomeContent? it looks like it has it own container enter image description here

// Home.jsx
import React from 'react';
import { FaWhatsapp } from 'react-icons/fa';
import pessoa from '../assets/banner-pessoa.png';
import { HomeContainer, HomeContent } from '../styles/Home.style';

const Home = () => {
  return (
    <HomeContainer>
      <HomeContent>
        <div>
          <h3>
            Unindo tecnologia e ciência a serviço da <strong>sua beleza</strong>
          </h3>
          <p>
            Protocolos exclusivos com equipamentos avançados de alta tecnologia e profissionais capacitados, entregando resultados excelentes em tratamentos corporais e faciais.
          </p>
          <div>
            <button>
              <FaWhatsapp />
              Agendar Consulta
            </button>
          </div>
        </div>
        <img src={pessoa} alt="uma mulher" />
      </HomeContent>
    </HomeContainer>
    
  );
};

export default Home;

import styled from "styled-components";

export const HomeContainer = styled.div`
    width: 100%;
    height: 640px;
    background-color: var(--beige-100);
    display: flex;
    align-items: center;
    justify-content: center;
`;

export const HomeContent = styled.div`
    display: flex;
    justify-content: space-between;
    align-items: center;
    
`;

Data shouldn’t change while clicking on both links on the same page in react.js

I don’t know what to say or how to say about this issue. Apologies for not making any sense.

Actually, I want to show the data by clicking on different links with different data (different data is coming from different components Posts and Album) on the same page, but it’s showing me the same data with different links.

For better clarification: You can check this current situation what it going on

Also this example link

Code snippets:

  • Navbar.js:
import { Link } from "react-router-dom";

export default function Navbar({ setPosts, setallAlbums }) {
    return (
        <>
            <li>
                <Link to="/">home</Link>
            </li>
            <li>
                <Link
                    to="#postlink"
                    onClick={() => {
                        setPosts((shuffledPosts) => [
                            ...shuffledPosts,
                            shuffledPosts,
                        ]);
                    }}
                >
                    postlink
                </Link>
            </li>

            <br />
            <li>
                <Link
                    to="#albumlink"
                    onClick={() => {
                        setallAlbums((shuffledAlbums) => [
                            ...shuffledAlbums,
                            shuffledAlbums,
                        ]);
                    }}
                >
                    albumlink
                </Link>
            </li>
        </>
    );
}

  • App.js:

import Posts from './pages/Posts';
import Navbar from './components/Navbar';
import { DataContext } from './context/DataContext.js';
import { useFetch } from './hook/useFetch';

export default function App() {
  const baseurl = 'https://jsonplaceholder.typicode.com';

  const { posts, setPosts } = useFetch(`${baseurl}/posts`, []);

  const { albums, setAlbums } = useFetch(`${baseurl}/albums`, []);

  return (
    <>
      <DataContext.Provider value={{ posts, setPosts, albums, setAlbums }}>
        <div>
          <Navbar setPosts={setPosts} setallAlbums={setAlbums} />
          <Posts />
        </div>
      </DataContext.Provider>
    </>
  );
}

I couldn’t understand what to do, what I’m missing, and what is wrong.

Any help would be appreciated!
Thank you.

InfluxDB – query for current week

How can I use the boundaries.week() LINK function from the "@influxdata/influxdb-client"?

The docs say I need to import import "date/boundaries but I don’t know where.

I need to query the current week from monday to now.

Here my current query:

  const weeklyPowerQuery = `
        from(bucket: "iobroker")
          |> range(start: -7d)
          |> filter(fn: (r) => r._measurement == "0_userdata.0.pv.dailyPower")
          |> filter(fn: (r) => r["_field"] == "value")
          `;

Problem with FixedColumn and RowGoroup using datatable

I want to use FixedColums and RowGroup extensions of datatable function. Both work together but when I add the scrollX option, I am not satisfied with the display.

Here is an easily reproducible example (the screen size must be not be too large to see the scrollX action).

Is there a way to fix the RowGroup names when I scroll on the x-axis ?

datatable(mtcars,
          rownames = TRUE,
          extensions = c("FixedColumns",'Scroller',"RowGroup"),
          escape=FALSE,class = 'cell-border stripe',
          selection = "single",
          option=list(fixedHeader = TRUE,
                      deferRender = TRUE,
                      fixedColumns = list(leftColumns = 4),
                      scrollX = TRUE,rowGroup = list(dataSrc = 1),
                      scroller = TRUE))

Thanks for your help

Cypress Test . How to test if a value (here title) is in the right category?

Cypress Test.

The “category name” and the “title name” is in the same column of a table.

I know how to find the fitting “value” to a “title” of the same row but inside a column I have not found yet a solution.

This is the example to find a value fitting to an another value of the same row:

cy.get('.table1 > tbody > tr:nth-child(2) > td:nth-child(1)').each(($e1, index, $list) => {
        var titeltext=$e1.text()
        if(titeltext.includes('title 1')) {
            cy.get('.table1 > tbody > tr:nth-child(2) > td:nth-child(3)').eq(index).then(function(aValue) {
                var theValue = aValue.text()
                expect (theValue.trim()).to.equal('value1')
            })
        }
    })

But to find a value (here “title”) being in the right category I have no idea so far. Is there cypress command like a “next value after a specific and fix entry in the same column”?

The table would be like this:

enter image description here

Code:

<table border="1">
<tr>
    <td>category 1</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr>
    <td>title 1</td>
    <td>subtitle 1</td>
    <td>value 1</td>
</tr>
<tr>
    <td>category 2</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr>
    <td>title 2</td>
    <td>subtitle 2</td>
    <td>value 2</td>
</tr>
<tr>
    <td>title 3</td>
    <td>subtitle 3</td>
    <td>value 3</td>
</tr>
<tr>
    <td>category 3</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr>
    <td>title 1</td>
    <td>&nbsp;</td>
    <td>value 4</td>
</tr>
<tr>
    <td>title 4</td>
    <td>subtitle 4</td>
    <td>value 5</td>
</tr>
<tr>
    <td>category 4</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr>
    <td>title 5</td>
    <td>&nbsp;</td>
    <td>value 6</td>
</tr>

How to test for example that in the same column “title 2” is in the “category 2”?

Thank you very much!

Space getting trim while extracting the PDF document using “pdfjs-dist” ( pdfjs ) package in nodejs Application

while extracting the pdf document into text i’m getting an issue, its removing extra space and converting into single space enter image description here.

Example – “Cycle started Quick, 01/09/2023 12:03” after extracting into text “Cycle started Quick, 01/09/2023 12:03”

current version witch having the space issue is

"pdfjs-dist": "3.11.174"

The version i was using previously which doesn’t have space issue

"pdfjs-dist": "2.11.338",

I’m using the below code to extracting the PDF document

import pdfjs from 'pdfjs-dist/build/pdf.js';
import * as pdfWorker from 'pdfjs-dist/build/pdf.worker.js';
import logger from './utils/logger.js';
import fs from 'fs/promises';

pdfjs.GlobalWorkerOptions.workerSrc = pdfWorker;

const pdfToText = async function ({ file, dataBuffer, startPage = 1, endPage = Number.MAX_VALUE, columnSeparator = '', rowSeparator = 'n', renderOptions }) {
    try {
        if (file) {
            dataBuffer = Uint8Array.from(await fs.readFile(file));
        } else {
            dataBuffer = Uint8Array.from(dataBuffer);
        }
        const doc = await pdfjs.getDocument(dataBuffer).promise;
        const result = {
            version: pdfjs.version,
            numPages: doc.numPages,
            metaData: await doc.getMetadata(),
        }
        result.info = result.metaData.info;

        endPage = Math.min(endPage, doc.numPages);

        const text = [];

        for (let pageNumber = startPage; pageNumber <= endPage; pageNumber++) {
            const page = await doc.getPage(pageNumber);

            const textContent = await page.getTextContent(renderOptions);
            let lastY, row = [];
            const pageText = [];
            for (const item of textContent.items) {
                if (lastY !== item.transform[5]) {
                    row = [];
                    pageText.push(row);
                    lastY = item.transform[5];
                }
                item.str = item.str.replace(' ', '*');
                row.push(item.str);
            }

            text.push(...pageText.map(row => row.join(columnSeparator)));
        }
        doc.destroy();
        result.text = text.join(rowSeparator);

        return result;
    } catch (err) { logger.error(`Error while extracting pdf doc ${err} : File name  ${file}`) }
}

export default pdfToText;

I have tried with different version of pdfjs-dist but is doesn’t work i couldn’t use the lower

Also i’m working with esbuild to bundling the application so i can’t use the version lower then 3.11.174 it trow canvas error

bs-offcanvas: Keep the backdrop when closing an canvas

I am working with one canvas and multiple body contents for that canvas. My base content displays 2 input fields, if one of them is clicked the canvas gets closed, the body content gets removed and new elements are added, then its shown again. The same functionality when the “layered canvas” is closed, it reapplies the base content. The functionality is fine, the Problem accurs when i close any canvas that isnt the “base” one. The backdrop gets removed and im left with a canvas without a backdrop.

Heres the functionality to handle the canvases in javascript. I hope i didnt miss any variable names, renamed them for better understanding. formElementsOne, … are just divs with that class, its the applied content. Other than that i have the bass canvas with an empty body.

function moveFormElementsToCanvas(elemSelector, offcTitle) {
        cleanCanvasBody(); 
        formElementSelector = elemSelector;
        let formElement = $(elemSelector);
        offcanvasTitle.html(offcTitle);
        offcanvasBody.append(formElement.children());
    }

    function cleanCanvasBody() {
        $(formElementSelector).append(offcanvasBody.children());
    }

    secondLayerButtonOne.on('click', function () {
        moveFormElementsToCanvas(formElementsOne, 'Wer kommt mit?');
        offcanvasForm.offcanvas('show');
        aktivesElement = 'secondLayerButtonOne';
    });

    secondLayerButtonTwo.on('click', function () {
        moveFormElementsToCanvas(formElementsTwo, 'Anreisetag & Dauer');
        offcanvasForm.offcanvas('show');
        aktivesElement = 'secondLayerButtonTwo';
    });

    baseLayerButton.on('click', function () {
        moveFormElementsToCanvas(formElementsThree, 'Ergebnisse Filtern');
        offcanvasForm.offcanvas('show');
        aktivesElement = 'mobileFilterButton';
    });

    closeButton.on('click', function () {
        if (aktivesElement === 'secondLayerButtonOne') {
            moveFormElementsToCanvas(formElementsThree, 'Ergebnisse Filtern');
            offcanvasForm.offcanvas('show');
            aktivesElement = 'mobileFilterButton';
        } else if (aktivesElement === 'secondLayerButtonTwo') {
            moveFormElementsToCanvas(formElementsThree, 'Ergebnisse Filtern');
            offcanvasForm.offcanvas('show');
            aktivesElement = 'mobileFilterButton';
        } else {
            offcanvasForm.offcanvas('hide');
        }
    });

I thought about either keep the closing from removing the backdrop in those special cases, which i couldnt really find a solution for.

Else i tried to reapply tha backdrop after, which fails wehen you open and close the canvases multiple times. the backdrops layer and the site gets darker and darker. Removing one backdrop when opening a “second layer” canvas just buggs the site.

Does anyone know how to stop a backdrop from being removed?

video player condition is not working with javascript in mozilla firefox

I am making a video website using Laravel and JS. To play the videos I’m using video tag ().
There are many conditions to play the video. Like: If user is not logged in then video will be paused after 20 seconds. After login if video is free then video will be play completely. But if video is paid and user did not pay for the video then the user can watch till 20 seconds only. and few more conditions are there.
In chrome all the conditions are working perfectly. But in Mozilla it does not working.
Like: If user is loggedin and he did not pay for the video then the video will be play till only 20 seconds and a message will be shown on the videos. It works on chrome.
But at the mozilla the same video does not pause at the 20 seconds.

Here is the my js code.

    <script>
    const videos = document.querySelectorAll('.myVideo');
    let playing = [];
console.log(routename);



    videos.forEach(async (video, index) => {
        const overlay = document.querySelectorAll('.overlay')[index];
        const paymentoverlay = document.querySelectorAll('.paymentoverlay')[index];

        video.addEventListener('loadedmetadata', async function () {
            console.log('1');
            video.addEventListener('timeupdate', async function () {
                console.log('2');
                if (!isUserLoggedIn && video.currentTime >= 20 && !video.paused && playing.includes(video)) {
                console.log('3');
                    video.pause();
                    video.controls = false;
                    overlay.style.display = 'block'; // Show the "Please login to continue watching" overlay
                } else {
                    if (isUserLoggedIn) {
                        if (await isFreeVideo(video)) {
                            console.log('4');
                            // Video will play.
                        } else {
                            if ((await isPaidVideo(video) && await hasPaid(video)) || (await isMemberVideo(video) && await isMembershipActive())) {
                                // Video will play.
                                console.log('5');
                            } else {
                                console.log('6');
                                if (!video.paused && video.currentTime >= 20) {
                                    console.log('7');
                                    video.pause();
                                    video.controls = false;
                                    paymentoverlay.style.display = 'block'; // Show the "Please pay first" overlay
                                }
                            }
                        }
                    }
                }
            });
        });

        video.onplay = function () {
            playing.push(video);
            if (!video.paused) {
                video.controls = true;
            }
        };

        video.onpause = function () {
            if (!video.paused) {
                video.controls = false;
            }
        };
    });

    document.addEventListener('click', async function (event) {
        if (!event.target.classList.contains('myVideo') && !event.target.classList.contains('play-icon')) {
            videos.forEach(async (video, index) => {
                const overlay = document.querySelectorAll('.overlay')[index];
                const paymentoverlay = document.querySelectorAll('.paymentoverlay')[index];

                if (!playing.includes(video) && !isUserLoggedIn && event.target.classList.contains('play-icon')) {
                    if (!(await isFreeVideo(video)) && !(await hasPaid(video)) && !(await isMembershipActive())) {
                        video.pause();
                        video.controls = false;
                        overlay.style.display = 'block'; // Show the "Please login to continue watching" overlay
                    } else if (await isPaidVideo(video) && !await hasPaid(video)) {
                        paymentoverlay.style.display = 'block'; // Show the "Please pay first" overlay
                    }
                }
            });
            event.stopPropagation();
        }
    });

    // Helper functions
    async function isFreeVideo(video) {
        const videoId = video.getAttribute('data-video-id');
        const response = await fetch(`{{ route('video.isFree', ['videoId' => ':videoId']) }}`.replace(':videoId', videoId));
        const data = await response.json();
        return data.isFree;
    }

    async function isPaidVideo(video) {
        const videoId = video.getAttribute('data-video-id');
        const response = await fetch(`{{ route('video.isPaid', ['videoId' => ':videoId']) }}`.replace(':videoId', videoId));
        const data = await response.json();
        return data.isPaid;
    }

    async function hasPaid(video) {
        const videoId = video.getAttribute('data-video-id');
        const response = await fetch(`{{ route('video.hasPaid', ['videoId' => ':videoId']) }}`.replace(':videoId', videoId));
        const data = await response.json();
        return data.hasPaid;
    }

    async function isMemberVideo(video) {
        const videoId = video.getAttribute('data-video-id');
        const response = await fetch(`{{ route('video.isMember', ['videoId' => ':videoId']) }}`.replace(':videoId', videoId));
        const data = await response.json();
        return data.isMember;
    }

    async function isMembershipActive() {
        const response = await fetch(`{{ route('user.isMembershipActive') }}`);
        const data = await response.json();
        return data.isMembershipActive;
    }
    </script>