How to use animate.css animations with Vue’s Transition and TransitionGroup components

Vue has the v-if and v-for directives which create/remove the element in the DOM depending on the condition. To animate v-if and v-for, you have to use the Transition and TransitionGroup built-in components respectively. How can I use animate.css’s built-in animations with these Vue built-in components?

Example;

<script setup lang="ts">
import { ref } from "vue";

const isModalVisible = ref<boolean>(false);
</script>
<button @click="() => (isModalVisible = true)">Click Me<button>

<Transition name="I want an animate.css animation here">
    <Modal v-if="isModalVisible" />
</Transition>

Typescript not enforcing that non-optional parameters / identifiers are provided to callback function argument [duplicate]

I’m making a function in TS which provides the equivalent functionality of Array.prototype.map() for dictionaries (objects within which all of the values share the same type). The function itself works just fine:

// Array.prototype.map, but for Dict
function mapDict<T, M>(dict: Dict<T>, callback: (dictValue: T, dictKey: string, dict: Dict<T>) => M): Dict<M> {
  const mappedDict: Dict<M> = {}
  for (let keyValPair of Object.entries(dict)) {
    const mappedVal: M = callback(keyValPair[1], keyValPair[0], dict);
    mappedDict[keyValPair[0]] = mappedVal;
  }
  return mappedDict;
};

However, what I’m struggling to understand is the following. In the typed function declaration above, we explicitly say that the second argument mapDict should take is a callback function which takes three arguments (none of which are optional) and returns a type which is cast onto our second generic type M. Bearing that in mind, why does TS not complain when I do this:

const fruits = {
  apple: { color: "red", mass: 100 },
  grape: { color: "red", mass: 5 },
  banana: { color: "yellow", mass: 183 },
  lemon: { color: "yellow", mass: 80 },
  pear: { color: "green", mass: 178 },
  orange: { color: "orange", mass: 262 },
  raspberry: { color: "red", mass: 4 },
  cherry: { color: "red", mass: 5 },
}
 
interface Dict<T> {
  [k: string]: T
}


const mappedDict = mapDict(fruits, (fruit) => {
  // return {
  //   ...fruit,
  //   kg: 0.001 * fruit.mass
  // }
});

As you can see, in the above invocation of mapDict, the callback I’ve passed in as an argument only has one argument / identifier, whereas I’ve explicitly stated it must receive three, and yet TS is totally fine with it. If I had to make a guess as to what’s going on here, I would say that TS what is actually enforcing is how many arguments are passed into the callback when the callback is invoked, and in the code above, the callback is always invoked with three arguments which adheres to the way we typed it. While that does somewhat make sense, it still confuses me that we explicitly tell TS “this argument must be a function that takes receives three arguments / identifiers”, and yet there are no complaints if we provide a function that only takes one.

Could somebody explain more clearly the behaviour that’s occurring here?

AmCharts 5 – Hide the scrollbar and change the colors

I bought a license from amcharts5 for my bachelor thesis and would now like to hide the logo, hide the scrollbars and change the color from blue to green in the “radar-line” example.

To hide the logo (watermark), I received the following instruction:

Add the following code before chart code to remove amCharts branding:
am5.addLicense(“AM5CXXXXXXXX”);

The site is currently running here: https://fabianschmidt.digital/amcharts5/amcharts5/examples/radar-line/

I have the following HTML code for this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>amCharts 5 Example - radar-line</title>
    <link rel="stylesheet" href="index.css" />
  </head>
  <body>
    <div id="chartdiv"></div>
    <script src="../../index.js"></script>
    <script src="../../xy.js"></script>
    <script src="../../radar.js"></script>
    <script src="../../themes/Animated.js"></script>
    <script src="index.js"></script>
  </body>
</html>

The following CSS code:

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  padding: 0;
  margin: 0;
  background-color: #ffffff;
}

#chartdiv {
  width: 100%;
  height: 80vh;
}

**And the following JS code:
**

Can somebody help me with it?

I look forward to your answers!
Kind regards, Fabian

Nodejs Socket.io xhr poll error, curl error, file_get_content error

i need help. I create a nodejs server when i am on cloudflare. I quit cloudflare and now. I cannot send request socket.io xhr (return poll error in cache), curl call (return null) or file_get_content (return false) etc to the node server. I run the server on port 8443. I already unlock the port in the firewall. When i open in my browser, it’s work! but…

SSL certificates is on and opérationnal. I want to send/get data to socket server from mon PHP file.

app.get("/receiveMDNDWEYS", function(request, response) {
 console.log("receive");
      console.log(request.query); //This prints the JSON document received (if it is a JSON document)
if(request.query.password && request.query.password == '****'){

request.query.mp = encode(request.query.mp, {
            'useNamedReferences': true
});



response.status(200).send('ok IS SEND');
} else {
    response.status(400).send('error');
}
});

My server Almalinux 8 with directadmin.

  • disable firewall and still not working
  • add port at the same power of 80,443 still not working
  • android app, delete cache work one time xhr poll error next app open

i don`t really understand why now that’s not working and before yes! Before i have cloudflare activate and now i use my own DNS system. I miss something ?

Using a single layout template for React pages?

I am just beginner in Reactjs and trying to use single layout components e.g. NavBar, MainContent and Footer. However, I am not sure how should I define properly. There are several options:

index.html
index.js
App.js

On the other hand, for Login page I want to use another template which has neither NavBar nor Footer. So, How should I define such a layout pages properly? Could you just give a basic and proper example? I implemented all layout seperately, just need the proper places implementations.

Having a playlist of songs that shuffle automatically on a website with Javascript

Is there a way to have a playlist of songs (Around 6 songs) that are shuffled and played on a website through javascript, html, or css? I’ve been able to get some songs to play over each other and to play automatically upon visiting the website, but there’s no way to make any songs play in a row, much less have a randomized/shuffled order for them to play in. The music automatically plays through a .mouseenter (hovering) function where it’s able to play one song, but that’s it. I can’t find nor figure out any way to make it play one after the other, or for them to be shuffled.
I’m somewhat new to coding so any and all help/advice is greatly appreciated. Thanks.

HTML code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<ul class="hidden">
    <a href="#">.</a>
    <audio id="flame" preload="auto">
        <source src="flame.mp3">
    </audio>
</ul>
<script>
        var flameOne = $("#flame")[0];
        $(".firesong")
        .mouseenter(function() {
  flameOne.play();
});
</script>

Change className when state value changes – other solutions not working

Problem Explanation

I’m trying to implement a tabs feature with two span elements in a div. One is called Active Programs, the other is called Inactive Programs.

Basically, when the Active Programs is clicked, it should show use the styles.sub__heading_active class, and set the class for Inactive Programs to styles.sub__heading_inactive; and vice versa.

I have used this exact method for similar use cases before, and never faced any issues until now. I have used different methods of storing values in the state (mentioned at the end of the question) as well. Any help is highly appreciated!


Relevant Code

I have declared the state like so:

const [activeTab, setActiveTab] = useState({
   "active": false,
   "inactive": true
});

This is the div with the two span elements inside the return of the functional component:

<div className='flex flex-row gap-12 justify-start'>
    <span 
      className={ (activeTab.active === true && activeTab.inactive === false) ? styles.sub__heading_active : styles.sub__heading_inactive }
      onclick={ () => setActiveTab( {active: true, inactive: false} ) }
    >
       Active Programs
    </span>
    <span 
      className={ (activeTab.active === false && activeTab.inactive === true) ? styles.sub__heading_active : styles.sub__heading_inactive }
      onclick={ () => setActiveTab( { active: false, inactive: true } ) }
    >
       Inactive Programs
    </span>
</div>

Fixes I have tried

  • Instead of storing an object with two key-value pairs in the state, I have tried storing a string and referencing the string in the className condition:
const [activeTab, setActiveTab] = useState('active');   // or 'inactive'

<span 
  className={ activeTab === 'active' ? styles.sub__heading_active : styles.sub__heading_inactive }
  onClick={ () => setActiveTab('active') }
> 
  Active Programs
</span>
<span 
  className={ activeTab === 'inactive' ? styles.sub__heading_active : styles.sub__heading_inactive }
  onClick={ () => setActiveTab('inactive') }
> 
  Inactive Programs
</span>
  • The other method was to just store a single boolean value in the state.

how do i dynamically import modules that use a module inside the module itself?

yes that probably sounds confusing, right?

i have the following module called app.js:

import express from 'express'

const app = express()

export default app

as you can see, all it does is create an express instance and export it.

now, i have a folder called routes, and inside of this folder, i want to be able to add as many route modules as i’d like.

oh, and i’d really love to use them like so (e.g. routes/index.js):

import { app } from '../app.js'

app.get('/', (req, res) => {
    res.send('Hello World!')
})

here is where it gets interesting. i want to change my my app.js code so that it will automatically import all of the route modules from inside the routes folder:

new app.js code:

import express from 'express'
import {globby} from 'globby'
import path from 'path'

const app = express()

const routePaths = await globby([
    './routes/**/*.js',
])

for (const routePath of routePaths) {
    await import(path.resolve(routePath))
}

export default app

of course, since the route module is referencing the app module, it suffers from a never ending loop which will continue until long after AI has taken over our planet, humans go extinct, and unconscious cyborgs rule the world.

is it possible to have a module which imports other modules that references itself?

i’ve tried exporting a function for my route modules which use app as a parameter, and while that works, i think its a much nicer DX with the way i am asking about.

Google Appscript

I created a custom Google Apps script that uses data from a different sheet in the same spreadsheet file, which works as intended. However, after a period of time, the function gets called again and returns all ‘0’s in every cell, including closing and reopening the file after a while.

I’m retrieving the other sheet via

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Calculations");

if that’s a potential culprit.

The function works again if I delete and replace the function in the cell.

How to re-render a state by calling a prop from a child component?

I think there’s something about states I’m not understanding when it comes to causing a re-render. When passing a state as a prop and its setState I was expecting that I would be able to cause a re-render when calling the setState however this does not seem to be the case.

I have created a piece of code that should show what I mean. The code below holds a simple task list. You can see I have split the list into 4 parts, (header, add task, update all task, update task within a day). When you enter a task name, task time and a task day the task will be added to the task state after you press create new task. This will then be passed down to the second layer where the task will be sorted by day then that will passed to the final child that will list this task in a drop down which can be expanded by clicking on the small carrot on the side of the day.

My goal is try and create a system where I can update a individual task, all task associated within a certain day or all task in the list. Currently I have it where I can update all task within a day by using the prop.setTask. If I do something that causes a re-render like adding a new task then the child component will re-render and go where it is supposed to go but if I only change all task within a day no re-render happens despite calling my props.setTask and I’m not sure why since I am updating a state. My goal was to manage my state only from the top level to avoid unnecessary re-renders and maintain robustness . Can someone explain why this is?

Please note that I have only created it to update all task within a day which you can do by selecting a day in the dropdown next to the name of the day. Each level is color coded for easier identification.

  • light blue = title
  • red – add task
  • coral – update all task
  • light grey – task within a day

Steps to reproduce issue

  • CreateTask
  • Open dropdown on day assigned to task
  • Change task day with dropdown next to name of day
  • Issue no re-render is invoked

Example code

Way to dynamically pass range of values from google sheet to a custom webform link as query string?

I have a sheet where I’ve have hyperlinks to my custom webform. When clicked on a hyperlink it passes the adjacent cell values(Order Number, Client Name) as query string to the webform URL. Now my question is, how to dynamically pass a range of values in this case, the “Products” as query string to the webform URL as an array?

Link to a sample sheet

Following is my sample code-

  1. Code.gs
function doGet(e){
  const template = HtmlService.createTemplateFromFile('form');
  
  template.orderno = e.parameter.orderno;
  template.clientname = e.parameter.client;
  
  //I want the following array like ['Product A', 'Product B', 'Product C'] to be passed dynamically from the sheet itself
  template.productsHtmlString = getProductsHtmlString(['Product A', 'Product B', 'Product C']);

  return template.evaluate();
}

function getProductsHtmlString(arr){
  const productsHtmlArray = [];

  for(let i in arr){
    productsHtmlArray.push(`<div class="productrow"><input id="product${Number(i)+1}" type="text" class="validate" disabled value="${arr[i]}"><label for="product${Number(i)+1}" class="active">Product</label></div>`);
  }

  return productsHtmlArray.join("");
}

function include(filename){
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
  1. form.html

<head>
  <?!= include('stylesheet'); ?>
</head>
<body>
    
  <div class="row">
    <input id="orderno" type="text" disabled value="<?= orderno; ?>" class="validate">
    <label for="orderno" class="active">Order Number</label>
  </div>

  <div class="row">
    <input id="clientname" type="text" disabled value="<?= clientname; ?>" class="validate">
    <label for="clientname" class="active">Client Name</label>
  </div>

  <div id="orderdetails">
    Product Details
    <?!= productsHtmlString; ?>
  </div>
</body>
  1. stylesheet.html
<style>
  .row{
    margin-top: 7.5px;
    margin-bottom: 7.5px;
  }
</style>

SolidJS without JSX

I am planning to make an application that is very light on DOM manipulation (I only really need canvas elements for drawing and a few divs to hold things together) but reactivity is very important. Solid JS strongly appeals to me because of several reasons: 1) push-pull based system with automatic graph-based detection of dependencies (super important for me), 2) hot observables by default, and 3) simple functional API. However, the part I don’t feel so strong about is JSX, since, like I said, I only need to do very little stuff with the DOM. JSX feels like a bit of unnecessary overhead.

Is Solid without JSX viable/good idea? This page of the docs says it ok (https://www.solidjs.com/guides/faq#can-i-use-solids-reactivity-on-its-own) but would I be giving up on anything, e.g. optimization, etc…? I am new to Solid so I would love to have a rough idea before I subscribe to one or the other way of doing things.

React project using

I’m building UI using React, where I am using redux for increment & decrement function. Unfortunately my increment and decrement buttons are not working, may be this issue is coming due to some logical error. I will be very grateful if anyone help me to solve this issue. Here I am posting my source code.

 **Creating Redux store code**


import {createStore} from 'redux';

const initialState ={counter:0, showCounter: true};

const counterReducer = (state =initialState,action) => {
    if (action.type === 'increament') {
    
    state.counter++;
       return {counter: state.counter + 1,
        showCounter: state.showCounter
    };
}

if (action.type === 'increase')  return{
    counter: state.counter + action.amount,
}

if ( action.type ==='decrement'){
    return {
        counter: state.counter - 1,
    };
}

if (action.type === 'toggle'){
    return{
        showCounter: !state.showCounter,
        counter: state.counter
    };
}
return state;

};

const store = createStore(counterReducer);

export default store;
**Counte.js code**

import {useDispatch, useSelector} from 'react-redux';

import classes from './Counter.module.css';

const Counter = () => {
  const dispatch = useDispatch();
const counter = useSelector(state => state.counter);
const show = useSelector(state => state.showCounter);

const increamentHandler = () => {
  dispatch({type:'increamennt', amount:10});
};

const increaseHandler = () => {
dispatch({type:'decrement'});
};

const decrementHandler = () =>{
  dispatch({type:'decreamennt'});
};

  const toggleCounterHandler = () => {
    dispatch({type:'toggle'})
  };

  return (
    <main className={classes.counter}>
      <h1>Redux Counter</h1>
      {show && <div className={classes.value}>{counter}</div>}
      <div>
      <button onClick={increamentHandler}>Increament</button>
      <button onClick={increaseHandler}>Increase by 10</button>
      <button onClick={decrementHandler}>Decrement</button>
      </div>
      <button onClick={toggleCounterHandler}>Toggle Counter</button>
    </main>
  );
};

export default Counter;

Event not listed in Google Analytics Realtime data

I have a form submit event on my page and added a gtag event after clicking the submit button. I tested it using the Google tag assistance and I can see that my event is firing since it is listed here – https://prnt.sc/zDDH6DRgVawa.

However, when I visit the real-time data on the Analytics, no events are listed here – https://prnt.sc/G6uswPi5tmo0. I tried refreshing and waiting for the GA events dashboard but no data is being fetched.

Here’s the snipper where I put my script.

if(refUrl !== '' && currentUrl != refUrl) {

    let previousCampaign = break_address(refUrl);
    
    if(previousCampaign == 'campaign/monthly') {
        console.log('conversion monthly triggered!')
        
        gtag('event', 'conversion', {'send_to': 'AW-xxxxxxxx/xxxxxxxxx', 'value': 800.0, 'currency': 'PHP' });
    }
    if(previousCampaign == 'campaign/onetime') {
        console.log('conversion onetime triggered!')
        
        gtag('event', 'conversion', {'send_to': 'AW-xxxxxxxx/xxxxxxxxx', 'value': 800.0, 'currency': 'PHP' });
    }   

    console.log('CONVERSION FIRED!')
} else {
    console.log('CONVERSION NOT FIRED!')
    // INSERT CONVERSION FAILED API HERE...
}

I hope you can give me some help on this. 🙂

Logout all users with the same JWT token

I am working with React and Nodejs. I am using JWT for the auth mechanism.
Now there is a case where multiple users are logged in with the same email say “[email protected]”.

Now we want to implement “Logout from all devices” which should expire all the tokens and throw the users out of their devices.

What could be the best approach to do that?