Why getPosts() is called within dispatch parentheses? How dispatch is working here?

export const getPosts = () => dispatch => {
  dispatch(setPostLoading());
  axios
    .get('/api/posts')
    .then(res =>{
     
      dispatch({
        type: GET_POSTS,
        payload: res.data
      })}
    )
    .catch(err =>
      dispatch({
        type: GET_POSTS,
        payload: null
      })
    );
};


export const addLike = id => dispatch => {
  axios
    .post(`/api/posts/like/${id}`)
    .then(res =>{ 
      dispatch(getPosts())
    })
    .catch(err =>
      dispatch({
        type: GET_ERRORS,
        payload: err.response.data
      })
    );
};

In my project whenever a user click on the like button of a post, addLike function will be called with an id of that post.

why this simple Userscript not working as I wanted?

I have been trying to make a userscript and I made one for Udemy. It checks the course’s progress and calculates the percentage, then adds the percentage after the progress text. But I don’t understand why it doesn’t work..!!
Note: I’m a total newbie to making a userscript. Although I use many for different purposes.

// @name         Udemy course percentage checker
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Trying to do something new
// @author       You
// @match        https://www.udemy.com/course/The-Course-Name/learn*
// @grant        none

// ==/UserScript==

(function() {
    'use strict';
    // Get the course progress element
    var progress = document.querySelector(".progress-popover-content--container--1SoAL");

    // If the element exists, get the numbers from the text and calculate the percentage
    if (progress) {
        var text = progress.querySelector('[data-purpose="progress-popover-text"]').textContent;
        var numbers = text.match(/d+/g);
        var completed = parseInt(numbers[0]);
        var total = parseInt(numbers[1]);
        var percentage = Math.round(completed / total * 100);

    // Create a new element to show the percentage and append it to the progress element
        var percentageElement = document.createElement('div');
        percentageElement.textContent = percentage + '%';
        percentageElement.className = 'ud-heading-sm';
        progress.appendChild(percentageElement);
    }
})();

How to perform date range queries in faunadb

I’m trying to perform a date range query to return all the records between 2 dates, but no matter what I try, it always returns zero results, even though I have the data existing in the collection.

My index was initially defined like this:

CreateIndex({
    name: "entries_by_date_only",
    source: Collection("Entries"),
    terms: [{ field: ["data", "created"] }]
})

This is a sample record from the Entries collection:

{
  "ref": Ref(Collection("Entries"), "36561645689871265"),
  "ts": 1684938186510000,
  "data": {
    "email": "[email protected]",
    "firstEntry": true,
    "state": "NY",
    "optin": true,
    "lang": "en",
    "created": "2023-08-22T10:23:06-05:00",
    "name": "Test Name",
    "ip": "123.123.456.456",
    "eligibility": true
  }
}

And this is the query I am trying:

const START_DATE = req.params.startDate; // I have tried 2023-08-01 AND 2023-08-01T00:00:00-05:00
const END_DATE = req.params.endDate; // I have tried: 2023-08-30 AND 2023-08-30T23:59:59-05:00

const entriesQuery = q.Map(
    q.Paginate(
        q.Range(q.Match(q.Index("allEntries")), START_DATE, END_DATE)
    ),
    q.Lambda("entry", q.Get(q.Var("entry")))
);

const entriesResult = await client.query(entriesQuery);

console.log("ENTRIES", entriesResult); // Logs: ENTRIES { data: [] }

Is there anything I’m missing here? The field holds the string in ISO format, so I thought I could use it for this purpose. Is that even possible?
Thanks in advance for any help.

Why am I still getting a “Warning: Each child in a list should have a unique “key” prop.”

I see the component in react dev tools and each of the Summaries has a unique key on it. But the warning won’t go away.

const summaryData = [
    {
      id: 1,
      box: "one",
      sprite: "html5",   
    },
    {
      id: 2,
      box: "two",
      sprite: "envelope",
    },
    {
      id: 3,
      box: "three",
      sprite: "wordpress",
    },
    {
      id: 4,
      box: "four",
      sprite: "tongue",
    },
  ];
{summaryData.map((summary) => (
            <Summaries
              key={`box${summary.id}`}
              box={summary.box}
              sprite={summary.sprite}
            />
          ))}

Privacy: API MediaDevices.getUserMedia() and Cache-control: private

For an experimental website/pwa, I’m using the user’s camera stream with MediaDevices.getUserMedia() as background with this:

<script>
var video = document.querySelector("#videoElement");

if (navigator.mediaDevices.getUserMedia) {
  navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } })
    .then(function (stream) {
      video.srcObject = stream;
    })
    .catch(function (err0r) {
      console.log("Something went wrong!");
    });
}
</script>

and

<div id="container">
    <video playsInline="true" muted="true" autoplay="true" id="videoElement">
    </video>
</div>

On the same page, under , I have the following meta tag:
<meta http-equiv="Cache-control" content="private">

My question is: can I be 100% sure that the video stream is stored in the local and private cache of the user’s browser? Or are files still stored on the server?

The aim is to make the website/pwa as confidential as possible and I don’t want to store any user data.

Thank you very much for your support.

Jehane

embad Javascript id based form in runtime Material tabs

One JavaScript library is constructing a form under DIV which is ID based.

Example: <div class="config-options" id="config-options-task-1">

This needs to to be in runtime in tab structure angular and every time DIV class="config-options" id="config-options-task-1"> should inject in tab 2 also not with ID changed

This code doesn’t load runtime div data on each tab click.

I need help, on this to run this. Any more information?

RXJS Observable, with a dynamic function pipe

I’m trying to return an observable with a pipe that gets populated every time it gets called.
To demonstrate what exactly this means, look at the example below:

const myObservable = timer(1000);
return myObservable.pipe(getCustomPipe());
function getCustomPipe() {
   return condition ? pipe(1,2,3) : pipe(4,5,6)
}

What actually happens in my current approach, getCustomPipe() is called once and the result kept into the observable pipe without calling it again, and this is expected as I’m calling the function inside the pipe without introducing some kind of pipe factory function.

How it should be:

return myObservable.pipe(
    mergePipe(() => getCustomPipe())
);

// mergePipe is an imaginary pipe factory

Is there any solution for this kind of pipe problem?

How to break out a website from FB webview?

My website uses Google OAuth login and my visitors complain that they cannot login.
The reason is that they receive the link in Messenger and FB opens urls in its own webview and not in a browser (Chrome or Safari).

I have figured out how to ask the user to leave the FB window, https://stackoverflow.com/a/54231915/1031191
but I would love to make an automatic mechanism that makes the webpage leave the FB window.

Is there any javascript solution to leave the FB window?

‘process.argv’/’process.argv.slice(1)’ is not working in cypress

I am using cypress with js for the automation testing.
My current requirement is to store the command which user pass to run a script.
Let me explain it in detail:
Here is my package.json file:

"scripts": {
    "e2e-headless": "cypress run --spec cypress/integration/examples/allSpec.js --browser chrome",
    "e2e": "cypress run --spec cypress/integration/examples/allSpec.js --browser chrome --headed",
    "suite": "cypress run --spec cypress/integration/examples/Suite.js --browser chrome --headed"
  },

User can use any script to run. if user run npm run suite command. I want to store this command in a variable. i.e. If I store it in cmd variable and print it, it should give me an output npm run suite

For that I tried below code in test.js file:

const scriptName = process.argv.slice(1); //with different number in argument
console.log('The script name is:' + scriptName);

and

const scriptName = process.argv; //also tried process.argv[2]
console.log('The script name is:' + scriptName);

But it’s not giving me the expected output.
I also tried:

"scripts": {
  "suite": "cross-env MY_SCRIPT_NAME=cypress run --spec cypress/integration/examples/Suite.js --browser chrome --headed"
}
const scriptName = process.env.MY_SCRIPT_NAME;
console.log('The script name is: ' + scriptName);

npm install --save-dev cross-env
But it gives me an error while executing a script that command is not recogised. I can’t put the screenshot of that right now, because I restore my code as it was and don’t want to disturb it.
Please help me. Thank you!

“Unmatched Route” when I start a React Native application with Expo

I’m new to React Native, and I just trying to start my React Native app with Expo, and instantly says: “Unmatched Route – Page could not be found” when I just access on Metro Bundler through the Expo Go app.

On-Screen Error:
enter image description here

on App.tsx:

import React from 'react';
import Navigation from './app/Navigation/Navigation';

export default function App() {
  return (
    <Navigation />
  );
}

on app/Navigation/Navigation.tsx:

import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import Home from '../pages/Home';
import StartScreen from '../pages/StartScreen';

const Stack = createNativeStackNavigator();

export default function Navigation() {
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName="StartScreen">
        <Stack.Screen name="StartScreen" component={StartScreen} />
        <Stack.Screen name="Home" component={Home} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

on app/pages/Home.tsx:

import { View, Text, SafeAreaView, useColorScheme } from 'react-native';
import styles from '../utilities/styles';
import React from 'react';
const packageJson = require('../../package.json');

const appVersion = packageJson.version;

const Home = () => {

    const colorScheme = useColorScheme();

    const themeContainerStyle = colorScheme === 'light' ? styles.lightContainer : styles.darkContainer;
    const themeTextStyle = colorScheme === 'light' ? styles.lightTextTheme : styles.darkTextTheme;

    return (
        <SafeAreaView style={[styles.container, themeContainerStyle]}>
            <View style={[styles.contentCenter]}>
                <Text style={[themeTextStyle, styles.h3]}>Home Page</Text>
            </View>
            <View style={[styles.contentEnd]}>
                <Text style={[themeTextStyle]}>Ver: {appVersion}</Text>
            </View>
        </SafeAreaView>
    )
}

export default Home;

on app/pages/StartScreen.tsx:

import { View, Text, SafeAreaView, useColorScheme } from 'react-native';
import styles from '../utilities/styles';
import React from 'react';
const packageJson = require('../../package.json');

const appVersion = packageJson.version;

const StartScreen = () => {

    const colorScheme = useColorScheme();

    const themeContainerStyle = colorScheme === 'light' ? styles.lightContainer : styles.darkContainer;
    const themeTextStyle = colorScheme === 'light' ? styles.lightTextTheme : styles.darkTextTheme;

    setTimeout(redirectToHome, 5000);

    return (
        <SafeAreaView style={[styles.container, themeContainerStyle]}>
            <View style={[styles.contentCenter]}>
                <Text style={[themeTextStyle, styles.h3]}>Project Spectrum</Text>
            </View>
            <View style={[styles.contentEnd]}>
                <Text style={[themeTextStyle]}>Ver: {appVersion}</Text>
            </View>
        </SafeAreaView>
    )
}

export default StartScreen;

I just tried add my Entry Point route into the app.json but even that it doesn’t work.

Additional function is executed when enter or space is pressed when it shouldn’t in simulated keyboard

I have a simulated keyboard in html. There are buttons forming a keyboard on the screen. When they are clicked the character assigned to that button is appended to a text element on the screen. Using the actual irl keyboard is possible too, working in the same manner.

The problem is that when I click an onscreen button and then press the irl spacebar or enter buttons, that onscreen button character is repeated after the space or enter. This happens with space and enter only, and only with the irl keyboard press. When the virtual space is clicked on the screen it works as it should. For example:

  1. I click the a key on screen

    output:a

  2. I press the irl keyboard spacebar

    output:a a

  3. I press the irl keyboard enter button

    output:a a

         a
    

I started with the irl keyboard and the html keyboard using different functions so I thought that might be the issue. I tried combinging them into one and the same issue persists. I added a paraemeter to the function that tells where the function is called from and strangley when I press the irl spacebar it shows that the extranious character is being called from the html button’s onclick. I feel like I’m missing something obvious or I’ve found a weird bug.

The HTML, please excuse any immature identifiers:

<body>
    <div class="poop" >
        <div class="myDiv" >
            <div id = "bh" class="behind-text"></div>
            <img class="typewriter-top" src="typewriter-top.png" id="typewriter-top">
            <div id="letter" class="text">
                <span class="inner-text" id="text"></span>
            </div>
            <img class="typewriter-bottom" src="typewriter-bottom.png" alt="typewriter-bottom">
            <img class="typewriter-bar" id="bar" src="typewriter-bar.png" alt="typewriter-bar">
          
            <button class="enter-container" id="Enter" onclick="typeHit(this.id,'click')"></button>
            <div class="outer">
                
    
                <div class="line-zero">
                    <button class="button small" id="1" onclick="typeHit(this.id,'click')">1</button>
                    <button class="button small" id="2" onclick="typeHit(this.id,'click')">2</button>
                    <button class="button small" id="3" onclick="typeHit(this.id,'click')">3</button>
                    <button class="button small" id="4" onclick="typeHit(this.id,'click')">4</button>
                    <button class="button small" id="5" onclick="typeHit(this.id,'click')">5</button>
                    <button class="button small" id="6" onclick="typeHit(this.id,'click')">6</button>
                    <button class="button small" id="7" onclick="typeHit(this.id,'click')">7</button>
                    <button class="button small" id="8" onclick="typeHit(this.id,'click')">8</button>
                    <button class="button small" id="9" onclick="typeHit(this.id,'click')">9</button>
                    <button class="button small" id="0" onclick="typeHit(this.id,'click')">0</button>
                </div>
                <button class="parenthesis-button" id="(" onclick="typeHit(this.id,'click')">( )</button>
                <div class="line-one">
                    <button class="l1b" id="Q" onclick="typeHit(this.id,'click')">Q</button>
                    <button class="l1b" id="W" onclick="typeHit(this.id,'click')">W</button>
                    <button class="l1b" id="E" onclick="typeHit(this.id,'click')">E</button>
                    <button class="l1b" id="R" onclick="typeHit(this.id,'click')">R</button>
                    <button class="l1b" id="T" onclick="typeHit(this.id,'click')">T</button>
                    <button class="l1b" id="Y" onclick="typeHit(this.id,'click')">Y</button>
                    <button class="l1b" id="U" onclick="typeHit(this.id,'click')">U</button>
                    <button class="l1b" id="I" onclick="typeHit(this.id,'click')">I</button>
                    <button class="l1b" id="O" onclick="typeHit(this.id,'click')">O</button>
                    <button class="l1b" id="P" onclick="typeHit(this.id,'click')">P</button>
                    <button class="l1b" id="-" onclick="typeHit(this.id,'click')" style="font-size: 15px; font-weight: bold;">- _</button>
                </div>
                <div class="line-two">
                    <button id="A" onclick="typeHit(this.id,'click')">A</button>
                    <button id="S" onclick="typeHit(this.id,'click')">S</button>
                    <button id="D" onclick="typeHit(this.id,'click')">D</button>
                    <button id="F" onclick="typeHit(this.id,'click')">F</button>
                    <button id="G" onclick="typeHit(this.id,'click')">G</button>
                    <button id="H" onclick="typeHit(this.id,'click')">H</button>
                    <button id="J" onclick="typeHit(this.id,'click')">J</button>
                    <button id="K" onclick="typeHit(this.id,'click')">K</button>
                    <button id="L" onclick="typeHit(this.id,'click')">L</button>
                    <button class="double-button" id=";" onclick="typeHit(this.id,'click')" style="font-size: 15px; font-weight: bold;">; :</button>
                    <button class="double-button" id="'" onclick="typeHit(this.id,'click')" style="font-size: 15px;  font-weight: bold;"><br />' "</button>
                </div>
                
                <div class="line-three">
                    <button class="button shift" id="shift" onclick="shifter()" style="text-shadow: 0px 0px 1px black;font-size: 8px;">SHFT</button>
                    <button id="Z" onclick="typeHit(this.id,'click')">Z</button>
                    <button id="X" onclick="typeHit(this.id,'click')">X</button>
                    <button id="C" onclick="typeHit(this.id,'click')">C</button>
                    <button id="V" onclick="typeHit(this.id,'click')">V</button>
                    <button id="B" onclick="typeHit(this.id,'click')">B</button>
                    <button id="N" onclick="typeHit(this.id,'click')">N</button>
                    <button id="M" onclick="typeHit(this.id,'click')">M</button>
                    <button class="double-button" id="," onclick="typeHit(this.id,'click')" style="font-size: px;  font-weight: bold;">,</button>
                    <button class="double-button" id="." onclick="typeHit(this.id,'click')" style="font-size: 15px;  font-weight: bold;">.</button>
                    <button class="double-button" id="?" onclick="typeHit(this.id,'click')" style="font-size: 15px; ">? /</button>
                </div>
                <button class="right-shift" onclick="shifter()" style="text-shadow: 0px 0px 1px black;font-size: 8px;">SHFT</button>
               
                <div class="line-four">
                    <button class="button space" id="Space" width="1000px" border-radius="100%" onclick="typeHit(this.id,'click')"></button>
                </div>
            </div>
        </div>
    </div>
   
    <script src="script.js" type="text/javascript"></script>
</body>

The Javascript:

window.addEventListener('keypress',function(e) {
    console.log("__"+e.key+"___");
    typeHit(e.key,'press');
}
);

function typeHit(key,whereYouComeFrom) {
    console.log(whereYouComeFrom);
    var len = lines[lines.length-1].length;
    if(lines.length <= 26) {
        if(len == null || len < 49 || (len-49)%51 != 0) {
            if(key == "Space") {
                hit.play();
                hit.currentTime = 0;
                // https://www.utf8-chartable.de/unicode-utf8-table.pl?start=128&number=128&utf8=string-literal&unicodeinhtml=hex
                lines[lines.length-1] += " ";
                document.getElementById('text').textContent = document.getElementById('text').textContent + "xa0";
            } else if(key == "Enter") {
                returnn.play();
                returnn.currentTime = 0;
                console.log("*************");
                console.log(lines[lines.length-1]);
                lines[lines.length] = " ";
                console.log(lines[lines.length]);
                enter();
            } else {
                hit.play();
                hit.currentTime = 0;
                if(shifted == false) {
                    lines[lines.length-1] += key.toLowerCase();
                    document.getElementById('text').textContent = document.getElementById('text').textContent + key.toLowerCase();
                } else {
                    let el = '';
                    if(key == '?') {
                        el = '/';
                    } else if(key == '(') {
                        el = ')';
                    } else if(key == ';') {
                        el = ':';
                    } else if(key == ''') {
                        el = '"';
                    } else if(key == '-') {
                        el = '_';
                    } else {
                        el = key;
                    }
                    lines[lines.length-1] += el;
                    document.getElementById('text').textContent = document.getElementById('text').textContent + el;
                }
            }
            let str = document.getElementById('text').textContent;
            shift();
        } else if(key == "Enter") {
            returnn.play();
            returnn.currentTime = 0;
            lines[lines.length] = "";
            enter();
        }
    }
    shifted = false;
}

express api (or server render) with three.js

I want to generate 3d models in base64 format (or any type of image) to use statically, but there is a problem: the only way I found it was with three.js, and my application is a web application that runs on a server (node.js), there is no page to load three.js. I can’t find solutions to generate static images of a 3d model server-side to save and re-use.

to be more clear, I want to generate a minecraft skin (in model, character format) from the 3d skin. and I’ve already had success doing this with an HTML page, but I have no idea how to do this on the server side.
I know that there is a way for me to use three.js with nodejs (without three/examples/jsm/.., and there is a lib for that), but the tools always give some conflict. I can’t use “modules” in the typescript application, which forces me to find a solution myself (since the html solution is a module). The code that I run in HTML is not possible to be used in NodeJs, mainly because the main tool (SkinViewer3D) is made to run in HTML.

Is there an easier way to do this?

Until then, I just generated an HTML page that does what I want, but this is not useful enough, as the user needs to open the page to load the model and I can save a copy of the model in static form. What I want is to be able to generate the model and a print of it without having to open an HTML page.

Initially I thought of a way to use this with a rest api that returns a base64 of the ready model, receiving a parameter (skin url) and rendering it on the server, then returning the printout of the customized and rendered model. but I also don’t know how I can do this, since I use express, and this is nodejs (and I don’t want to use puppeter to load the entire page and then export).

my second option is to have a method/class already within the application, which will load the 3d model and then return a print of it to be used statically, which I even prefer, but still, it’s within nodejs.

Vite React app HashRouter not work on github pages

I built an app with vite react router. I pushed it to github pages and got some error. I read about github pages doesn’t support browserrouter, so I changed it to hashrouter, but still not working. This is the code for it.

import React from 'react';
import { HashRouter as HashRouter, Routes, Route } from 'react-router-dom';
import HomePage from './pages/HomePage';
import HeroesPage from './pages/HeroesPage';

export default function App() {
  return (
    <HashRouter>
      <Routes>
        <Route path="/" element={<HomePage />} />
        <Route path="/HeroesPage" element={<HeroesPage />} />
      </Routes>
    </HashRouter>
  );
}

Maybe I made mistakes when use hashrouter. I dont know where I should start search for the mistake. Is there any issue with the way I imported and implemented hashrouter or the path?

React JS Component Keeps Re-rendering

The issue is that it appears that the entire adminControlPannel keeps getting called or something. The menu at the top of the screen keeps redoing its animation and if im looking at the drop down menu it is also refreshing. It doesnt look like the whole web page is refreshing but the component is.

https://gist.github.com/LunarSamurai/74ea58ce27ee9d786abf55c179e75ee5.js

I have spent a few days now, attempting to figure this out. So there is the entire source code for that one webpage (function) this is ReactJS. Here is the Admin Webpage that is being called as well:

https://gist.github.com/LunarSamurai/d4932bbed2c260a7c2eaa7fae52cc4a8