google sheets into pdf via apps script

i am trying to merge selected google sheets tabs into one pdf
manage to get one work pdf export to drive but other two gives errors or the cell which has formulas shows #REF! in pdf output

need to add other 2 sheets named “Invprttwo” & “Invprtthree”
Please Help

function savepdftodrive() {
  var sheetName = "INVOICE";
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var invoicesheet = spreadsheet.getSheetByName(sheetName);
  var filename = "Invoice_" + invoicesheet.getRange("H5").getValue() + ".pdf";

  // Create export parameters for PDF
  var url = 'https://docs.google.com/spreadsheets/d/' + spreadsheet.getId() + '/export?';
  var exportOptions = {
    exportFormat: 'pdf',
    format: 'pdf',
    size: 'letter',
    portrait: true,
    fitw: true,
    sheetnames: false,
    printtitle: false,
    pagenumbers: false,
    gridlines: false,
    fzr: false,
    gid: invoicesheet.getSheetId(), // the sheet's ID
  };

  var params = [];
  for (var key in exportOptions) {
    params.push(key + '=' + exportOptions[key]);
  }
  var finalUrl = url + params.join('&');

  // Fetch the file from the URL
  var token = ScriptApp.getOAuthToken();
  var response = UrlFetchApp.fetch(finalUrl, {
    headers: {
      'Authorization': 'Bearer ' + token
    }
  });

  var blob = response.getBlob().setName(filename);

  // Get the parent folder
  var folder = DriveApp.getFileById(spreadsheet.getId()).getParents().next();

  // Check if the 'OldCopies' folder exists, if not create it
  var oldCopiesFolder;
  var subfolders = folder.getFoldersByName('OldCopies');
  if (subfolders.hasNext()) {
    oldCopiesFolder = subfolders.next();
  } else {
    oldCopiesFolder = folder.createFolder('OldCopies');
  }

  // Move existing files with the same name to the 'OldCopies' folder
  var existingFiles = folder.getFilesByName(filename);
  while (existingFiles.hasNext()) {
    var file = existingFiles.next();
    file.moveTo(oldCopiesFolder);
  }

  // Save the new PDF file to the folder
  folder.createFile(blob);
}

HTML, Css and javascript [closed]

I want to code a website where the users create their own custom cloth and i want them to drag and drop the images, I need it to be a box where they drop the cloths

I tried making a drag and drop rectangle, but it was limited to only one image, I was expecting it to be more than one image

Make JS function to return value instead of writing lengthy code inside onload=function()

Below is a function to detect if input file is a JPEG and (as tested), it works perfectly. Sorry to ask but I am not used to async nature of JS and want to know… if there is a way to make this function return a value and could be used like this:

MyMainFunction()  {
  // code goes in here
  // lengthy code block

  if ( validateFile() == false )  {
    // show warning
    return;
  }
  
  // keep writing code to process JPEG
  // and more as we get valid input
  // lengthy code...
 
}

function validateFile() {
  var blob = document.getElementById('filex1').files[0].slice(0,12);
  document.getElementById('filex1').value=null;
  var fileReader3 = new FileReader();
  fileReader3.readAsArrayBuffer(blob);
        
  fileReader3.onload = function(someVar) {
    var arr = (new Uint8Array(someVar.target.result)).subarray(0, 4);
    var header = "";
    for(var i = 0; i < arr.length; i++) {
      header += arr[i].toString(16);
    }
    if (['ffd8ffe0', 'ffd8ffe1', 'ffd8ffe2', 'ffd8ffe3', 'ffd8ffe8'].includes(header))  {
      console.log(header, ': JPEG File Detected');
/*    Continue writing a lengthy code here or call another
      function containing main code.
      While keeping blob, fileReader3 and all other variables
      in memory which are basically useless after
      detecting file type
*/
    }
    else    {
      console.log(header, ': Invalid File Type');
/*    Show warning to user and do nothing.. code ends here  */
    }
  }
}
<input type='file' id='filex1' onchange='validateFile()'>

Edit: I don’t want to use callback… I am already following the concept of calling my main function after the check is complete inside onload=function() block. And I don’t find myMainFunction a good fit to be declared as async.

CSS mix-blend-mode for maximum contrast

After going through all the blend modes, there seems to be no solution for maximum contrast. Ideally, the text should be only black or white, so that contrast can be maximized with any background color. Not sure if this is possible with css. See this example: https://codepen.io/YhomasV/pen/vYqRGyN

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <link rel="stylesheet" href="styles.css" />
    </head>
    <body>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: normal">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: normal">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: normal">Hello</p></div>
            <p class="a4">normal</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: screen">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: screen">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: screen">Hello</p></div>
            <p class="a4">screen</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: overlay">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: overlay">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: overlay">Hello</p></div>
            <p class="a4">overlay</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: darken">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: darken">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: darken">Hello</p></div>
            <p class="a4">darken</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: lighten">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: lighten">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: lighten">Hello</p></div>
            <p class="a4">lighten</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: multiply">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: multiply">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: multiply">Hello</p></div>
            <p class="a4">multiply</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: hue">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: hue">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: hue">Hello</p></div>
            <p class="a4">hue</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: saturation">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: saturation">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: saturation">Hello</p></div>
            <p class="a4">saturation</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: color">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: color">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: color">Hello</p></div>
            <p class="a4">color</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: luminosity">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: luminosity">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: luminosity">Hello</p></div>
            <p class="a4">luminosity</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: exclusion">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: exclusion">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: exclusion">Hello</p></div>
            <p class="a4">exclusion</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: color-dodge">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: color-dodge">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: color-dodge">Hello</p></div>
            <p class="a4">color-dodge</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: color-burn">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: color-burn">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: color-burn">Hello</p></div>
            <p class="a4">color-burn</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: hard-light">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: hard-light">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: hard-light">Hello</p></div>
            <p class="a4">hard-light</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: soft-light">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: soft-light">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: soft-light">Hello</p></div>
            <p class="a4">soft-light</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: difference">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: difference">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: difference">Hello</p></div>
            <p class="a4">difference</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: plus-darker">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: plus-darker">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: plus-darker">Hello</p></div>
            <p class="a4">plus-darker</p>
        </div>
        <div class="a">
            <div class="a1"><p style="mix-blend-mode: plus-lighter">Hello</p></div>
            <div class="a2"><p style="mix-blend-mode: plus-lighter">Hello</p></div>
            <div class="a3"><p style="mix-blend-mode: plus-lighter">Hello</p></div>
        <p class="a4">plus-lighter</p>

        <button onclick="changeColor()">Change all p elements color</button>
        <script>
            function changeColor() {
                var input = document.createElement("input");
                input.type = "color";
                input.value = "#000000";
                input.addEventListener("input", function() {
                    var elements = document.getElementsByTagName("p");
                    for (var i = 0; i < elements.length; i++) {
                        elements[i].style.color = input.value;
                    }
                });
                input.click();
            }
        </script>
    </body>
</html>
body {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    width: 100%;
}
.a {
    width: 300px;
    height: 50px;
    display: grid;
    grid-template-columns: 50px 50px 50px 150px;
    grid-template-rows: 50px;
}

.a p {
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    margin: 0;
}

.a1 {
    background-color: white;
    mix-blend-mode: color-dodge;
}

.a2 {
    background-color: #7f7f7f;
}

.a3 {
    background-color: black;
}

.a4 {
    color: black !important;
}

Tried all blend modes

React component using native HTML input of type date: All values get reseted while editing in Firefox

I am working on a date picker component which makes use of the HTML element <input type="date" />. In Firefox 129.0.1, when typing 0 as day or month the two other parts get reset.

I replicated the basic functionality on codesandbox.io to make the issue reproducible:

  1. Enter 12.12.2024
  2. Go back to month part
  3. Enter 0

Result: Day and year get deleted, but I would expect them to be left unchanged.

This behaviour is different in Chrome and when using <input type="date" /> without react. In both cases, the other parts are left unchanged when entering 0.

What causes this strange behaviour in Firefox?
How can it be solved?

passing url parameters from a table

I’m wanting to be able to use a submit button to pass variables via the url to an external page. I only have the first td in each of these set up to do so, but I’m not getting any results. I don’t have the button in here, and I’m looking to just pass the data from a single person. I’d appreciate some suggestions.

<body>
  
    <div class="container">
        <div class="col-md-12">
          
            <div class="panel panel-default">
                <div class="panel-heading">
                    Inmate
                </div>
                <div class="panel-body">
                    <table class="table table-condensed table-striped">
                        <tbody>

                            <tr data-toggle="collapse" data-target="#demo1" class="accordion-toggle">
                                <td name="name" type="hidden" value="names">NAME from sql</td>
                                <td>ID from sql</td>
                            </tr>
                            <tr>
                                <td>Category from sql</td>
                                <td>Amount from sql</td>
                            </tr>

                            <tr>
                                <td colspan="12" class="hiddenRow">
                                    <div class="accordian-body collapse" id="demo1">
                                        <table class="table table-striped">
                                            <thead>
                                                <tr class="info">
                                                    <th>Address:</th>
                                                    <th>DOB:</th>
                                                </tr>
                                            </thead>

                                            <tbody>
                                                <tr data-toggle="collapse" class="accordion-toggle">
                                                    <td>address</td>
                                                    <td>birthday</td>
                                                </tr>

                                                <tr>
                                                    <td>Fees:</td>
                                                    <td></td>
                                                </tr>

                                            </tbody>
                                        </table>
                                    </div>
                                </td>
                            </tr>

                            
                            <tr data-toggle="collapse" data-target="#demo2" class="accordion-toggle">
                                <td name="name" type="hidden" value="names">NAME from sql</td>
                                <td>ID from sql</td>
                            </tr>
                            <tr>
                                <td>Category from sql</td>
                                <td>Amount from sql</td>
                            </tr>

                            <tr>
                                <td colspan="12" class="hiddenRow">
                                    <div class="accordian-body collapse" id="demo2">
                                        <table class="table table-striped">
                                            <thead>
                                                <tr class="info">
                                                    <th>Address:</th>
                                                    <th>DOB:</th>
                                                </tr>
                                            </thead>

                                            <tbody>
                                                <tr data-toggle="collapse" class="accordion-toggle">
                                                    <td>address</td>
                                                    <td>birthday</td>
                                                </tr>

                                                <tr>
                                                    <td>Fees:</td>
                                                    <td></td>
                                                </tr>

                                            </tbody>
                                        </table>
                                    </div>
                                </td>
                            </tr>

                            <tr data-toggle="collapse" data-target="#demo3" class="accordion-toggle">
                                <td name="name" type="hidden" value="names">NAME from sql</td>
                                <td>ID from sql</td>
                            </tr>
                            <tr>
                                <td>Category from sql</td>
                                <td>Amount from sql</td>
                            </tr>

                            <tr>
                                <td colspan="12" class="hiddenRow">
                                    <div class="accordian-body collapse" id="demo3">
                                        <table class="table table-striped">
                                            <thead>
                                                <tr class="info">
                                                    <th>Address:</th>
                                                    <th>DOB:</th>
                                                </tr>
                                            </thead>

                                            <tbody>
                                                <tr data-toggle="collapse" class="accordion-toggle">
                                                    <td>address</td>
                                                    <td>birthday</td>
                                                </tr>

                                                <tr>
                                                    <td>Fees:</td>
                                                    <td></td>
                                                </tr>

                                            </tbody>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                  
                </div>
                    
            </div>
            
        </div>
    </div>
    
</body>

How to use require() in React

I’m new to React.
I was wondering how to read and write to JSON file and most people use require(fs) etc…
I know that require is not standard browser function (or Reacts) but I’m confused how to connect React with it?
I already have node modules in that folder and I thought that require function would be included in that (as when I worked with node.js)?

I thought that require would already be included since I have node_modules that came with react in that folder

Dropdown Menu Gets Hidden Inside Scrollable Navigation Bar with overflow-x: auto

I’m working on a navigation bar with a list of items, some of which have dropdown menus. The list is too long to fit on the screen horizontally, so I used overflow-x: auto to make it scrollable. This part works perfectly fine, and the navigation bar scrolls as expected.

However, I’m encountering an issue where the dropdown menu becomes invisible when hovering over a navigation item. To fix this, I tried setting overflow-y: visible, but it’s still not working. The dropdown remains hidden, clipped by the overflow of the parent container.`

.section-wrapper {
  overflow: visible;
  overflow-x: auto;
  -ms-overflow-style: none;
}


.section-wrapper::-webkit-scrollbar {
  width: 0px;
  background: transparent;
}

.nav-menu .menu {
  width: -moz-max-content;
  width: max-content;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  font-size: 14px;
  text-transform: uppercase;
}
.nav-menu .menu .menu-item {
  position: relative;
}
.nav-menu .menu .menu-item a {
  display: block;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--color-text-2);
  font-weight: 500;
}
.nav-menu .menu .menu-item a:hover {
  background-color: #f0f0f0;
}
.nav-menu .menu .menu-item.menu-item-has-children > a::after {
  content: "▼";
  margin-left: 5px;
  font-size: 0.75em;
}
.nav-menu .menu .menu-item.menu-item-has-children:hover > .sub-menu {
  display: block;
}
.nav-menu .menu .menu-item.menu-item-has-children .sub-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  background-color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  overflow-y: auto;
}
.nav-menu .menu .menu-item.menu-item-has-children .sub-menu .menu-item {
  width: 180px;
  background-color: #fff;
  z-index: 2;
}
.nav-menu .menu .menu-item.menu-item-has-children .sub-menu .menu-item a {
  padding: 10px;
}
.nav-menu .menu .menu-item.menu-item-has-children .sub-menu .menu-item.menu-item-has-children {
  position: relative;
}
.nav-menu .menu .menu-item.menu-item-has-children .sub-menu .menu-item.menu-item-has-children:hover > .sub-menu {
  display: block;
}
.nav-menu .menu .menu-item.menu-item-has-children .sub-menu .menu-item.menu-item-has-children > .sub-menu {
  display: none;
  position: absolute;
  top: 0;
  left: 100%;
  margin-left: 1px; /* Small gap to avoid overlap */
}
<nav class="section-header-sec-nav">
    <div class="nav-menu section-wrapper">
        <div class="menu-header-2-container"><ul id="menu-header-2" class="menu"><li id="menu-item-44" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item menu-item-44"><a href="http://phantom777.local/sample-page/" aria-current="page">ICC Men’s</a></li>
<li id="menu-item-45" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item menu-item-45"><a href="http://phantom777.local/sample-page/" aria-current="page">ICC Women’s</a></li>
<li id="menu-item-46" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item menu-item-46"><a href="http://phantom777.local/sample-page/" aria-current="page">Leagues</a></li>
<li id="menu-item-47" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor menu-item-has-children menu-item-47"><a href="http://phantom777.local/sample-page/" aria-current="page">Prediction</a>
<ul class="sub-menu">
    <li id="menu-item-52" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item menu-item-52"><a href="http://phantom777.local/sample-page/" aria-current="page">Match Prediction</a></li>
</ul>
</li>
<li id="menu-item-48" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item menu-item-48"><a href="http://phantom777.local/sample-page/" aria-current="page">Fantasy Cricket</a></li>
<li id="menu-item-49" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item menu-item-49"><a href="http://phantom777.local/sample-page/" aria-current="page">Match Odds</a></li>
<li id="menu-item-50" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item menu-item-50"><a href="http://phantom777.local/sample-page/" aria-current="page">ICC Ranking</a></li>
<li id="menu-item-51" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item menu-item-51"><a href="http://phantom777.local/sample-page/" aria-current="page">Analysis</a></li>
</ul></div>    </div>
</nav>

` Issue:
When I hover over the nav item with a dropdown, the dropdown menu gets cut off and is not visible due to the overflow-x: auto setting on the parent container. Setting overflow-y: visible doesn’t resolve this issue.

React child component causes grid items to be placed in next row in horizontally-expandable grid before the previous row is filled

Bear with me, as the problem is difficult to describe clearly.

I have an app that lists “items” in a grid. This grid is only large enough to hold a single item at first, but it expands with each new item up to five items, at which point new items are added to the next row. When the second row reaches five items, the next one is placed on row 3.

I originally had a static “add item” button at the top of the page, but I decide it made more sense practically and aesthetically to have the add button be the last “item” in the grid such that when you hit the add button, it is replaced by a new item. This seemed more intuitive as the add button sits where you would be adding another item.

I achieved this using child components. Each grid item component is just a div container set to the proper width and height to fill a single grid component, and it takes in a child component which can be either an item in the grid or the add button.

Everything was working fine before using this child component scheme – and in fact still works fine with “items” as child components of the “item container” components. However, when I add an “item container” with an add button as a child component, that add button gets placed on a new row despite the previous row not being filled with 5 items.

Red arrow shows where the add button should go

What is even stranger is when I put in some temporary code to make the add button a middle item in the list with more regular items coming after, the add button will appear in the proper space in the current row – but all items after will start on the next row!

Item on 2nd row should be at end of first row instead

There’s a lot of code involved, so I’m hoping somebody might have an idea of a general issue in the way somebody might try to implement this that would cause this result. Even so, I’ll do my best to strip it down to the most relevant code so you’ve got some idea of what I’m doing.

App.tsx:

    type AddButtonProps = {
  onAddCoinSlot: () => void;
}

type CoinsListItemProps = {
  children: React.ReactNode,
  bordered?: boolean
}

const AddButton = function (props: AddButtonProps) {
  return(
    <>
      <input type="button" onClick = {props.onAddCoinSlot} value="+" id="add-button"></input>
    </>
  )
}

const CoinsListItem = (props: CoinsListItemProps) => {
  let borderedClassName = props.bordered ? " bordered" : "";
  return(
    <div className={"coin-slot" + borderedClassName}>
      {props.children}
    </div>
  )
}
  let coinList = coinsDataWithAddButton.map((coin, index) => {
    if(coin !== null){
      return(
        <CoinsListItem bordered={true}>
          <CoinSlot 
            id={index}
            coinTicker={coin.ticker}
            addressEntryIsOpen={coin.addressEntryIsOpen}
            availableCoins={availableCoins}
            coinImage={coin.image}
            address={coin.address}
            addressIsValid={coin.addressIsValid}
            isCustom={coin.rank === -1 ? true : false}
            onChangeCoin={onChangeCoin}
            onChangeAddress={onChangeAddress}
            onChangeLogo={onChangeLogo}
            onChangeTicker={onChangeTicker}
            onRemoveCoinSlot={onRemoveCoinSlot}
            toggleAddressEntryArea={onToggleAddressEntry}
            moveCoinSlot={moveCoinSlot}
            lines={coin.lines}
          />
        </CoinsListItem>
      )
    } else {
      return (
        <CoinsListItem>
          <AddButton onAddCoinSlot={onAddCoinSlot}/>
        </CoinsListItem>
      )
    }
  })

 return (

    <div className="App">
      <div className="debug">
      </div>
      <div className="app-box">
        <h1>Cryptowidget Builder</h1>
        <div className="coin-list-container">
          <AddButton onAddCoinSlot={onAddCoinSlot}/>
          <div className="coin-list">
            {coinList}
          </div>
        </div>
        <button onClick={onGenerateQrs} value="Get widget" disabled={generationIsDisabled}>Get widget</button>
        <button onClick={makeAllAddressesValid} value="Make addresses valid (for testing)">Make Addresses Valid</button>
      </div>
    </div>
  );

CoinSlot.tsx:

    return(
    <>
        <input type="button" className="remove-button" onClick = {onRemoveCoinSlot} value="X"></input>
        <img src={props.coinImage} id="background-image" alt="coin"></img>
        <div className="coin-slot-grid">
            <div className="move-button-container">
                <button className="move-button" onClick={moveCoinSlotLeft}>{"<"}</button>
            </div>
            <div className="coin-slot-options">
                <div className="select-area">
                    <select value={props.coinTicker || ""} className = "dropdown-menu" onChange={onChangeCoin}>
                        {coinOptions}
                    </select>
                </div>

                {addressEntryElement}
                <div className={customCoinOptionsClassName}>
                    <input type="text" onChange={onChangeTicker} value={props.customTicker} className="custom-ticker-entry" placeholder="ticker"></input>
                    <input type="file" id={"logo-chooser-" + props.id.toString()} className="logo-chooser" onChange={onChangeLogo} ></input>
                </div>
            </div>
            <div className="move-button-container">
                <button className="move-button" onClick={moveCoinSlotRight}>{">"}</button>
            </div>
        </div>
    </>
)

How to create water disperse and assemble back effect using html css and js

I want to create an interesting effect where a ring or circle, when hovered over, breaks into smaller particles or elements that disperse or flow outwards, similar to water spreading out and assemble back in the original position. How can we achieve this kind of effect using CSS animations and JavaScript event handling.

Here’s an example (pls open the desktop version because it might not work in mobile version.)

https://www.codeglo.com/

How can I have this similar effect that this green circle has for a logo/image of a bird?

What would your approach be? Pls explain it in small steps because I am new to html, css and js.

What existing combination of frontend and backend (if its needed) technologies has been used by codeglo to achieve this effect? How might one guess that accurately?

Diameter of a binary tree – failing case when the longest path doesn’t pass through the root

So I’m working on this problem:

Given the root of a binary tree, return the length of the diameter of the tree.

The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.

The length of a path between two nodes is represented by the number of edges between them.

Here’s how I tried to solve:

var diameterOfBinaryTree = function(root) {

if(root === null) return 0;
let max_height = 0;

function maxDepth(node){
    if (node === null) return 0;
    var lh = maxDepth(node.left);
    var rh = maxDepth(node.right);

    return 1+ Math.max(lh, rh);
}


max_height = Math.max(max_height, maxDepth(root.left) + maxDepth(root.right));

diameterOfBinaryTree(root.left);
diameterOfBinaryTree(root.right);

return max_height 
}

Now, this does work except apparently for the case when the longest path doesn’t pass through the root node. But I did try to incorporate those case through, i.e I do iterate on every node of the tree:

diameterOfBinaryTree(root.left);
diameterOfBinaryTree(root.right);

Where am I going wrong? Appreciate any help.
Note that I do have to optimize this from O(N2) to O(N) but for now I’m just trying the brute force.

How can I check the Checkbox components passed to a Mantine CheckBox.Group component?

I am trying to build a group of checkboxes using Mantine component Checkbox.Group. I added my own styles and props. I also created a personalized Checkbox component from the Mantine Checkbox component to the previous thing. Here it is the code of my own Checkbox component:

export function Checkbox({
  size,
  indeterminated = false,
  disabled = false,
  checked = false,
  onChange,
  ...rest
}) {
  const [isChecked, setChecked] = useState(checked);

  const adjustedSize = size === "md" ? "sm" : "xs";
  const checkboxStyles = {
    backgroundColor: disabled && !isChecked ? "var(--mantine-color-gray-2)" : undefined,
    cursor: disabled ? "not-allowed" : "pointer",
  };

  const handleChange = (event) => {
    const newChecked = event.currentTarget.checked;
    setChecked(newChecked);
    if (onChange) {
      onChange(event);
    }
  };

  return (
    <MantineCheckbox
      className={classes.component}
      color={disabled ? "var(--mantine-color-green-2)" : "var(--mantine-color-green-8)"}
      label={<span className={disabled ? classes.labelDisabled : ""}>{rest.label}</span>}
      checked={isChecked}
      data-disabled={disabled}
      description={
        <span className={disabled ? classes.descriptionDisabled : classes.description}>
          {rest.description}
        </span>
      }
      size={adjustedSize}
      radius={adjustedSize === "sm" ? "4px" : "2px"}
      onChange={handleChange}
      styles={{
        input: checkboxStyles,
      }}
    />
  );
}

When I try to wrap this checkboxes in a group I cannot check the checkboxes clicking on them. Here the code of the Checkbox.Group:

Checkbox.Group = function CkeckboxGroup({
  required = false,
  direction = "horizontal",
  title,
  subtitle,
  error,
  label1,
  label2,
  label3,
  label4,
  ...props
}) {
  const [value, setValue] = useState([]);

  const Wrapper = direction === "vertical" ? Stack : Group;
  const adjustedSize = props.size === "md" ? "sm" : "xs";

  const marginTop =
    adjustedSize === "sm" ? "var(--mantine-spacing-md)" : "var(--mantine-spacing-sm)";
  const marginBottom =
    adjustedSize === "sm" ? "var(--mantine-spacing-md)" : "var(--mantine-spacing-sm)";

  return (
    <MantineCheckbox.Group
      value={value}
      onChange={setValue}
      label={
        <span
          style={
            adjustedSize === "sm"
              ? { fontSize: "var(--mantine-font-size-md)" }
              : { fontSize: "var(--mantine-font-size-sm)" }
          }
          className={classes.groupLabel}
        >
          {title}
        </span>
      }
      description={
        <span
          style={
            adjustedSize === "sm"
              ? { fontSize: "var(--mantine-font-size-md)" }
              : { fontSize: "var(--mantine-font-size-sm)" }
          }
          className={classes.groupDescription}
        >
          {subtitle}
        </span>
      }
      error={
        <span
          style={
            adjustedSize === "sm"
              ? { fontSize: "var(--mantine-font-size-xs)" }
              : { fontSize: "var(--mantine-font-size-xxs)" }
          }
          className={classes.groupError}
        >
          {error}
        </span>
      }
      size={props.size}
      withAsterisk={required}
    >
      <Wrapper
        gap={
          direction === "vertical"
            ? adjustedSize === "sm"
              ? "var(--mantine-spacing-xs)"
              : "var(--mantine-spacing-xxs)"
            : adjustedSize === "sm"
              ? "var(--mantine-spacing-md)"
              : "var(--mantine-spacing-sm)"
        }
        style={{
          marginTop: marginTop,
          marginBottom: marginBottom,
        }}
      >
        <Checkbox label={label1} size={props.size} />
        <Checkbox label={label2} size={props.size} />
        <Checkbox label={label3} size={props.size} />
        <Checkbox label={label4} size={props.size} />
      </Wrapper>
    </MantineCheckbox.Group>
  );
};

I tried to use the code refered in the Mantine documentation, in which they use an array to handle the state of the value of each Checkbox, but nothing happened.
I also tried to get the onChange prop from the Checkbox already created and use an array of checked properties (one for each Checkbox child component) in the group.

Thanks in advance!

Creating a svg path with javascript is not working [duplicate]

I have some buttons that are generating dynamically and those buttons have an svg inside to render an icon.

I have created a function to ease the process

function CreateSvg(className, d) {
    const svg = document.createElement('svg');
    svg.classList.add(className);
    svg.setAttribute('viewBox', '0 0 24 24');
    
    const path = document.createElement('path');
    path.setAttribute('fill', 'currentColor');
    path.setAttribute('d', d);
    path.setAttribute('stroke', '#fff');
    path.setAttribute('stroke-width', '3');

    svg.append(path);
    return svg;
}

And then call it

const play_button = document.createElement('button')
play_button.classList.add('play-pause-btn');

const play_icon = CreateSvg('play-icon', 'M14,19H18V5H14M6,19H10V5H6V19Z');
play_button.append(play_icon);

The element generates correctly and it appends it where it should.

    <button class="play-pause-btn">
      <svg class="play-icon" viewbox="0 0 24 24">
        <path fill="currentColor" d="M14,19H18V5H14M6,19H10V5H6V19Z" stroke="#fff" stroke-width="3">
        </path>
     </svg>
   </button>

However when looking at the browser, the svg are not being drawn.

The svgs should be visible in the red squares
Example of svgs not rendering properly

Awaiting API Response within Outlook Add In getAttachmentContentAsync Function

I am trying to upload attachments from a ReactJS Outlook Add In but I can not make the code wait on the API response from the server, rather it executes JS code after immediately which is problematic if upload fails.

Here is my JS code:

const uploadOutlookFile = async (files) => {
    const options = { asyncContext: { currentItem: item } };
    const item = Office.context.mailbox.item;
    files.map((id) => { // files have attachment id
        item.getAttachmentContentAsync(id, options, (result) => {
            const success = handleAttachmentsCallback(result);
        });
    });
    
    if(success) {
       navigate("/uploadSuccess");
    } else {
       navigate("/uploadFailure");          
   }
};

Which calls:

const handleAttachmentsCallback = async (result) => {
    return await uploadFile(result.value.content);
};

Which then calls the API:

const uploadFile = async (file) => {
    let url = `/my/rest/url`;
    return fetch(url, {
        method: "POST",
        body: file.toString(),
    });
};

I can’t add an await within the getAttachmentContentAsync() function without receiving this parse error:

Parsing error: ‘await’ is only allowed within async functions and at
the top levels of modules.

What do I need to change to make this work if at all possible?

Importing images to use as icons within a react.js project

I have an index.js that imports images to use as icons in a verticaltimeline component (from react.js) that showcases my work experience. This project is followed by a tutorial (https://www.youtube.com/watch?v=0fYi8SGA20k) where in the file they provided all the images are imported fine. However, when I try and add my own image into the same asset file and call it I get this error:

SyntaxError: The requested module ‘/src/assets/index.js’ does not provide an export named ‘whittleburypark’ (at index.js:26:5)

Here is the import code:

import {
    mobile,
    backend,
    creator,
    web,
    javascript,
    typescript,
    html,
    css,
    reactjs,
    redux,
    tailwind,
    nodejs,
    mongodb,
    git,
    figma,
    docker,
    meta,
    starbucks,
    tesla,
    shopify,
    carrent,
    jobit,
    tripguide,
    threejs, 
    whittleburypark, // this is my image i have added
  } from "../assets";

Here is the code where it is being used

const experiences = [
    {
      title: "Digital Marketing Assistant",
      company_name: "Whittlebury Park",
      icon: whittleburypark, //if i use for example 'starbucks' it works fine
      iconBg: "#383E56",
      date: "June 2019 - July 2019",
      points: [
        "I spent the summer of 2019 working as a Digital Marketing Assistant. It was an exciting and insightful experience as during this time I was heavily involved in the preparation for the Silverstone F1 Grand Prix. ",
        "Working within a small team, I developed branding material for the event and led on providing social media content.",
        " Throughout this busy and challenging period, I learnt plenty of skills that gave me great insight into digital marketing world.",
      ],
    },

The file ‘whittleburypark.png’ is in the same directory as ‘starbucks.png’ and the rest of the images, where it is being fetched from ../assets.

I can’t seem to figure out what I am doing wrong here. I understand this is within a larger project so if you need anymore information please let me know.