Kepler GL polygon layer not showing

With Kepler.gl, I need to display a polygon layer but it doesn’t show on my app, the layer is created. The issue isn’t the data because it came directly from kepler.gl demo site (export -> Export Map -> JSON) and when I tried it on the same demo-app, everything works fine! So the issue must come from my app but I can’t figure it out (I’m pretty new with react)!

Here’s my app: here's a screen of my app

Here’s kerpler demo with the same data: kepler demo with the same data

Here’s my code:

import React, { Component, useContext} from 'react';
import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
import { addDataToMap, wrapTo } from '@kepler.gl/actions';
import KeplerGl from '@kepler.gl/components';
import { processKeplerglJSON } from '@kepler.gl/processors';
import styled from 'styled-components';

import cadastreData from './data/kepler.gl.json'

const StyledWrapper = styled.div`
  position: absolute;
  width: 100vw;
  height: 100vh;
`;

export default class FreshMap extends Component {

  static contextType = SelectedNamesContext;

  componentDidMount() {

    this.props.dispatch(addDataToMap(processKeplerglJSON(cadastreData)));
  }

  render() {
    const { id } = this.props;

    return (
      <StyledWrapper>
        <AutoSizer>
          {({ height, width }) => (
            <KeplerGl
              mapboxApiAccessToken={TOKEN}
              id={id}
              width={width}
              height={height}
            />
          )}
        </AutoSizer>
      </StyledWrapper>
    );
  }
}

And here’s how I call it in my app.js,

class App extends Component {
  render() {

    return (
      <div style={{ position: 'absolute', width: '100%', height: '100%' }}>
        <SelectedNamesProvider>
          <TabView> // tab from primereact
            <TabPanel header="dashboard">
              // ...
            </TabPanel>
            <TabPanel header="map">
              <div height='500px'>
                <FreshMap
                  dispatch={this.props.dispatch}
                  id="foo">
                </FreshMap>
              </div>
            </TabPanel>
          </TabView >
        </SelectedNamesProvider>
      </div >
    );
  }
}

const mapStateToProps = state => state;
const dispatchToProps = dispatch => ({ dispatch });

export default connect(mapStateToProps, dispatchToProps)(App);

Here’s my store.js:

import keplerGlReducer from '@kepler.gl/reducers';
import {legacy_createStore, combineReducers, applyMiddleware} from 'redux';
import {taskMiddleware} from 'react-palm/tasks';

import appReducer from './app-reducer';

const reducer = combineReducers({
  // <-- mount kepler.gl reducer in your app
  keplerGl: keplerGlReducer,

  // Your other reducers here
  app: appReducer
});

// create store
export default legacy_createStore(reducer, {}, applyMiddleware(taskMiddleware));

appReducer:

import { createAction, handleActions } from 'redux-actions';

// CONSTANTS
export const INIT = 'INIT';

// ACTIONS
export const appInit = createAction(INIT);

// INITIAL_STATE
const initialState = {
  appName: 'highqmap',
  loaded: false,
  modal: null,
  selectedNames: []
};

// REDUCER
const appReducer = handleActions(
  {
    [INIT]: (state, action) => ({
      ...state,
      loaded: true
    }),
  },
  initialState
);

export default appReducer;

And here’s my package.json:

{
  "name": "highqmap",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "assert": "^2.1.0",
    "chart.js": "^4.4.3",
    "chartjs-plugin-zoom": "^2.0.1",
    "kepler.gl": "^3.0.0",
    "primeflex": "^3.3.1",
    "primeicons": "^7.0.0",
    "primereact": "^10.7.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4",
    "webpack": "^5.93.0"
  },
  "scripts": {
    "start": "react-scripts --openssl-legacy-provider start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

ngx-mat-intl-tel-input not working properly in Angular 17

I am using Angular 17,
with following Versions/Details

Angular CLI: 17.3.8
Node: 18.20.2
Package Manager: npm 10.5.0
OS: linux x64
Angular: 17.3.12

I want to import library ngx-intl-tel-input to validate phone number with country Code.
I just checked following both:

https://www.npmjs.com/package/ngx-intl-tel-input

https://www.npmjs.com/package/ngx-intl-tel-input-gg

package.json file packages:

"google-libphonenumber": "^3.2.38",
"intl-tel-input": "^17.0.3",
"ngx-intl-tel-input": "^3.2.0",

angular.json File changes:

"styles": [
    "node_modules/ngx-toastr/toastr.css",
    "node_modules/intl-tel-input/build/css/intlTelInput.css",
    "src/styles.scss"
],
"scripts": [
    "node_modules/jquery/dist/jquery.min.js",
    "node_modules/intl-tel-input/build/js/intlTelInput.min.js",
]

And also import module in app-component

I can see a text box with country flag and I can enter phone number.

However, when I click on country flag the drop down does not open

hyphens: Only with Javascript [closed]

Is there a way to achive exactly the same thing hyphens: auto; in css does with pure Javascript?

I already found libraries for that, such as Hyphenopoly, but it does not work as I excpected it.
Can someone provide a solution or an idea, how to solve this issue?

Thank you all in advance.

I tried to solve it via Hyphenopoly, but it is very complex and primarily for speperating every word, not only the words that breaks at the end of a certain width.

Developing Arabic JavaScript search code in Laravel 11

I have finished writing the code to search for members and their specialties and I am taking my data from the database

I faced a problem in entering the search as it does not give me correct results from the search and I noticed that the Arabic language is not supported in the search when I enter.

Knowing that the search is open and there are no search conditions. If the search result matched, show me the result .

functions.js

import $ from 'jquery';

// Search functionality
$(document).ready(function() {
// Attach keyup event listener to the search input
$("#searchInput").on("keyup", function() {
// Get the current value of the input and convert it to lowercase
var value = $(this).val();

            // Filter the table rows based on the input value
            $("#tableBody tr").filter(function() {
                // Toggle the visibility of the row based on whether it contains the search value
                $(this).toggle($(this).text().indexOf(value) > -1);
            });
        });
    });

members.blade.php

 <input class="form-control mb-3" id="searchInput" type="text" placeholder="Search...">

        <!-- Table with Search and Filter -->
        <div class="table-container">
    <table class="table table-bordered">
        <thead>
            <tr>
                <th scope="col">ID</th>
                <th scope="col">Name</th>
                <th scope="col">role</th>
            </tr>
        </thead>
    
        <tbody id="tableBody">
            @foreach($members $member)
                <tr>
                    <th scope="row">{{ $member->id }}</th>
                    <td>{{ $member->name ?? 'no data'}}</td>
                    <td>{{ $member->role->name ?? 'no data'}}</td>
                    <td>
                    <button @click="UpdateMember = true; currentMember = {{ $member->toJson() }}" class="bg-green-500 text-white px-4 py-2 rounded">تعديل</button>
    
                        <!-- <a href="'member.edit', $member->id) " class="btn btn-primary">Edit</a> -->
                        <form action="{{ route('member.destroy', $member->id) }}" method="POST" style="display: inline-block;">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn btn-danger">حذف</button>
                        </form>
                    </td>
                </tr>
        </tbody>
        @endforeach
    
    </table>
    </div>

How to preserve links when copying text from an HTML element with JS

I’m trying to copy rich text where the links from HTML elements are preserved but I can’t figure it out no matter how many times I try.

The code below is the best I can come up with, but it only copies text without preserving the links

const tempElem: HTMLDivElement = document.createElement("div");
tempElem.innerHTML = responseBody;

console.log("running clipboard.write()....");

try {
  navigator.clipboard.write([
    new ClipboardItem({
      "text/html": new Blob([tempElem.innerText], {
        type: "text/html",
      }),
      "text/plain": new Blob([tempElem.innerText], {
        type: "text/plain",
      }),
    }),
  ])

  console.log("Rich text copied to clipboard");
} catch (err) {
  console.error("Failed to copy: ", err);
}

show the user the id of the ticket submitted on google forms using appscript

i’m trying to create a form for 502 users to submit tickets on google forms to show the id of the ticket to the user as a confirmation message and to the team who is going to solve it the id is added correctly to the sheet but to the user it shows the id of the previously submitted form
this is the code i know the problem is in getLastRow() so how to make it work please

function onFormSubmit(e) {
  
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const lastRow = sheet.getLastRow();
  const idColumn = 1;
  
   const ticketID = 'T-' + Utilities.formatString('%04d', lastRow);
  // const ticketID = lastRow
  
  sheet.getRange(lastRow, idColumn).setValue(ticketID);

  
  Logger.log('New ticket ID: ' + ticketID);

  // Update the confirmation message in the form
  const form = FormApp.openById('1oxTnzU5NRnzAlNFMmyehSf9vkORLs9vj5-XGGDvfqM0'); 
  const message = 'Thank you! Your ticket number is: ' + ticketID;
  form.setConfirmationMessage(message);
}

Response sheet

How to make vue3 (with vite) and vuetify3 work with chrome 70+?

I’m running vue3 using vite. Everything works well on Chrome 90, but when I run the app on Chrome 70, I get the error “Cannot convert undefined or null to object”.

I managed to narrow the problem down, it comes from the function “genCssVariables”. In that function, it tries to execute for (const [key, value] of Object.entries(theme.colors)).

I tried to add to the vite.config.js legacy but it didn’t help.
This is the vite.config.js:

export default defineConfig({
    plugins: [
        vue(),
        vuetify(),
        legacy({
            targets: ["defaults", "not IE 11", "Chrome >= 70"]
            moderPolyfills: true,
            additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
        }),
    ],
    build: {
        minify: false,
        target: ["es2015"],
    },
})

Java script for bookmarklet data extraction from an html monthly calendar schedule

I have a bookmarklet and java script with which I am extracting data from an html table from a website.
For the most part the script works fine however it parses the date wrong. The date, in the HTML table,
shows up only once for a particular day, it’s a schedule table with client bookings, but I need
to have the date on each parsed line so I have the script add it to each line of the parsed text.

See the actual HTML of the first three rows of the table at the bottom of the post. The names have been randomized.

This is the result the script outputs currently:

2024-08-02,40P 02:30N
2024-08-02,40P 02:30N
2024-08-02,40P 03:20N,10963 Jane Doe
2024-08-02,40P 04:10N
2024-08-02,40P 04:10N
2024-08-02,40P 05:00N
2024-08-02,40P 05:00N
2024-08-02,40P 06:00N,M7967 Mary Jane
2024-08-02,40P 06:50N,10840 Samurai Jack
2024-08-02,40P 07:40N,11286 Soldier Boy
2024-08-02,40P 11:00N,1498 John Oliver
2024-08-02,40P 11:50N,5750 Tommy Jones
2024-08-02,40P 01:20N,3846 Super Mario(Z)
2024-08-02,40P 02:10N,5136 Cold Spring
2024-08-02,40P 03:00N,5136 Cold Spring
2024-08-02,40P 04:10N,8606 The Duke
2024-08-02,60G 05:00N

This is what I want it to output:

2024-08-02,40P 02:30N
2024-08-02,40P 02:30N
2024-08-02,40P 03:20N,10963 Jane Doe
2024-08-02,40P 04:10N
2024-08-02,40P 04:10N
2024-08-02,40P 05:00N
2024-08-02,40P 05:00N
2024-08-02,40P 06:00N,M7967 Mary Jane
2024-08-02,40P 06:50N,10840 Samurai Jack
2024-08-02,40P 07:40N,11286 Soldier Boy
2024-08-03,40P 11:00N,1498 John Oliver
2024-08-03,40P 11:50N,5750 Tommy Jones
2024-08-03,40P 01:20N,3846 Super Mario(Z)
2024-08-03,40P 02:10N,5136 Cold Spring
2024-08-03,40P 03:00N,5136 Cold Spring
2024-08-03,40P 04:10N,8606 The Duke
2024-08-03,60G 05:00N

Notice the date change here 2024-08-03,40P 11:00N,1498 John Oliver. The script does not detect the date change
in the html and keeps on going with the 2nd, the next date change it does detect is the 5th.The date in html is <a href="/instructor/reserve/daily/D_2024-08-02/S_/">.

<table class="ta01" cellpadding="0" cellspacing="0" border="0">
<tr>
<th class="bg01013E" width="14%"><span class="wday0">Su</span></th><th class="bg01013E" width="14%"><span class="wday1">Mo</span></th><th class="bg01013E" width="14%"><span class="wday2">Tu</span></th><th class="bg01013E" width="14%"><span class="wday3">We</span></th><th class="bg01013E" width="14%"><span class="wday4">Th</span></th><th class="bg01013E" width="14%"><span class="wday5">Fr</span></th><th class="bg01013E" width="14%"><span class="wday6">Sa</span></th>
</tr>
<tr>
<td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">&nbsp;</div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">&nbsp;</div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">&nbsp;</div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">&nbsp;</div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">
            <div style="position:relative;top:4px;text-align:center;" class="wdate4">01</div>
        </div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">
            <div style="position:relative;top:4px;text-align:center;">
                <a href="/instructor/reserve/daily/D_2024-08-02/S_/"><span class="wdate5">02</span></a>
            </div>
        </div>
        <div style="padding:5px;text-align:left;"><div style="margin-bottom: 5px;"><div class="ico_bs crs_pr " style="font-size:11px;">40P 02:30N</div></div><div style="margin-bottom: 5px;"><div class="ico_en crs_pr " style="font-size:11px;">40P 02:30N</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 03:20N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">10963 Jane Doe</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_bs crs_pr " style="font-size:11px;">40P 04:10N</div></div><div style="margin-bottom: 5px;"><div class="ico_en crs_pr " style="font-size:11px;">40P 04:10N</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_bs crs_pr " style="font-size:11px;">40P 05:00N</div></div><div style="margin-bottom: 5px;"><div class="ico_en crs_pr " style="font-size:11px;">40P 05:00N</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 06:00N</div><div style="color:#f00; font-weight: bold; background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;"><span class="is_method">M</span>7967 Mary Jane</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 06:50N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">10840 Samurai Jack</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 07:40N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">11286 Soldier Boy</div></div></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">
            <div style="position:relative;top:4px;text-align:center;">
                <a href="/instructor/reserve/daily/D_2024-08-03/S_/"><span class="wdate6">03</span></a>
            </div>
        </div>
        <div style="padding:5px;text-align:left;"><div style="margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 11:00N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">1498 John Oliver</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 11:50N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">5750 Tommy Jones</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 01:20N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">3846 Super Mario(Z)</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 02:10N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">5136 Cold Spring</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 03:00N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">5136 Cold Spring</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 04:10N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">8606 The Duke</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_gr " style="font-size:11px;">60G 05:00N</div></div></div>
        </td>
</tr>

<tr>
<td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">
            <div style="position:relative;top:4px;text-align:center;" class="wdate0">04</div>
        </div>
        <div style="height:50px;"></div>
        </td><td style="padding:0;">
        <div style="background:#D8D6CC;height:28px;">
            <div style="position:relative;top:4px;text-align:center;">
                <a href="/instructor/reserve/daily/D_2024-08-05/S_/"><span class="wdate1">05</span></a>
            </div>
        </div>
        <div style="padding:5px;text-align:left;"><div style="margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 02:30N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">0858 Magellan</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 03:20N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">11206 Little Car</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 04:10N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">10402 Big Tom/10578 Little Tom</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_bs crs_pr " style="font-size:11px;">40P 05:00N</div></div><div style="margin-bottom: 5px;"><div class="ico_en crs_pr " style="font-size:11px;">40P 05:00N</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_en crs_pr capa_full" style="font-size:11px;">40P 06:00N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">4577 Sunflower</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_bs crs_pr capa_full" style="font-size:11px;">40P 06:50N</div><div style="background:#D3E5ED;line-height:14px;margin:4px 0;padding:2px 4px;font-size:80%;">7367 Jane Doe(Z)/7366 John Doe(Z)</div></div><div style="border-top: 2px solid #f00; padding-top: 10px; margin-bottom: 5px;"><div class="ico_bs crs_pr " style="font-size:11px;">40P 07:40N</div></div><div style="margin-bottom: 5px;"><div class="ico_en crs_pr " style="font-size:11px;">40P 07:40N</div></div></div>
        </td><td style="padding:0;">

And here is the script:

javascript:(function() {
  var table = document.querySelector('table.ta01[cellpadding="0"][cellspacing="0"][border="0"]');
  var output = [];
  var rowData = [];
  var currentDate = "";

  if (table) {
    table.querySelectorAll('tr').forEach(function(row) {
      var dateLinks = row.querySelectorAll('a[href^="/instructor/reserve/daily/D_"]');
      currentDate = dateLinks.length > 0 ? dateLinks[0].getAttribute('href').match(/D_(d{4}-d{2}-d{2})/)[1] : "";

      row.querySelectorAll('div[class^="ico_"]').forEach(function(div) {
        var text = div.textContent.trim();
        var extraInfo = div.nextElementSibling;

        if (extraInfo && extraInfo.style && extraInfo.style.backgroundColor == "rgb(211, 229, 237)") {
          text += "," + extraInfo.textContent.trim();
        }

        if (text) {
          rowData.push(text);
        }
      });

      if (rowData.length > 0) {
        rowData = rowData.map(function(line) {
          return currentDate + "," + line;
        });
      }

      output = output.concat(rowData);
      rowData = [];
    });

    var csv = "data:text/csv;charset=utf-8," + encodeURIComponent(output.join("n"));
    var link = document.createElement("a");
    link.href = csv;
    link.download = "schedule.csv";
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
  } else {
    alert("Table not found!");
  }
})()

Dependency (upstream) services are undefined with no useful error when doing e2e testing using Jest

This is in NestJs, using Jest. I am trying to test my controller, which relies on my “main” service. I wish to perform e2e testing on the controller. (To clarify, my smaller unit tests of the dependency services are all working fine – no issues there.)

My controller’s constructor and first method I am testing look like this:

export class MyController{
constructor(
private aService: AService,
private bService: BService,
//etc etc multiple such services
) {}

@Post('/login')
async login(@Body() logDto: LogDTO)
{
console.log('aService: ' + this.aService);
console.log('bService: ' + this.bService);
//etc etc
//then the code
}
}

I’ve set up the test as normal, tediously importing everything, mocking repos, etc, and when I missed things, I got an error saying I missed importing some service or so on.

My very first test in the spec.ts is:

//controller, aService, bService, etc were all defined in the beforeEach block
it('should be defined', () => {
expect(controller).toBeDefined();
expect(aService).toBeDefined();
expect(bService).toBeDefined();
//etc
}

This test is passing. Everything is defined fine in my spec.ts. However, the moment I try to run a test involving the actual controller.ts, I get errors like “Cannot read properties of undefined” the moment I try to execute a method from a dependency service. And, those console.logs confirm that the dependency services are all undefined in the actual controller itself.

I tried to ensure that I didn’t miss any imports, but without any actually useful error messages, I’m completely stuck. I’ve never done E2E testing with Jest before, so this is completely new ground for me, too.

How can avoid nested forEach loops for this tabbed content script?

I have made a small script in JavaScript for tabbed content.

(function() {
  let contentElms = document.querySelectorAll('.content > div');
  let tabs = document.querySelectorAll('.tabs li');

  // Show first tab initially
  contentElms[0].classList.add("active");
  tabs.forEach((tab, index) => {
    tab.addEventListener("click", () => {
      // Toggle tabs
      tabs.forEach((tab) => {
        tab.classList.remove("active")
      });
      tab.classList.add("active");

      // Toggle content
      contentElms.forEach((el) => {
        el.classList.remove("active")
      });

      contentElms[index].classList.add("active");
    });
  });
})();
body {
     margin: 0;
     padding: 0;
     font-family: Arial, Helvetica, sans-serif;
}
 body * {
     box-sizing: content-box;
}
 .tabbed-content {
     max-width: 600px;
     margin: 10px auto;
}
 .tabbed-content .tabs ul {
     list-style-type: none;
     margin: 0;
     padding: 0;
     display: flex;
}
 .tabbed-content .tabs ul li {
     flex: 1;
     border: 1px solid rgba(0, 0, 0, 0.1);
     border-radius: 4px 4px 0 0;
     overflow: hidden;
}
 .tabbed-content .tabs ul li.active {
     border-bottom: none;
     font-weight: bold;
}
 .tabbed-content .tabs ul a {
     display: block;
     padding: 10px;
     text-align: center;
     text-decoration: none;
     color: #7f7f7f;
}
 .tabbed-content .content {
     padding: 10px;
     border: 1px solid rgba(0, 0, 0, 0.1);
     border-top: none;
     border-radius: 0 0 4px 4px;
}
 .tabbed-content .content > div {
     font-size: 14px;
     line-height: 1.5;
     text-align: justify;
     display: none;
}
 .tabbed-content .content > div.active {
     display: block;
}
 
<div class="tabbed-content">
  <nav class="tabs">
    <ul>
      <li class="active"><a href="#">Tab 1</a></li>
      <li><a href="#">Tab 2</a></li>
      <li><a href="#">Tab 3</a></li>
    </ul>
  </nav>
  <div class="content">
    <div>Nesciunt velit a hic, officia animi veritatis quis obcaecati tempora omnis iusto.</div>
    <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias dolorem, sequi quos unde tempora corporis voluptatibus officia atque voluptatum consequuntur necessitatibus fuga quidem nihil. Perspiciatis reiciendis impedit cupiditate odit veritatis!</div>
    <div>Deserunt est in, ipsum possimus dolorum! Numquam suscipit laborum, reiciendis delectus. Labore?</div>
  </div>
</div>

The tabs work fine.

The problem

I am unhappy with the fact that there are nested forEach loops in the script.

Questions

  1. Is there any (reliable) way to avoid that?
  2. Can I have just one forEach loop in the script?

ScrollSmoother paused/resumed leads to stopping and disturbing the scroll after resumed smoothness

I have replicated the issue and implemented a sample 3 pager nuxt app using stackblitz platform for you take reference. I am clicking on More Details button from Portfolio detail page and popup opens and scrollSmoother instance is pausing correctly and popup position is perfect. But when I close the popup scrollSmoother instance isn’t resumed as expected and scroll get disturbed and I implemented the resume as well. Can you please help here.

https://stackblitz.com/edit/nuxt-starter-5s4aqy?file=pages%2Fportfolio%2F[id].vue,app.vue,helpers%2Fgsap%2FInitGSAP.js

TypeError: document.getElementsById is not a function [closed]

Here is my code :

function Nhap(first,last,age,year){
    this.FirstName=first;
    this.LastName=last;
    this.personAge=age;
    this.personYear=year;

    this.fullinfo=function() {
        return this.FirstName +" "+ this.LastName
    };
}
    const myBrother = new Nhap("Minh","Do",15,2010);
    document.getElementsById("p1").innerHTML= myBrother.fullinfo();

i try to change and see some example in w3 but it not stop give me error

Ensure DOM elements are ready before triggering GSAP animations with useGSAP in React

Question: Is there any better way to rewrite my code without using setTimeout?

use useGSAP in React.

If I use console.log(parentRef) in child.tsx, it will get null.

parent.tsx

export default function Page() {
  const parentRef = useRef(null);

  return (
    <main className="flex min-h-screen flex-col p-6">
      <div
        className="flex h-20 shrink-0 items-end rounded-lg bg-dark-slate-gray p-4 md:h-52"
        ref={parentRef}
      >
        <Logo parentRef={parentRef} />
      </div>
    </main>
  );
}

child.tsx

export default function Logo({ parentRef }: LogoProps) {
  const container = useRef<HTMLDivElement>(null);

  const setupAnimation = () => {
    const parentWidth = parentRef.current?.getBoundingClientRect().width;
    gsap.to(container.current, { x: parentWidth, rotation: 10 });
  };

  useGSAP(
    () => {
      setupAnimation();
    },
    { scope: container }
  );

  return (
    <div
      className={`${lusitana.className} flex flex-row items-center leading-none text-wheat`}
      ref={container}
    >
      <GlobeAltIcon className="h-12 w-12 rotate-[15deg]" />
    </div>
  );
}

I tried adding setTimeout to my code, and it worked correctly. It ensures that parentRef elements are fully rendered before being accessed.

child.tsx

useGSAP(
  () => {
    setTimeout(() => {
      setupAnimation();
    }, 100);
  },
  { scope: container }
);

JavaScript Fetch API Error When Sending GET Request Using URL Parameter

I’m trying to send a GET request to an API to fetch courses based on a category specified in the URL. I’m using the fetch API in JavaScript to do this, but I’m encountering an error. The code I’m using is as follows:

// Function for getting key from URL

const getUrlParams = (key) => {
  const urlParams = new URLSearchParams(location.search);
  return urlParams.get(key);
};

// Function to fetch courses based on category

  const getAndShowCategoryCourses = async () => {
    let categoryName = getUrlParams("cat");

    const res = await fetch(
     `http://localhost:4000/v1/courses/category/${categoryName}`
   );
    const courses = await res.json();
    return courses;
   };

Expected Behavior: The function should fetch and log the list of courses based on the cat parameter from the URL.

Actual Behavior: Instead of fetching the courses, I get the error:

[ “message”: “this route is protected and you can’t have access to it.”]

Browser/Environment: I’m testing this on Chrome and the backend tech are node and MongoDB.

Backend Details: The API is running on a local server at http://localhost:4000/v1/courses/category/:categoryName.

Steps Taken:
I verified that the cat parameter is correctly retrieved using getUrlParams,
and when I’m testing this API using postman with this API (http://localhost:4000/v1/courses/category/backend) and it gives me the same error:

[ “message”: “this route is protected and you can’t have access to it.”]

Variables names in callbacks [closed]

I’m working on a JavaScript project, and there’s a debate within my team regarding the use of short vs. descriptive variable names in inline callbacks. Here are two versions of the same piece of code:

My code:

const nextSelectedLabels = items
  .filter(i => i.selected)
  .map(i => this.filteredVehicleProjects.find(p => p.name === i.itemData['label']))
  .map(p => ({ label: p.name, sublabel: p.businessProject.projectName, td: p }));

Suggested by My Team:

const nextSelectedLabels = items
  .filter(item => item.selected)
  .map(item => this.filteredVehicleProjects.find(project => project.name === item.itemData['label']))
  .map(project => ({ label: project.name, sublabel: project.businessProject.projectName, td: project }));

While I prefer the shorter variable names for conciseness, my team argues that the longer, more descriptive names is better and we should use it everywhere.

I completely agree with using descriptive names for methods, classes, function names, and arguments. However, I feel that using long, descriptive names for one-line callbacks is overkill and does not help much in readability.

Are there best practices or guidelines that suggest when to use one approach over the other? Wdyt?

Thanks !