How to close the dropdown menu if user clicks outside the dropdown menu using react-select AsyncPaginate

So it’s a known bug of react-select AsyncPaginate where the dropdown closes as soon as you select an option in a multi-option dropdown. Which shouldn’t be the case.
Basically ‘closeMenuOnSelect’ doesn’t work as intended if we use Creatable react-select.

So I am left with no option but to have a workaround using useRef. Intention is to close the dropdown menu if the user clicks outside the dropdown menu. However, I do not know how to hook the ref with the dropdown menu, since I can’t access it’s div.

export const AsyncSelectField = ({props}) => {
  const [menuOpen, setMenuOpen] = useState(false);
  const dropDownRef = useRef(null);

  const handleMenuClose = () => {
    if (isMulti) {
      // If isMulti is true, reopen the menu
      setMenuOpen(true);
    } else {
      // Otherwise, just close the menu
      setMenuOpen(false);
    }
  };

  useEffect(() => {
    const handleClickOutside = (event) => {
      if (dropDownRef.current && !dropDownRef.current.contains(event.target)) {
        setMenuOpen(false);
      }
    };

    document.addEventListener('mousedown', handleClickOutside);
    return () => {
      document.removeEventListener('mousedown', handleClickOutside);
    };
  }, [menuOpen]);
 }

  const Option = (props) => {
    return (
      <components.Option {...props}>
        <RenderOption {...props} />
      </components.Option>
    );
  };

  // single select
  const SingleValue = (props) => {
    return (
      <components.SingleValue {...props}>
        <RenderSingleValue {...props} />
      </components.SingleValue>
    );
  };

  const CreatableAsyncPaginate = withAsyncPaginate(Creatable);
  const AsyncPaginateField = useMemo(
    () => (isCreateable ? CreatableAsyncPaginate : AsyncPaginate),
    [CreatableAsyncPaginate, isCreateable],
  );

return (
    <AsyncSelectFieldStyled ref={dropDownRef} className={className} disabled={disabled}>
      {label && (
        <div className="label" data-testid="label">
          <Typography color="#2B3952">{label}</Typography>
          {optional && <div className="optionalField">(Optional)</div>}
          {description && (
            <div data-testid="description" className="info-icon">
              <Description description={description} />
            </div>
          )}
        </div>
      )}
      <AsyncPaginateField
        key={id}
        id={id}
        className="async-paginated-select"
        classNamePrefix="react-select"
        value={value}
        isMulti={isMulti}
        closeMenuOnSelect={!isMulti}
        menuIsOpen={menuOpen}
        onMenuClose={handleMenuClose}
        onMenuOpen={() => setMenuOpen(true)}
        hideSelectedOptions={hideSelectedOptions}
        options={options}
        loadOptions={loadOptions}
        loadOptionsOnMenuOpen={false}
        onChange={(newValue) => onChange(newValue)}
        placeholder={placeholder}
        getOptionValue={(option) => option.value}
        backspaceRemovesValue={backspaceRemovesValue}
        getOptionLabel={(option) => option.label}
        isClearable={isClearable}
        isOptionDisabled={isOptionDisabled}
        components={{
          Option,
          SingleValue,
          IndicatorSeparator: () => <span />,
          DropdownIndicator: () =>
            isLoading ? (
              <Box className="loading-bar-wrapper">
                <Loader isCircular size={15} />
              </Box>
            ) : (
              showDropdownIcon && <div className="caret-icon">{<ArrowDropDownIcon />}</div>
            ),
          ...(!showMenuList && { MenuList: () => null }),
        }}

What can I do to make this work? How can I assign the ref to the dropdown menu?

how to call a function upon giving the same text as before for a input field

I need to call a function myFunc() upon changing the value of the input field to the same text as before and for some reason for my test case I don’t want to use onBlur() event.

For Example:

<html>
<body>

Enter your name: <input type="text" id="fname" onchange="myFunc()">

<script>
function myFunc() {
  var x = document.getElementById("fname");
  x.value = x.value.toUpperCase();
}
</script>

</body>
</html>

Here first I give the input “Martin” it calls the function, now again if I type “Martin” I need to call that function.

vanillajs-datepicker does not set input value, no change event triggered on date click

I’m using this datepicker and I like it but its not triggering the change event on an input after I click a date.

Here is my code
I tested this on jsFiddle

const elem = document.querySelector('input[name="foo"]');
const datepicker = new Datepicker(elem, {
  autohide: true,
  todayHighlight: true,
  format: "yyyy-mm-dd",
});

elem.addEventListener("change", function(e) {
  console.log(e.target.value);
});
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/datepicker.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/datepicker-full.min.js"></script>

<input type="text" name="foo">

When I click the specific date on the datepicker the change event is not triggered.

I need help with this.

I’m also using it with livewire and alpine but after clicking the date the change even is not triggered. here is my laravel code
code

When I tested pickaday it works.

How can I work around this or make it to trigger the change even on vanillajs datepicker.

Thanks in advance.

Changing state of checkboxes using jQuery

I am trying to develop a JQuery script to change the state of a checkbox by setting the disabled attribute to true depending on the state of a different checkbox.

I have three checboxes – suspended, option1 and option2

Using the below code, thn clicking the suspended checkbox, the other two are disabled. If I uncheck the suspended box, they are then availble (disabled attr removed).

I would like to apply the same logic atpage load. My code is below:

(function( $ ) {
    'use strict';

    $( document ).ready(function() {
        if( $('input[name="suspended"]').is(':checked')){
            console.log( "Suspended is checked" );
            $('input[name="option1"]' ).attr("disabled", true);
            $('input[name="option2"]' ).attr("disabled", true);
        }
        else{
            console.log( "Suspended is unchecked" );
            $('input[name="option1"]' ).removeAttr("disabled");
            $('input[name="option2"]' ).removeAttr("disabled");

        }

        $( 'input[name="suspended"]' ).change( function( e ){
            e.preventDefault;
            if ($(this).is(':checked')) {
                $('input[name="option1"]' ).attr("disabled", true);
                $('input[name="option2"]' ).attr("disabled", true);
            }else {
                $('input[name="option1"]' ).removeAttr("disabled");
                $('input[name="option2"]' ).removeAttr("disabled");
            }option2
            
        } );

    });

})( jQuery );

I have obviously solved the change state of click situation, but canno’t work out why it doesnt not also work on page load. I am able to get a concole.log message to display the state at page load, but chnage the state of the checboxes.

Screen Recording with Video results in fragmented audio in the recording

I was trying to implement the Screen Recording With Video using the RecordRTC library, but found out that while using the example shown in

https://www.webrtc-experiment.com/RecordRTC/simple-demos/show-logo-on-recorded-video.html

results in segmented audio in the recording.

If you go to the link and start recording, and say aaaaaaaaaaaaaaaaaaaa, then the recording outputs the audio like aaaa aaa aaa.

Is this a bug in RecordRTC?
Is there any way to get smooth audio and video in the recording while using canvas recording?

Thanks for your help in advance.

Does Google have any kind of support for creating Google meet bots? [closed]

I have been trying to develop a bot that is basically doing what Otter, Firefly, etc already do. My problem is that I cannot find much or any support from Google to create these. I can make this bot work using selenium stealth, a reCaptcha2 solver, rotating user agents and ip adresses, but I refuse to believe that these big companies are doing this and automating browsers because it breaks googles TOS on multiple fronts.

Any of you guys know how these Google Meet bots are being created?

I am trying to use Date.now() in javascript and its returning 0 instead of the value in miliseconds

const display = document.getElementById("display");

let timer = null;
let startTime = 0;
let elapsedTime = 0;
let isRunning = false;

function start(){
    if(isRunning){
        startTime = Date.now()
    }

    console.log(startTime);
}

I already have a css and Html file linking to this start function and the rest of the code is incomplete but this Date.now() should be giving me a value and its not. having a feeling its VS code thats causing my issue, because on the console Date.now() works perfectly

I am trying to make a stop watch and Date.now() should be giving me a value but its returing 0

TypeError: Cannot read properties of null (reading ‘fn’)

Error:
When trying to compile the Next.js project, the following error occurs:

TypeError: Cannot read properties of null (reading 'fn')
    at /path/to/file/bundle5.js:13:29685
    ...

Relevant Files:

package.json:
{
  "name": "web-feature-store-v2",
  "version": "0.1.0",
  "private": false,
  "scripts": {
    "dev": "next dev",
    "build": "next build && npx tailwind -i app/globals.css -o app/tailwind.css",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@chakra-ui/react": "^2.8.0",
    "@emotion/react": "^11.11.1",
    "@emotion/styled": "^11.11.0",
    "@google-cloud/storage": "^7.5.0",
    "@module-federation/enhanced": "^0.1.8",
    "@module-federation/nextjs-mf": "^6.1.3",
    "@mui/icons-material": "^5.14.1",
    "@mui/material": "^5.14.2",
    "@mui/x-data-grid": "^6.10.2",
    "@radix-ui/colors": "^3.0.0-rc.4",
    "@radix-ui/primitive": "^1.0.1",
    "@radix-ui/react-checkbox": "^1.0.4",
    "@radix-ui/react-dropdown-menu": "^2.0.5",
    "@react-oauth/google": "^0.11.1",
    "@reduxjs/toolkit": "^1.9.5",
    "@tanstack/react-query": "^4.33.0",
    "@tanstack/react-table": "^8.9.7",
    "@types/chart.js": "^2.9.40",
    "@types/node": "20.4.5",
    "@types/react": "18.2.17",
    "@types/react-dom": "18.2.7",
    "axios": "^1.4.0",
    "bootstrap": "^5.3.1",
    "chart.js": "^4.4.0",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.0.0",
    "dotenv": "^16.3.1",
    "encoding": "^0.1.13",
    "env-cmd": "^10.1.0",
    "eslint": "8.46.0",
    "eslint-config-next": "13.4.12",
    "framer-motion": "^10.16.2",
    "fs": "^0.0.1-security",
    "lib-utils-ts": "^2.0.4-stable",
    "lucide-react": "^0.274.0",
    "net": "^1.0.2",
    "next": "13.4.12",
    "next-auth": "^4.22.3",
    "react": "18.2.0",
    "react-bootstrap": "^2.8.0",
    "react-chartjs-2": "^5.2.0",
    "react-dom": "18.2.0",
    "react-modal": "^3.16.1",
    "react-redux": "^8.1.2",
    "reactjs-popup": "^2.0.6",
    "reactstrap": "^9.2.0",
    "sharp": "^0.32.4",
    "tailwind-merge": "^1.14.0",
    "tailwindcss-animate": "^1.0.7",
    "typescript": "5.1.6"
  },
  "devDependencies": {
    "@faker-js/faker": "^8.0.2",
    "@types/react-modal": "^3.16.0",
    "autoprefixer": "^10.4.14",
    "json-loader": "^0.5.7",
    "postcss": "^8.4.27",
    "react-router-dom": "^6.14.2",
    "tailwindcss": "^3.3.3"
  },
  "browser": {
    "child_process": false,
    "fs": false,
    "tls": false
  },
  "resolutions": {
    "webpack": "5.1.3"
  }
}

index.tsx

import dynamic from "next/dynamic"
import { NextFederationPlugin } from '@module-federation/nextjs-mf';

const ContainerPage = dynamic(() => import ('container/App').then(module => module.default));

export default function Doapprove(){
    return (
        <>
            <div className="flex flex-col">
                <div id="remote-container">
                    <ContainerPage />
                </div>
            </div>
        </>
    )
}

next.config.js


module.exports = {
  plugin: [
    new NextFederationPlugin({
      name: 'WebFS',
      remotes: {
        container: `container@https://xxxx-Xxxx-xxxx-dev.xxxnet.com.br/_next/static/chunks/remoteEntry.js[getRandomString()]`,
      },
      filename: 'static/chunks/remoteEntry.js',
      shared: {
        // whatever else
      },
    })
  ]
}

Description:
When attempting to compile the Next.js project with webpack, a type error occurs during the compilation process. The error mentions “TypeError: Cannot read properties of null (reading ‘fn’)”, indicating that there is an issue during the execution of a function somewhere in the code.

I expected the solution

Pausing in Phaser

I’m developing a game where if an enemy gets closer to a certain x value, the game should pause, switch to another scene. where a question will be asked. if they answer the question right, the first scene will be resumed. and all the scores will be stored, and basically the game just resumes from where it stopped

I’m not able to figure it out. When I switch to a different scene., the progress in the first scene is lost. Pls help

Set a cookie from subdomain to all subdomains

I’m working on a NextJS project where I have multiple apps on separate subdomains. My goal is to login in one app and automatically signed in at every other. We’re using nookies as cookie handler, creating a cookie with a JWT token payload received from an API. I thought if I set the cookie domain manually then it’s going to set the cookie on the main domain but it did not happen.

Here’s what I’ve tried:

setCookie(
    null,
    "token",
    `JWT ${data.tokenAuth.token}`,
    {
        maxAge: 29 * 24 * 60 * 60,
        path: "/",
        domain: process.env.NEXT_PUBLIC_COOKIE_DOMAIN,
    }
);

I’ve set the NEXT_PUBLIC_COOKIE_DOMAIN as "example.com" and ".example.com", neither of them worked, my cookie was always set to the current subdomain. I also got the idea to put the login page under “example.com/login” to set the cookie on the main domain so I can access it everywhere, but I wonder if there’s a solution to avoid it. I’ve already read about RFC 6265, from which I assume it’s only possible from the main domain, yet the tracking took we’re using somehow can assign “.example.com” for it’s cookie. What am I missing? Thanks for replies in advance.

Why is this bringing back a filled array?

I am trying to find out what venues are opened at present using a filter, the thing works well when the time is in between and after the time is not. Then come late night and everything changes.

I am using Moment JS to compare the time now Hour to the close and open in an object.

The object has this format

value = [ {
  "id" : "place_01",
    "name" : "Place One",
    "location" : "Location One",
    "hours" : [
    {"day": "Sunday", "day_id": 0,
    "hours": "9:00 AM - 5:00 PM", "open": "9:00 AM", "close": "5:00 PM", "tags": "" },
    {"day": "Monday", "day_id": 1,
    "hours": "9:00 AM - 5:00 PM", "open": "9:00 AM", "close": "5:00 PM", "tags": "" },
    {"day": "Tuesday", "day_id": 2,
    "hours": "9:00 AM - 5:00 PM", "open": "9:00 AM", "close": "5:00 PM", "tags": "" },
    {"day": "Wednesday", "day_id": 3,
    "hours": "9:00 AM - 5:00 PM", "open": "9:00 AM", "close": "5:00 PM", "tags": ""  },
    {"day": "Thursday", "day_id": 4,
    "hours": "9:00 AM - 5:00 PM", "open": "9:00 AM", "close": "5:00 PM", "tags": "" },
    {"day": "Friday", "day_id": 5,
    "hours": "9:00 AM - 9:00 PM", "open": "9:00 AM", "close": "9:00 PM", "tags": "" },
    {"day": "Saturday", "day_id": 6,
    "hours": "9:00 AM - 9:00 PM", "open": "9:00 AM", "close": "9:00 PM", "tags": "" }
    ]
    }
]

This is the filter

 let f1 =  value.filter(item => item.hours.some((hour: { day_id: any; close: string; open: string; }) => hour.day_id == moment().format('d') && hour.open <= moment().format('LT') && hour.close >= moment().format('LT') ));

I wanted the filter to bring back value only when all variables are true.

i.e. If the day ID is # and the close if more than Moment() etc…

When the time is between both everything is great then for a few hours after it works fine, where it won’t bring back any values, then at nigh it starts bring values back, very weird.

How can I get this to only bring back values when the time it between xyz times on xyz day.

Calling Restlet from External Suitelet

I’ve been encountering some issues here and there with some externally available suitelets where certain issues occur that disappear when instead accessing the suitelet internally. For some of these issues, I was thinking a good workaround would be to offload the affected execution to a restlet. I’m working on the theory that the issues are based on whether or not a user is executing the code. My issue is that I’ve never been good with connecting to restlets, and what I’ve seen out there I believe is now outdated. I don’t think they allow username/password authentication to restlets these days. Is there a good reference to use that highlights the best way to call a restlet from within a suitelet? I can’t just directly use a restlet because the suitelet generates a web page for data entry, so I’m hoping this is feasible.

I’d like to link to a page that contains what they say to do, but it requires a NetSuite login to access. But I can detail out what it says, and where I have trouble.

So, they start by saying to determine the url and verb, which, yeah, ok, whatever, I already know that. Then they say to sort out the url parameters alphabetically with their values. Below I have a screen shot of their example.

sorted parameter key/value pairs

At this point, I’m not sure how to generate the nonce value or the timestamp value. I had done this once before, but in C#, and I don’t have the same libraries to utilize from within SuiteScript that I did using .NET. If there are external libraries that work well in SuiteScript, or methods available in the 2.0 API modules, that can generate those values, that would be great to know.

Moving on… It then says to concatenate the key/value pairs using an ampersand. Pretty much a standard url after the question mark. After that it says to url encode that string. Also not a problem. After that, they want a string something along the lines of HTTP_VERB%{url_encoded_base_url}&{url_encoded_parameter_string}. That’s also nothing I’m concerned with putting together. However, this next part is also something I’m not sure how to accomplish.

This next step states to sign this result string using the consumer secret and token secret using an ampersand. I’m really not sure how that’s supposed to be accomplished from within SuiteScript. After this, it wants that resulting value Base64 encoded, which is easy, and that value is to be url encoded. After that, I’m not sure how this value is supposed to be passed to the restlet for authentication. I assume it’s to be set to a header, but I think I’m overlooking what it is.

If field x is greater than y return value of 3

I am trying to create a formula for a scorecard where bonus points are calculated.

I need the formula to look as to which of the scores below is greater, and the greater of the two scores returns a value of 3 bonus points.

The lower of the two scores returns a value of 0.

  • HTP (Home Team Points) 147
  • ATP (Away Team Points) 148

ANSWER:

  • HTBP (Home Team Bonus Points) = 0
  • ATBP (Away Team Bonus Points) = 3

I tried this but it doesn’t return any values at all.

var HTP = Number(this.getField("HTP").valueAsString);
var ATP = Number(this.getField("ATP").valueAsString);

this.getField("HTBP").value = (HTBP&&ATBP) ? (HTP > ATP ? 3:0) : "";
this.getField("ATA").value = (HTBP&&ATBP) ? (HTP > ATP ? 0:3) : "";

Wechat group chat user sent the picture processing do not know how to deal with [closed]

@547d2d0783974e181576c60056ce2fdd3faf540e7437ff2a0c326af4182ca570b1aa57d45a28a81b5d9ae6b25f98e22a6d20eed07e5e3cbcb079d806d8acf290f8119e6da02bb6cd3533acb3c20dc67d5fd9e275f58e1686b4cbe7288349a2c35985d9ac8ac4191c1f3550f3da27c56cb2404afb6ca04d9ec277269a462c3bc1e4d86e7f7ae082f7beaaff1eed83fa78b74c5c4462832be2447575e31f928763f794545ed96692406813c84a205da9377733c2ba00a12d0d01939af15c2875460328683e5b3995eb671185694058ea40bd5021eb460aada569f040dc30125ddb85a42fda2821e6ec301e1d0ff50b9f4c5a1ca1ed458c47d7802cf280d44205ad11119579e7cb4cbc7fe6c8f39fb68bab551d923db9a88bb899516b1db89a53ca19f0048a70589115d3d45b860842b49cf12fcd9731e01498025ddbefcaebadec8b0bc947b6906b37ad0fb09ee3d178cf6ac7a67b128245c166569201167f6bea2ef2e85a92ae708a3309563a6ed5c40fd223bbd3b087466b63dfcb2167e0bf7a293ed4ac24c59978edd58c2d755b09f3734fa2cde9597ee149d12ed7f0b3d5416253eff6d098a8df3d718e2b627c9b9c922c274a0aa4cc5d6c2489875a235763c17ad16c9e4226951a59c50d489e554a1aa9ca66b5de90e875973da01f280a8262b4e9a7d83fff60dc471b495da75e3f9b8acdfda7fde9b581985754d71af4618a0a2c4b75c15fd79803887970fb045735e3a25c41aeddca4934a856c6b9e730c474821698693a0e49bc6dd47bfc8e516a17fd0a9e2e6649dd30632d00a3397242dcff0e7ac5949638309dce01ba74428d9e7f17bf97354db8cdcbead6c3f7478f52a828b2c4e9f9b988f0705e307ae17c8ec01b112e2e2a1ba0bb4f1783a3ea80853fc2fac5d66d7cc16ba2ef9a266f24309849ff105abdac63c99715289891fe83adcd8370ce8ba84f210abf91e7c73ade1a0e4d1ae0f7e07950aeb0ec9d9335e36a9c3f322f4c515cbc598d9e61178ee1b54b833afa3060c1a2f4975d3f3968afdf06a7e667ee0fed81ca5a0ead914778c3846a1e3e641fd7fa5d0e74cc57daec566c49f50ebc88a881745b4cf64d751facc833b6907f20f0b8615d61efafadaabdf4fa9e97521ce615caf662cfa9e983a0e5e3e71ae76a2b9d48a0b58e2b9c349786f0be21409421fa88c58a09ad4406f43a2b0e9f860cb1b9bafd57e717a0e385b93110d3215a2c5c35eab66234e94c2d725c291a37600c2e0c8f931dfa4224f3b5459f9cac03ebec5ed38a8f99123e12