Can i send array with null to GraphQL Nest.js resolver?

Can i do that?
I use it in input type:

@Field(() => [String], {
    nullable: true,
  })
  date: string[];

And when i send on in date key, null on some array index, i got an error. Example:
date: [“2023-02-13 00:00:00”, null, null, “2023-02-13 00:00:00”] ->
Error: Expected value of type “String!”, found null.”

Can i send an array with null in some position?

Transition in React is not working like expected

From the website and some articles, i have learned that any changes made to the app will first be reflected in the Virtual DOM. and then to the Real DOM after diffing both trees. the lifecycle hook useEffect will fire once the Real DOM is populated.

Problem

import React from 'react';
import { useEffect, useRef } from 'react';

export function App(props) {
  const ref = useRef();
  useEffect(() => {


    const ref2 = ref.current;

    const div = document.createElement('div')
    div.innerHTML = "ASDF"
    div.style.position = "absolute";
    div.style.top = 0;
    div.style.transition = "all 5s"


    ref2.appendChild(div);

    // this should work theoretically and my div should get a transition
    div.style.top = "100px"


  }, [])
  console.log("render")
  return (
    <div ref={ref} className='App'>
      <h1>Hello React.</h1>
      <h2>Start editing to see some magic happen!</h2>
    </div>
  );
}

// Log to console
console.log('Hello console')

Running the above code gives a static div with top as 100px instead of a transition.

So, I tried the following code

import React from 'react';
import { useEffect, useRef } from 'react';

export function App(props) {
  const ref = useRef();
  useEffect(() => {


    const ref2 = ref.current;

    const div = document.createElement('div')
    div.innerHTML = "ASDF"
    div.style.position = "absolute";
    div.style.top = 0;
    div.style.transition = "all 5s"



    ref2.appendChild(div);
    
    // The following three lines is the only change
    setTimeout(()=>{
      div.style.top = "100px"
    }, 0)

  }, [])
  console.log("render")
  return (
    <div ref={ref} className='App'>
      <h1>Hello React.</h1>
      <h2>Start editing to see some magic happen!</h2>
    </div>
  );
}

// Log to console
console.log('Hello console')

and this gives me the result i wanted. where initially the div is positioned at the top and animates to 100px.

**Why does a 0 second setTimeout work? Does it have something to do with the event loop? **

I can’t use useTransition, animations API, framer-motion or any other animation method. I need the transition to happen this way only. Thank you for your patience!

Set javascript variable from php script

I’m not a developer may be that’s why I’m struggling with something that should not be difficult but somehow can’t do that for about a week already.

As a result I need to get the ${translator} variable to proceed
To get it I have a php script that looks up the translator and returns it as a text
https://find.dhamma.gift/scripts/translator-lookup.php?fromjs=/sutta/sn/sn1/sn1.1

Output

sv

I need to use the variable in this url for translationResponse.
console.log(/o/sutta/${slugReady}_translation-ru-${translator}.json`);

It should look like

/o/sutta/sn/sn1/sn1.1_translation-ru-sv.json

But I’m getting this in console log

Url for translationResponse is /o/sutta/sn/sn1/sn1.1_translation-ru-undefined.json
translator outside fetch is sv 

But in the code translator is set before the url for translationResponse

I tried many ways that I’ve found on stackoverflow and other sites. But none of them work

Please help. Javascript won this time. I’m defeated.

What I’ve tried

`let translatorData = fetch(‘http://localhost:8080/scripts/translator-lookup.php?fromjs=/sutta/sn/sn1/sn1.1’)

.then(response => response.text());

Promise.all([translatorData]).then(responses => {

const [translator] = responses;

console.log(‘translator outside fetch is’, translator);

});`

Or

`var myGlobalVar = “”;

fetch(‘https://find.dhamma.gift/scripts/translator-lookup.php?fromjs=/sutta/sn/sn1/sn1.1’)

.then(response => response.text())

.then(data => {

window.myGlobalVar = data;

console.log('myGlobalVar is ', myGlobalVar);

// do something with the response data

})

.catch(error => console.error(error));`

Or

`fetch(

`https://find.dhamma.gift/scripts/translator-lookup.php?fromjs=${texttype}/${slugReady}`).then(response => {

return response.text()

})

.then(text => {

console.log(‘text is “‘, text,'”‘)

let translator = text;

console.log(‘translator before fetch “‘, translator, ‘”‘);

})

console.log('translator after fetch "', translator, '"');`

Core fore url for translationResponse works fine if I’ll set variable directly

`let translator = “sv”;

const translationResponse = fetch(

        `/o/sutta/${slugReady}_translation-ru-${translator}.json`

).then(response => response.json());`

Dynamically Add New Item With Id [closed]

On my page I add a div with id and then try to add something in it

document.getElementById('main_div').innerHTML = '<div id="new1"></div>';
....
document.getElementById('new1').innerHTML = 'HELLO';

Web page doesn’t recognise the new div (new1) that I added. “Uncaught TypeError: Cannot read properties of null” error occur. I think we must introduce the the new element before using it. But how can we do that?

React render after effects from loading spinner

I have a React application with a loading spinner that goes away when an API call finishes. I have the loading spinner set up to render in my index file like this:

  if (isFinishedLoading === false) {
    return (
      <LoadingSpinner/>
    );
  }

  return (
     {rest of code}
  )

Where isFinishedLoading is false as set by useState. I call the needed API like this in useEffect:

useEffect(() => {
    apiGET()
}, [])

and I call setIsFinishedLoading(true) inside of apiGET().

However, there is always a split second where the page is not fully rendered, it looks like some divs appear before others and the site flickers a little bit, it doesn’t look like a fully rendered site.

My question is: is this just a fact of using React that it will take a half second for the page to fully render? Or am I implementing my loading spinner in the wrong way?

I’ve tried a few things:

  1. Putting my setIsFinishedLoading(true) in a setTimeout(),
  2. Adding an additional loading flag to wait until all images are loaded like this: React: Show loading spinner while images load

Ideally, I’d be able to call something like img “onLoad” for divs, but that sounds a lot like useEffect() anyway. For what it’s worth, the application is in Gatsby.

API in node.js is dead?

So, API in Node.js.

Is it correct to say that when we want to write an API server, for mobile, for programmers, for any service that actually wants to communicate with our database. Is there a distinct disadvantage to using Next.js over any other node.js framework? (nodejs, nest, express…)

I mean, is there really any reason to use node.js other than for backend services that don’t communicate with any frontend? Especially when in Next.js, we can in the same breath, produce a frontend that will communicate with the API, authentication, documentation and more… it feels to me that all the knowledge of node.js has already become a bit redundant,

isn’t it?

Touchscreen get browser click or ouse even type

We have an Elo touchscreen that has multi touch. This can be probably for most touch screens as well, but we are trying to capture the “event type” on the body when a user touches the screen so we can trigger a timeout event. Right now we are using jQuery just for ease.

$('body').on("click mouseover mousedown touchstart touchend mouseup", function(e){
   console.log("trigger type" + e.type);  
 });

Is there a way with Javascript (or jQuery) to get the touch type without first defining the events we want to watch for?
Instead of having to define and watching, setting a case statement, etc for “click”, “mousedown”, etc.
Is there a way to just get the event type?

My assumption is probably not, but since it is a proprietary touchscreen manufacturer, knowing the type from the DOM would be helpful. We are using Chrome/Chromium for a web app interactive for this.

This.gamestate variable not recognized (phaser.js)

So I’ve been trying to replicate the tile chebyshev lab outside of the phaser lab area, in glitch, and I’ve been Using the variable solution I got in this answer about using Phaser.gamestate for my variable that need to be update in many locations

And my Console hits me with Cannot read properties of undefined (reading 'gameState')

I’ve tried the this context setting too, but it continues this error, what can I do to fix it?

My Code:

import Phaser from "../lib/phaser.js";

export default class Game extends Phaser.Scene {
  constructor() {
    super("game1");
  }

  preload() {
    this.load.image(
      "Tileset",
      "https://cdn.glitch.global/cc90578e-c3d0-47c5-bb0d-f5a81263b5b6/pixil-frame-0%20(17).png?v=1675985219390"
    );
    this.load.tilemapTiledJSON(
      "map",
      "https://cdn.glitch.global/cc90578e-c3d0-47c5-bb0d-f5a81263b5b6/Map.tmj?v=1675985261369"
    );
    this.load.spritesheet(
      "player",
      "https://cdn.glitch.global/cc90578e-c3d0-47c5-bb0d-f5a81263b5b6/pixil-frame-0%20(13).png?v=1675904194091",
      { frameWidth: 32, frameHeight: 32 }
    );
  }

  create() {
    this.gameState = {
      map: "",
      cursors: "",
    };

    this.gameState.map = this.make.tilemap({ key: "map" });
    this.tiles = this.gameState.map.addTilesetImage("tileSet", "Tileset");
    this.worldLayer = this.gameState.map.createLayer(
      "Block Layer",
      this.tiles,
      0,
      0
    );

    this.player = this.physics.add.sprite(0, 0, "player", 1);

    this.cameras.main.setBounds(
      0,
      0,
      this.gameState.map.widthInPixels,
      this.gameState.map.heightInPixels
    );
    this.cameras.main.startFollow(this.player);

    this.gameState.cursors = this.input.keyboard.createCursorKeys();
  }

  update() {
    function updateMap() {
      console.log(this.gameState)
      var origin = this.gameState.map.getTileAtWorldXY(
        this.player.x,
        this.player.y
      );

      this.gameState.map.forEachTile(function (tile) {
        var dist = Phaser.Math.Distance.Chebyshev(
          origin.x,
          origin.y,
          tile.x,
          tile.y
        );

        tile.setAlpha(1 - 0.1 * dist);
      }, this);
    }

    if (this.gameState.cursors.left.isDown) {
      this.player.setVelocityX(-50);
      this.player.anims.play("left", true);
    } else if (this.gameState.cursors.right.isDown) {
      this.player.setVelocityX(50);
      this.player.anims.play("right", true);
    } else if (this.gameState.cursors.up.isDown) {
      this.player.setVelocityY(-50);
    } else if (this.gameState.cursors.down.isDown) {
      this.player.setVelocityY(-50);
    } else {
      this.player.setVelocityX(0);
    }

    updateMap();
  }
}

how to use combineLatest/zip but only react to emits of second observable and ignore emits from first observable

So I have this property initialization:

this.currentMapObject$ = zip(this.mapObjects$, this.currentMapObjectsIndex$,
      (mapObjects, index) => mapObjects[index]);

I only want to emit this.currentMapObject$ if this.currentMapObjectsIndex$ emits but not if this.mapObjects$ emits.

As far as I know now this.currentMapObject$ will emit even if a single property of an item of this.mapObjects$ changes. I want to ignore all changes to this.mapObjects$ and only take its current value, but I DO want to react to this.currentMapObjectsIndex$ changes

Stacked image slide

Hello I’m using slick slide to make the slides in a list of images on my page, but when loading the screen the images appear stacked and then they go to the slide format, is there any solution to only display them when they are already in slides ?

Html:

<div class="conteiner">
        <div class="row-fluid">
            <div class="titulo-vitrine-marcas">
                <span>{{ section.settings.title }}</span>
            </div>
            <div class="marcas">
                {% for block in section.blocks %}
                    <li class="marca">
                        {% if block.settings.collection != blank %}
                                {% if block.settings.image != blank %}
                                    {%- capture image_size -%}{{ section.settings.image_max_width }}x{%- endcapture -%}
                                    <img class="marca-imagem" style="max-width: {{ section.settings.image_max_width }}px;" src="{{ block.settings.image | img_url: image_size, scale: 2 }}" width="{{ block.settings.image.width }}" height="{{ block.settings.image.height }}" onclick="location.href = '{{ block.settings.collection.url }}';">
                                {% endif %}
                        {% endif %}
                    </li>
                {% endfor %}
            </div>
        </div>
    </div>

JS:

$('.marcas').slick({
        infinite: true,
        dots: false,
        arrows: true,
        prevArrow:
            "<div class="slick-prev slick-arrow" style="display: block;"><svg enable-background="new 0 0 330.002 330.002" version="1.1" viewBox="0 0 330.002 330.002" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m233.25 306l-105.75-141 105.75-141c4.971-6.628 3.627-16.03-3-21-6.627-4.971-16.03-3.626-21 3l-112.5 150c-4 5.333-4 12.667 0 18l112.5 150c2.947 3.93 7.451 6.001 12.012 6.001 3.131 0 6.29-0.978 8.988-3.001 6.628-4.971 7.971-14.373 3-21z"></path></svg></div>",
        nextArrow:
            "<div class="slick-next slick-arrow" style="display: block;"><svg enable-background="new 0 0 330.002 330.002" version="1.1" viewBox="0 0 330.002 330.002" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m233.25 156l-112.5-150c-4.972-6.628-14.372-7.97-21-3-6.628 4.971-7.971 14.373-3 21l105.75 141-105.75 141c-4.971 6.627-3.627 16.03 3 21 2.698 2.024 5.856 3.001 8.988 3.001 4.561 0 9.065-2.072 12.012-6.001l112.5-150c4-5.333 4-12.667 0-18z"></path></svg></div>",
        slidesToShow: 4,
        slidesToScroll: 1,
        responsive: [
            {
                breakpoint: 980,
                settings: {
                    autoplay: false,
                    autoplaySpeed: 2000,
                    slidesToShow: 1,
                    slidesToScroll: 1,
                    infinite: true,
                    arrows: true,
                    prevArrow:
                        "<divx20class=x22slick-prevx22><svgx20width=x22451.85pxx22x20height=x22451.85pxx22x20enable-background=x22newx200x200x20451.847x20451.847x22x20version=x221.1x22x20viewBox=x220x200x20451.847x20451.847x22x20xml:space=x22preservex22x20xmlns=x22http://www.w3.org/2000/svgx22><pathx20d=x22m97.141x20225.92c0-8.095x203.091-16.192x209.259-22.366l194.29-194.28c12.359-12.359x2032.397-12.359x2044.751x200x2012.354x2012.354x2012.354x2032.388x200x2044.748l-171.92x20171.9x20171.9x20171.91c12.354x2012.354x2012.354x2032.391x200x2044.744-12.354x2012.365-32.386x2012.365-44.745x200l-194.29-194.28c-6.167-6.177-9.252-14.274-9.252-22.372zx22/></svg></div>",
                    nextArrow:
                        "<divx20class=x22slick-nextx22><svgx20width=x22451.85pxx22x20height=x22451.85pxx22x20enable-background=x22newx200x200x20451.846x20451.847x22x20version=x221.1x22x20viewBox=x220x200x20451.846x20451.847x22x20xml:space=x22preservex22x20xmlns=x22http://www.w3.org/2000/svgx22><pathx20d=x22m345.44x20248.29l-194.29x20194.28c-12.359x2012.365-32.397x2012.365-44.75x200-12.354-12.354-12.354-32.391x200-44.744l171.91-171.91-171.91-171.9c-12.354-12.359-12.354-32.394x200-44.748x2012.354-12.359x2032.391-12.359x2044.75x200l194.29x20194.28c6.177x206.18x209.262x2014.271x209.262x2022.366x200x208.099-3.091x2016.196-9.267x2022.373zx22/></svg></div>",
                }
            }
        ]
    });

CSS:

.vitrine-marcas .conteiner {
    padding-bottom: 30px !important;
    max-width: 1380px;
    width: 100%;
    margin: 0 auto;
}

.vitrine-marcas .marcas li {
    height: 100%;
    opacity: 1 !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.titulo-vitrine-marcas {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    position: relative;
}

.titulo-vitrine-marcas span {
    font-size: 25px;
    font-weight: 500;
}

.vitrine-marcas .marcas .slick-prev {
    left: -25px;
}

.vitrine-marcas .marcas .slick-next {
    right: -25px;
}

.vitrine-marcas .marcas .slick-arrow {
    cursor: pointer;
    position: absolute;
    z-index: 1;
}

.vitrine-marcas .marcas .slick-arrow svg {
    width: 33px;
    height: 33px;
    display: flex;
}

@media only screen and (max-width: 1024px) {
    .titulo-vitrine-marcas span {
        font-size: 20px;
    }

    .vitrine-marcas .marcas .slick-prev {
        left: -5px;
        margin-left: 20px;
    }

    .vitrine-marcas .marcas .slick-next {
        right: -5px !important;
        margin-right: 20px;
    }

    .vitrine-marcas .marcas .slick-arrow svg {
        width: 25px;
        height: 25px;
    }
}

.vitrine-marcas .slick-slider {
    display: flex !important;
    align-items: center !important;
}

.slick-track {
    display: flex !important;
}

.slick-slide {
    height: inherit !important;
    display: flex !important;
    justify-content: center;
    align-items: center;
}

When starting the page it looks like this:

enter image description here

After:

enter image description here

DOMException while copying text to clipboard in javascript

I am trying to make a simple encoder in javascript, and copying the output to clipboard, but the code gives an error.

I tried this code:

function encode() {
  let alphabet = " abcdefghijklmnopqrstuvwxyz1234567890-=!@#$%^&*()_+[];'/.,'{}|:~";
  const a_list= alphabet.split('');
  const m_list = prompt("message: ").split('');
  let return_message = "";
  for (let i=0; i<m_list.length; i++) {
    let current_letter = m_list[i];
    let translated_letter = a_list[a_list.indexOf(current_letter)+5];
    return_message+=translated_letter;
  }
  navigator.clipboard.writeText(return_message);
}
encode()

but the console gives this error:

Error: DOMException {INDEX_SIZE_ERR: 1, DOMSTRING_SIZE_ERR: 2, HIERARCHY_REQUEST_ERR: 3, WRONG_DOCUMENT_ERR: 4, INVALID_CHARACTER_ERR: 5, …}

I host the server in replit.
When I try to do an alert with the encoded words, it works fine.

Elements disappear vue js template in safari

I wonder if anyone has experienced this before.

I have a vue 2 template rendering using vuetify 2, it has some buttons on the page to navigate between sub pages. But in safari only, those buttons “flash” on the page load and then disappear?

I can inspect them and see them in the DOM, im finding that removing some inline style properties (overflow: auto etc) can hack it back to showing.

But any other browser on any other platform theyve all been working perfectly fine. I also have another vue template which has similar buttons setup and that also works in safari.

The other factor ive found as well is that stretching the browser window to a stupidly wide width renders the button?

Thanks in advance!

enter image description here

How do I create a Backend for an E-Commerce Website [closed]

Hello im going to be very straightforward here so here’s my question, I’m a beginner when it comes to developing a website and currently im preparing for my capstone project and I just want to ask if there’s any website or youtube tutorial about developing the backend of a project because I really have no idea and sense about it. The only thing I know is the front end and back end is a really different dimension from what I’m trying to do right now so to summarize I know nothing of backend and I really appreciate it if you have any tips and videos that might help me start creating a server connecting it from a database for an e-commerce desing website.
Thank you in Advance ^^

I already finished studying front end developing and yep backend is a really different one and I just want a tutorial for it.

TypeError: exports.[interface_name] is not a constructor

I’ve created an Interface in Typescript NodeJS but I cannot wrap my head-around the error that says:

TypeError: exports.Something is not a constructor

interface Something {
    name: string;
    message: string;
    stack?: string;
}

interface SomethingConstructor {
    new(message?: string): Something;
    (message?: string): Something;
    readonly prototype: Something;
}

export declare var Something: SomethingConstructor;

This is what I have created as an Interface. And using it like so.

import { Something } from './dummy;

testFunction();

function testFunction() {
    try {
        const something = new Something("Here is a message");
        console.log(something.message)
    } catch (e) {
        console.log('in catch block');
        console.log(e);
    }

}

I expected this would run and prints “Here is a message” in the console but throws the “is not a constructor” error. I might not know how I should use interfaces. Please shed light on how can I do something like it?