Why does the animate.css animation flicker after fade in

If an animation is triggered while the element’s opacity is set to 0, it fades in, but briefly flickers after completion. This occurs even when the opacity is set to 1 directly afterwards.

Here is a jsfiddle that illustrates the problem.


Just for context: I use this function to add animations classes (found on the animate.css website):

const animateCSS = (element, animation, prefix = 'animate__') =>
  // We create a Promise and return it
  new Promise((resolve, reject) => {
    const animationName = `${prefix}${animation}`;
    const node = document.querySelector(element);

    node.classList.add(`${prefix}animated`, animationName);

    // When the animation ends, we clean the classes and resolve the Promise
    function handleAnimationEnd(event) {
      event.stopPropagation();
      node.classList.remove(`${prefix}animated`, animationName);
      resolve('Animation ended');
    }

    node.addEventListener('animationend', handleAnimationEnd, {once: true});
  });


  • First I thought the flickering is caused by any animation delay.
    test1.style.setProperty('--animate-delay', '0s');

  • Since it returns a promise, I thought it should be enough to set the opacity in a .then() statement.
let test1 = document.getElementById("test1");

animateCSS("#test1", "flipInX")        // flickers
    .then(()=>{
      test1.style.opacity = 1;
    });

...

animateCSS("#test1", "flipOutX")
    .then(()=>{
      test1.style.opacity = 0;
    });

  • Setting the value immediately doesn’t work either.
let test1 = document.getElementById("test1");


animateCSS("#test1", "flipInX")
test1.style.opacity = 1;

...

animateCSS("#test1", "flipOutX")       // flickers
test1.style.opacity = 0;

What is the correct way to achieve this effect?


I use animate.css 4.1.1.

Javascript – Loop through API 10 times, although, using the ID of each returned API call as a parameter for the NEXT api call

I am trying to make 10 API calls to the reddit API to get a users most recent comments.

Basically, Reddit uses a parameter ‘after’ in the URI to get the next page. So basically, if there is some dummy example comment data below, I need the LAST ID.

Example.

API Call: https://www.reddit.com/user/USERNAME/comments.json?limit=3

returns:

{
   id: 'd4gf125',
   comment: 'blah blah blah'
},
{
   id: 'dag42ra',
   comment: 'blah blah blah'
},
{
   id: '**hq6ir3j**', // I need this ID right here, the LAST in the list for the next API call
   comment: 'blah blah blah'
},

Then, another API call needs to be made directly AFTER the previous, using the ID as a parameter.

API Call:

`https://www.reddit.com/user/USERNAME/comments.json?limit=3&after=tl_hq6ir3j`

This will run 10 times, which will get 10 pages, so in total, 30 results.

I have tried using this for loop but as for loops are not asynchronous, I cannot change the variable ‘lastID’ in time.

First attempt:

const handleSubmit = async () => {
    setLoading(true);
    axios.get(`${apiUrl}user/${username}/about.json`).then((res) => {
      setUserData({
        about: res.data.data,
      });
      axios
        .get(`${apiUrl}user/${username}/comments.json?limit=100`)
        .then((res) => {
          let data = res.data.data.children;
          let lastItem = data[data.length - 1];
          for (i = 0; i < 10; i++) {
            axios
              .get(
                `${apiUrl}comments/${lastItem.data.id}/comments.json?limit=100&after=tl_${lastItem}`
              )
              .then((res) => {
                lastItem =
                  res.data.data.children[res.data.data.children.length - 1];
              });
          }
        });
    });
  };

If you need some example REAL data, see the link below:

https://www.reddit.com/user/bulkorcut99/comments.json?limit=1000&after=t1_hq6ir3j

Is there an free way to test Avalara and CertCapture APIs?

Anyone has experience with testing Avalara and CertCapture APIs? I noticed the production integration broke might be caused by some recently Avalara API update but when I try to test with sandbox. I was billed $140 for the sandbox account. Is there an easy way to test or I will have to look for a substitute solution? Charging for a sandbox account is definitely not startup and developer-friendly!!!

Alert inside a For Loop

I have 4 types of document status: In Preparation, For Approval, Approved, Rejected.
Also, this code has a checkbox that’s why the array is called ‘selectedPurhcaseRequests’. So the code is every time that I check a checkbox, it get its data and pushes it to the ‘selectedPurchaseRequests’ array. And inside of that data, it has a document status. So I want to have a for loop to check all the purchase request’s document status.

for(let i = 0; i < this.selectedPurchaseRequests.length; i++) {
    if(this.selectedPurchaseRequests[i].docStatus !== 'In Preparation') {
        continue;
    } else {
        fetch(`url`, {
            method: 'PUT',
            headers: {
                'Content-Type': 'application/json'
            }
        })
    }
}

Now, I want to alert a message with a summary of those purchase request number with a status of not equal to ‘In Preparation’. But I want it to alert one time when ‘selectedPurchaseRequests’ array is done looping. Because if it alerts multiple time, it will take a lot time and effort for the user to press ok.

Can someone help me?

Can you please help me run this code with way ı want [duplicate]

hi everyone ı am trying to do something like that you see down. What ı want is if next sibling of H1 is H4 element then log to console “right” but without defining H4 element javascript dont understand.Also when ı tried ı get this error –>Cannot set property nextSibling of # which has only a getter at script.js:219:18

if(h1.nextSibling=h4){
  console.log('right');
}

and ı also tried this

if(h1.closest=h4){
  console.log('right');
}

this last code worked but ı had to define h4 which is what ı dont want to
but when ı deleted already selected variable (const h4=document.querySelector(‘h4’)) it’s again started say h4 undefined. right now what ı want is find a way to run this code without speacially define h4
please help me

change icon for resizing in react-modal-resizable-draggable

i am using the react-modal-resizable-draggable modal from:
https://www.npmjs.com/package/react-modal-resizable-draggable
and i am facing a problem while trying to change the little tiny icon that is in the bottom right to a different icon from “kendo”.
the icon o want to change

I would like to know what is the right way to do so.

Is there any way to add a class only to the icon without doing dumb manipulations on the dom like: Document.querySelector() etc.

Thanks for your help!!!

The state variable declared in context is not persisting its value

I am using a context state variable to store my token value when user signs in. And using that token through out my application.
When I log in, the token is console logged on the login page. But it gives empty value on other pages even though I am using the context in all the files.

AuthContext.js

export const AuthContext = createContext();

export const AuthProvider = (props) => {
  const [authToken, setAuthToken] = useState("");
  const [authProtected, setAuthprotected] = useState(true);

  return (
    <AuthContext.Provider
      value={{
        token: [authToken, setAuthToken],
        authProtect: [authProtected, setAuthprotected],
      }}
    >
      {props.children}
    </AuthContext.Provider>
  );
};

Login.js

const userAuth = (e) => {
    e.preventDefault();
    Axios.post(authApi, loginInfo).then((res) => {
      setJwtToken(res.data.idToken.jwtToken);
    });
  };
  console.log(jwtToken);

After log in, I use this in one of my pages and it logs an empty value

const { token } = useContext(AuthContext);
const [jwtToken, setJwtToken] = token;

console.log(jwtToken);

Error: Returned error: VM Exception while processing transaction: revert. Uniswap Error

I have implemented the Uniswap v2 router function called

function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);

I implemented it like this…

function swapTokensForExactEthTest(
        uint256 _amountOut,
        address _tokenIn,
        uint256 _amountInMax,
        address _to
    ) external {
        IERC20(_tokenIn).transferFrom(msg.sender, address(this), _amountInMax);
        IERC20(_tokenIn).approve(UNISWAP_ROUTER_ADDRESS, _amountInMax);

        address[] memory path;
        path = new address[](2);
        path[0] = _tokenIn;
        path[1] = WETH;

        IUniswapV2Router01(UNISWAP_ROUTER_ADDRESS).swapTokensForExactETH(
            _amountOut,
            _amountInMax,
            path,
            _to,
            block.timestamp
        );
    }

and testing it like this…

//WBTC_WHALE=0xF977814e90dA44bFA03b6295A0616a897441aceC
const WHALE = process.env.WBTC_WHALE;
const AMOUNT_OUT_MIN = 1;
const TOKEN_IN = WBTC; //0x2260fac5e5542a773aa44fbcfedf7c193bc2c599
const AMOUNT_IN = 100000000;


it('should swap tokens for exact eth', async()=>{

        tokenIn = await IERC20.at(TOKEN_IN);
        testUniswap = await TestUniswap.new();

        await testUniswap.swapTokensForExactEthTest(

            AMOUNT_OUT_MIN,
            tokenIn.address,
            AMOUNT_IN,
            accounts[0],

            {
                from: WHALE
            }

        );

        console.log(`sent ${balanceOf(accounts[0])}`);

    });

My problem is when I’m testing it like the testing code above, I’m getting…

Error: Returned error: VM Exception while processing transaction: revert

I caught the error using remix. The error is due to gas limit and says…

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Gas estimation: 0x2dc6c0 Gas limit: 0x2dc6c0

more specifically…

code -3200 "message": "VM Exception while processing transaction: revert"

I can’t understand how to solve it. Anyone please help.

Anyone please help.

how can I embed text in svg server side

How can I embed a text into SVG in NodeJS? The context is that I have a ticket in SVG and in response to a webhook the Netlify function is called, and I need to embed the name in the ticket, convert it to PDF and send it. With conversion to PDF I know I need to use PDFmake, however I don’t know how to embed the name in the correct place in the ticket (which has ID). The only idea that comes to my mind is to paste the SVG code directly in the file as a string literal and embed the name in there. The code of a ticket is huge, tho, and it’s going to be a mess. Any ideas please?
Thanks

How to Upload File without submit button

I am new to React and I want to upload an image directly when the user selects an image using axios.

But when I select an Image I only get the id but not the image in server side.

<input type='file' name='file' className="form-control" onChange={
  (e) => {
    const file = e.target.files[0];
    const data = new FormData();
    data.append('file', file, file.name);
    data.append('id', link.id);
    axios.get('../sanctum/csrf-cookie').then(response => {
      axios.post("/userlinks/update-image", data, {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }).then((res) => {
        getLinks();
      }).catch((err) => {
        console.log(err);
        getLinks();
      });
    });
    console.log(file.name);
  }
} />

This what I get:

{"id":"14","file":{}}

xmlhttprequest only gets the domain instead of the full url. what should I do

I have open source software. I want to see who is using this. So with xmlhttprequest I POST the url of where my open source software is installed to my own website. On my own website the write.php file captures and saves them.

But on some servers this URL doesn’t work properly. For example, if the software is on example.com/file/123/1.html, the POST value I receive is only example.com.

What I want is to POST example.com/file/123/1.html but on some servers it only POSTs to example.com.

Can you help me please.

var url = "example.com/write.php";

var xhr = new XMLHttpRequest();
xhr.open("POST", url);

xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      
   }};

var data = "url="+(location.href);

xhr.send(data);

I Can Understand This Error Someone Help Please [duplicate]

  if(target.roles.cache.has('937250064894664734')){
                   ^

TypeError: Cannot read properties of undefined (reading ‘cache’)
at Object.execute (C:UsersmihriOneDriveDesktopAdomisBotAdomis-Botcommandsmute.js:6:24)
at Client. (C:UsersmihriOneDriveDesktopAdomisBotAdomis-Botmain.js:57:37)
at Client.emit (node:events:390:28)
at MessageCreateAction.handle (C:UsersmihriOneDriveDesktopAdomisBotAdomis-Botnode_modulesdiscord.jssrcclientactionsMessageCreate.js:34:18)
at Object.module.exports [as MESSAGE_CREATE] (C:UsersmihriOneDriveDesktopAdomisBotAdomis-Botnode_modulesdiscord.jssrcclientwebsockethandlersMESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:UsersmihriOneDriveDesktopAdomisBotAdomis-Botnode_modulesdiscord.jssrcclientwebsocketWebSocketManager.js:351:31)
at WebSocketShard.onPacket (C:UsersmihriOneDriveDesktopAdomisBotAdomis-Botnode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:UsersmihriOneDriveDesktopAdomisBotAdomis-Botnode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:301:10)
at WebSocket.onMessage (C:UsersmihriOneDriveDesktopAdomisBotAdomis-Botnode_moduleswslibevent-target.js:199:18)
at WebSocket.emit (node:events:390:28)

The Error

module.exports ={
name: ‘mute’,
description: ‘Mute Command’,
execute(message, args){
const target = message.mentions.users.first();
if(target.roles.cache.has(‘937250064894664734’)){
if(target){
let mainRole = message.guild.cache.find(role => role.name === ‘member’)
let mutedRole = message.guild.cache.find(role => role.name === ‘muted’)

        let memberTarget = message.guild.members.cache.get(target.id);
        memberTarget.roles.remove(mainRole.id)
        memberTarget.roles.add(mutedRole)

        message.channel.send("Kullanici Susturulmustur!")
    }

    else{
        message.channel.send("Kullanici Bulunamamistir!")
    }
   }

   else{
       message.channel.send("Bu Komutu Kullanmak Icin Yetkin Yoktur!")
   }
}

}

The Code

How to align the header and its components evenly in node js

enter image description here`.header { padding: 15px 20px; display: flex; position: sticky; background-color: white; justify-content: space-between; z-index: 100; top: 0; box-shadow: 0px 5px 8px -9px rgba(0, 0, 0, 0.75); }

.header_left { display: flex; justify-content: space-evenly; }

.header_input { display: flex; align-items: center; background-color: #eff2f5; padding: 10px; margin-left: 10px; border-radius: 999px;

}

.header_left > img { height: 40px; }

.header_input { border: none; background-color: transparent; outline-width: 0; }

.header_center { display: flex; flex: 1; justify-content: center; }

.header_option > .MuiSvgIcon-root { color: gray; }

.header_option:hover > .MuiSvgIcon-root { color: #2e81f4; }

.header_option { display: flex; align-items: center; padding: 0 30px; cursor: pointer; }

.header_option:hover { background-color: #eff2f5; border-radius: 10px; align-items: center; padding: 0 30px; border-bottom: none; }

.header_info { display: flex; align-items: center; }

enter code here
.header_info > h4 { margin-left: 10px; }’

Changing status of parent/children on the basis of boolean value

I have a array as follows:

[
  {
    data: {
      name: "Cloud",
      size: "20mb",
      type: "Folder",
      DisplayStatus: 1,
    },
    children: [
      {
        data: {
          id: 1,
          name: "backup-1.zip",
          size: "10mb",
          type: "Zip",
          isDisplayStatus: 1,
        },
      },
      {
        data: {
          id: 2,
          name: "backup-2.zip",
          size: "10mb",
          type: "Zip",
          isDisplayStatus: 1,
        },
      },
    ],
  },
  {
    data: {
      name: "Desktop",
      size: "150kb",
      type: "Folder",
      DisplayStatus: 0,
    },
    children: [
      {
        data: {
          id: 3,
          name: "note-meeting.txt",
          size: "50kb",
          type: "Text",
          isDisplayStatus: 0,
        },
      },
      {
        data: {
          id: 4,
          name: "note-todo.txt",
          size: "100kb",
          type: "Text",
          isDisplayStatus: 1,
        },
      },
    ],
  },
];

I have a method in which I will receive two arguments. One is boolean value and one is id.

  1. If boolean value is false, then I need to find the element in the array for the id which is coming as argument of method and set “isDisplayStatus” field to 0.

  2. If boolean value is true, then I need to find the element in the array for the id which is coming as argument of method and set “isDisplayStatus” field to 1.

  3. If for any children “isDisplayStatus” is 0, then “DisplayStatus” in parent should be set as 0. If all chilren “isDisplayStatus” is 0, then for parent “DisplayStatus” should be 0. If all children “isDisplayStatus” is 1, then for parent “DisplayStatus” should be 1.

My Try:

myMethod(flag, data) {
  if (flag == true) {
    this.isDisplayStatus = 1;
  } else if (flag == false) {
    this.isDisplayStatus = 0;
  }
  this.myArray = this.myArray.reduce(
    (f, i) => [
      ...f,
      {
        ...i,
        children: i.children.map((child) => ({
          ...child,
          data: {
            ...child.data,
            ...(child.data.id === data.id
              ? {
                  isDisplayStatus: this.isDisplayStatus,
                }
              : {}),
          },
        })),
      },
    ],
    []
  );
}

I am able to achieve 1 & 2 point but I am not able to achieve point 3. Please help

How can I do this?