Is there a better way of handling folder structure in Express Handlebars with views

I’m wondering if there is a better way of rendering my html without having to always have my files named differently. If there’s any way handlebars can know I want this file in this folder to be rendered rather than searching everywhere and having same-name conflicts..Any help would be appreciated. Here’s an example of code. Thank you!

//Setting up configuration views here //
const hbs = exphbs.create({ helpers, defaultLayout: 'main', extname: '.handlebars' });
app.engine('handlebars', hbs.engine);


//Handlebar files must be named differently //
app.set('views', [
    path.join(__dirname, 'views/corporate'),
    path.join(__dirname, 'views/help-center'),
  ]);
  
app.set('view engine', 'handlebars');

And then my view folder is

enter image description here

And here is an example of one of my routes

const router = require("express").Router();
const config = require("../../lib/config");
const { appUrl } = config;


router.get("/", (req, res) => {
    res.render("corpIndex", {
      appUrl
    });
  });

  module.exports = router;

JavaScript React component takes dictionary creates the aside bar with the li and link using JSX

I’m learning react and creating a blog along the way and on my articles I want to create a component that would take in a prop dictionary and the key would be the link the user can see and click on and the value would be the link for my routing. Thanks for any help.

import React from 'react'
import styled from 'styled-components'
import { Link } from 'react-router-dom'


function AsideBar(props) {
    return (
        <Container>
            <Sidebar>
                <Nav>
                    {for (const property in props.link_short){
                        <Link='{props.link_short[property]}'><li>property</li></Link>
                    }}
                </Nav>
            </Sidebar>
        </Container>
    )
}

export default AsideBar

PKG Failed to make Bytecode

I am getting this warning when I try and run .. pkg index.js -t macOS

node v17.3.1
[email protected]

Warning Failed to make bytecode node17-arm64 for file /snapshot/______/index.js

was hoping anyone could help,

I have also tried to use -b and got

Error: ENOENT: no such file or directory, open ‘/var/folders/fy/c5tgsjcj63q73kfvg_dd53fh0000gn/T/pkg.d5ef9dd92b18360a4ff95824/node/out/Release/node

thank you

Loop iteration with time interval before passing value to included function

I’m trying to figure out how to set time out for function inside the loop iteration in Ionic TypeScript application.

setInterval makes equal time interval with calling the function in endless repetition:

   setInterval(() => {
      this.myFunc1(val);
   }, 800);

setTimeout gives required result if listed sequentially:

   setTimeout(() => {
      this.myFunc1(val);
   }, 800); 

   setTimeout(() => {
      this.myFunc1(val);
   }, 1200); 

but how to loop with time interval trough the updated list and wait while pass second value val to the function, or call myFunc1 when it will be finished in previous iteration:

 async myFunc2() {
    for (let val of this.myValueList) {
        /// wait for 5 sec or wait for finishing process, then pass value calling function:  
        this.myFunc1(val);          
    }
  }

Understanding Context & Array Types

Good Afternoon,

I am in the process of setting up my context for my application but running into an issue with the information display after the initial load. The initial application load then navigating to the products page everything displays correctly, but if I was to reload the page on Products screen the information is missing. If I was to reload the page on the Products screen, then click the navigation click to that same page the information will load correctly.

index.js

//Context
import UserContextProvider from "./components/context/UserContext";
import ProductsContextProvider from "./components/context/ProductsContext";
import CartContextProvider from "./components/context/CartContext";

ReactDOM.render(
  <BrowserRouter>
    <UserContextProvider>
      <ProductsContextProvider>
        <CartContextProvider>
          <App />
        </CartContextProvider>
      </ProductsContextProvider>
    </UserContextProvider>
  </BrowserRouter>,
  document.getElementById("root")
);

app.js

const App = () => {
  return (
    <div className="App">
      <Switch>
        <Route exact path="/" component={HomePageScreen} />
        <Route exact path="/shop/bands" component={BandsPageScreen} />
        <Route exact path="/shop/photo" component={InsertPageScreen} />
        <Route exact path="/shop/products" component={ProductScreen} />
     </Switch>
    </div>
  );
};

productContext.js

import React, { createContext, useState } from "react";
import axios from "axios";

export const ProductsContext = createContext();

const initialState = [];

const ProductsContextProvider = ({ children }) => {
  const GetProducts = async () => {
    await axios.get("/api/products/find/all").then((response) => {
      if (response.data.results) {
        for (var i = 0; i < response.data.results.length; i++) {
          initialState.push(response.data.results[i]);
        }
      }
    });
  };
  GetProducts();
  const [products] = useState(initialState);
  console.log("Setting Product Context");

  return (
    <ProductsContext.Provider value={{ products }}>
      {children}
    </ProductsContext.Provider>
  );
};

export default ProductsContextProvider;

productScreen.js

import { React, useContext, useState, useEffect } from "react";
import axios from "axios";
import HeaderBar from "./modules/header";
import { Button, Image, Icon, Card, Container } from "semantic-ui-react";
import Temp from "../../img/tempphoto.png";

//Context Files
import { UserContext } from "../context/UserContext";
import { ProductsContext } from "../context/ProductsContext";

const ProductScreen = () => {
  const activeScreen = "productScreen";
  const { products } = useContext(ProductsContext);

  console.log(products);

  const allProducts = products.map((product) => (
    <Card raised key={product.sku}>
      <Image src={Temp} wrapped ui={false}></Image>
      <Card.Content>
        <Card.Header>{product.title}</Card.Header>
        <Card.Meta>
          Sku: {product.sku} | Color: {product.color}
        </Card.Meta>
        <Card.Description> {product.description}</Card.Description>
      </Card.Content>
      <Card.Content extra>
        {/* <Button color="green" onClick={(e) => addItemCart(product._id, e)}>
          <Icon name="add to cart"></Icon>Add to Card
        </Button> */}
      </Card.Content>
    </Card>
  ));

  return (
    <>
      <HeaderBar screen={activeScreen} />
      <Container>
        <Card.Group>{allProducts}</Card.Group>
      </Container>
    </>
  );
};

export default ProductScreen;

  1. Reload Product Screen -> First Array after reload
  2. Click the Navigation Link -> Second Array after click (Everything loads correctly here).

enter image description here

Not sure what I am doing wrong but the information is being stored within the context from what I can see.

apply function from methods to reverse string in paragraph in vue.js

Dears, I have tried to apply function to reverse string in paragraph text in vue.js,
I have created function to reverse words in methods called (reverseword) and added it

card using :rule=”reverseword()”,but it does not work. your support is highly appreciated
Code:

    <div class="post-box">
        <span class="post-viwes">{{viwes}}</span>
        <h3 class="post-title">{{title}}</h3>       
         <span class="post-date">{{date}}</span>
        <p class="post-content">{{content}}</p>
        <div class="row">
            <div class = "col-sm-6 text-right">
              <span class="post-author">{{author}} </span>
            </div>
            <div class = "col-sm-6 text-right" :rules="reverseword()">
              <span class="post-category"  >{{category.toUpperCase()}}</span>
            </div>
        </div>
        )
    </div>
</template>
<script>
export default {
    props:["viwes","title","date","content","author","category"],
    name:"posts",
      methods: {
        reverseWord: function () {
          this.category = this.category.split('').reverse().join('')
    }   
}};
</script>```

Реализация статичных ссылок с функцией onclick [closed]

Как передать аргумент функцию onclick при статичном формировании?

function linkHref(link, name){
return (‘<a href=”#” type=”button” onclick=selectTheme(‘+ link + ‘)>’+ name + ”);
}

Источник: https://codereview.stackexchange.com/questions/176498/javascript-sidebar-menu-with-subitems-from-a-json-object

Cannot type in TextField inside Dialog modal

I am building a react app using mui, but I can’t get the inputs from my TextFields when they are inside a Modal. When I type they basically lose focus after one character. The example in the mui site only show how to manage a single TextField https://mui.com/components/dialogs/#form-dialogs . Is there a way to use more than one? My code:

<Dialog
                open={openCreateSheet}
                onClose={handleCloseCreateSheet}
                disableEnforceFocus
              >
                <DialogContent>
                  <CreateSheetBox>
                    <DialogContentText>
                      Fill in the blanks to generate a new work
                    </DialogContentText>
                    <TextField
                      label="Nome"
                      variant="outlined"
                      value={sheetName}
                      onChange={(e) => setSheetName(e.target.value)}
                    />
                    <TextField
                      label="Location"
                      variant="outlined"
                      value={sheetLocation}
                      onChange={(e) => setSheetLocation(e.target.value)}
                    />
                  </CreateSheetBox>
                </DialogContent>
                <DialogActions
                  sx={{
                    display: "flex",
                    justifyContent: "center",
                  }}
                >
                  <Button
                    variant="contained"
                    onClick={addSheet}
                    color={"secondary"}
                  >
                    Add Sheet
                  </Button>
                </DialogActions>
              </Dialog>```

Issue With stoping Autoclicker

On my website (https://autoclicker75.glitch.me/), I have a autoclicker I made, but I can’t figure out how to make it stop. I’ve tried using the break command, and the id command, but neither work. Could someone help me?
Here is the code: javascript:clicker:{const{Number}=self;const milliseconds=Number.parseInt(self.prompt('Time (Sec) untill click again?%20(I%20recommend%20setting%20it%20to%201)%27,%271%27));if(false===Number.isSafeInteger(milliseconds)){self.alert(%27Input%20was%20not%20an%20integer%27);break%20clicker;}let%20clientX=0,clientY=0;const{document}=self;self.setInterval(()=%3E{document.elementFromPoint(clientX,clientY)?.click?.();},milliseconds);document.addEventListener(%27mousemove%27,event=%3E{({clientX,clientY}=event);},{passive:true});}
I’m hoping to use another bookmarklet, with the id element, to stop the clicker, but I can’t get it to work.
Thanks!
-Piplup7575

Bootstrap works when imported by CDNS but not when imported by Node modules

Basically, I am trying to learn and test out bootstrap. I’ve noticed I can get it working by importing the files exactly as the template on their website shows for cdns. But when I install boostrap, poppper, and jquery through node, and import the exact same files. It doesnt work. I have attached two screenshots showing what I mean.
Bootstrap collapse working when I import using the CDNS

Bootstrap collapse not working when I import using the node modules

EDIT: here is my file system
files system

Lodash sortby first condition and then check for other conditions

I am using lodash to sort by value in a function. It is sorting by value at the moment. However, I would like to add another condition. I want to make it so that it sorts by this condition first(meaning a filed will be equal to something), then it will do the sorting by value.

In other words, there is one item that has the name of ‘Sally’. This item should be first, and then the rest of the items are sorted by value.

I have been doing many research on this and could not find anything online. Wondering if anyone has ever come across this issue. Please see my code:

const sortByNameThenValue = () => {
  let result;
  
  result = sortBy(name, 'Sally') && sortBy(allowance, 'value').reverse();
}

I was also thinking of chaining it but doesnt seem to work as well. Please let me know if you see something. Thanks and appreciate it!

How to apply a setFilter on javascript array with Mapbox

I have a map object with geojson data as source. each features is like :

{
    "id": "0",
    "type": "Feature",
    "properties": {
        "color": "#377eb8",
        "edge_id": 1,
        "speed_out": [
            50,
            48.18181818181818,
            46.36363636363636,
        ]
    },
    "geometry": {
        "type": "Polygon",
        "coordinates": [....]
    }
}

speed_out property is an array. Its the speed recorded at eah following hour: 6AM, 7AM and 8AM.

I would like to apply setFilter in speed_out to change my layer’s filter property whenever the input event fires (here the hour).

I try this without succes.

document.getElementById('slider').addEventListener('input', (event) => {
    const hour = parseInt(event.target.value);

   //update the map
   map.setFilter('lines', ['==', ['number', ['get', 'speed_out']], hour]);

Mocha.js – How to save a global variable?

I’m working with Mocha.js for testing in a Node.js – Express.js – Firebase

I need a token from Firebase to access the API endpoints, I have a before hook in all my files, but after about 250 tests, probably calling the authentication endpoint multiple times, I’m getting rate limited by firebase.

I want to get the token once and use it in all my tests.

The tests are spread in different files, I have an index.js that requires them all.
I’m aware of Root Level Hooks, but how can I save the token and use it in all my separate files?

Thanks!

Prevent initial page jump when showing an element based on cookie value

I have a page of static HTML which, on load and via jQuery, checks if a permanent cookie (“hideAnnouncements”) exists. If this cookie does NOT exist then it loads an external HTML file (containing a bullet list of announcements) into a div using jQuery’s load() method, and then executes a vertical carousel scroller on the bullet list. When the user selects to hide this div by clicking on an “x” icon, then it creates the “hideAnnouncements” cookie for subsequent visits.

The problem I’m having is that the page HTML is loaded first, and then there is a very obvious and annoying page jump when the announcements div is loaded into the very top of the page.

Without relying on server-side code (since the page is cached/static HTML), is there a better way to approach this that will avoid the page jump? Or do I just delay loading the entire page until I know if the cookie exists or not?