Angular JS Uncaught Error: [$injector:modulerr] when running app

I have a project written in angular version 1.8.1 that upon serving the project doesn’t run… the terminal shows no build errors but the console in the browser shows this:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.8.1/$injector/modulerr?p0=myApp&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.8.1%2F%24injector%2Fmodulerr%3Fp0%3DngFileSaver%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.8.1%252F%2524injector%252Fnomod%253Fp0%253DngFileSaver%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjs%252Fscripts.js%253Fv%253D1.3.3%253A741%253A168%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjs%252Fscripts.js%253Fv%253D1.3.3%253A760%253A503%250A%2520%2520%2520%2520at%2520b%2520(http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjs%252Fscripts.js%253Fv%253D1.3.3%253A760%253A25)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjs%252Fscripts.js%253Fv%253D1.3.3%253A760%253A277%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjs%252Fscripts.js%253Fv%253D1.3.3%253A777%253A201%250A%2520%2520%2520%2520at%2520r%2520(http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjs%252Fscripts.js%253Fv%253D1.3.3%253A742%253A76)%250A%2520%2520%2520%2520at%2520g%2520(http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjs%252Fscripts.js%253Fv%253D1.3.3%253A777%253A49)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjs%252Fscripts.js%253Fv%253D1.3.3%253A777%253A233%250A%2520%2520%2520%2520at%2520r%2520(http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjs%252Fscripts.js%253Fv%253D1.3.3%253A742%253A76)%250A%2520%2520%2520%2520at%2520g%2520(http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjs%252Fscripts.js%253Fv%253D1.3.3%253A777%253A49)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjs%2Fscripts.js%3Fv%3D1.3.3%3A741%3A168%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjs%2Fscripts.js%3Fv%3D1.3.3%3A777%3A491%0A%20%20%20%20at%20r%20(http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjs%2Fscripts.js%3Fv%3D1.3.3%3A742%3A76)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjs%2Fscripts.js%3Fv%3D1.3.3%3A777%3A49)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjs%2Fscripts.js%3Fv%3D1.3.3%3A777%3A233%0A%20%20%20%20at%20r%20(http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjs%2Fscripts.js%3Fv%3D1.3.3%3A742%3A76)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjs%2Fscripts.js%3Fv%3D1.3.3%3A777%3A49)%0A%20%20%20%20at%20fb%20(http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjs%2Fscripts.js%3Fv%3D1.3.3%3A781%3A153)%0A%20%20%20%20at%20c%20(http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjs%2Fscripts.js%3Fv%3D1.3.3%3A756%3A57)%0A%20%20%20%20at%20Wc%20(http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjs%2Fscripts.js%3Fv%3D1.3.3%3A756%3A370)
    at scripts.js?v=1.3.3:741:168
    at scripts.js?v=1.3.3:777:491
    at r (scripts.js?v=1.3.3:742:76)
    at g (scripts.js?v=1.3.3:777:49)
    at fb (scripts.js?v=1.3.3:781:153)
    at c (scripts.js?v=1.3.3:756:57)
    at Wc (scripts.js?v=1.3.3:756:370)
    at Ee (scripts.js?v=1.3.3:755:45)
    at HTMLDocument.<anonymous> (scripts.js?v=1.3.3:1085:117)
    at e (scripts.js?v=1.3.3:2:30005)

I have searched some docs and on some webpage found this:

A common reason why the module fails to load is that you’ve forgotten
to include the file with the defined module or that the file couldn’t
be loaded.

But I don’t know what module is missing or what I could forget to include…

Refactor React Radio buttons and Dynamic Input fields

I have 3 radio buttons that need to dynamically show and remove an input field when the radio button is true for that group

I am looking for another set of eyes to help me refactor this code. I feel like there is better way to clean this up or utilize better logic to remain DRY without bugging up the state or turning this into an uncontrolled component. The code works and the repo is here https://github.com/GregPetropoulos/Naval-Letter-Generator

import { Fragment, useState } from 'react';

const Radios = () => {
  const [viaIsChecked, setViaIsChecked] = useState(false);
  const [refIsChecked, setRefIsChecked] = useState(false);
  const [encIsChecked, setEncIsChecked] = useState(false);

  const [addViaInput, setAddViaInput] = useState([]);
  const [addRefInput, setAddRefInput] = useState([]);
  const [addEncInput, setAddEncInput] = useState([]);

  // If the VIA radio button is checked Yes, show the first input field and add button
  // If an additional VIA field is added show the remove button
  // * HANDLING THE RADIO CLICK AND SETTING THE INTIAL STATE
  const viaOnChange = () => {
    setViaIsChecked(!viaIsChecked);
    setAddViaInput([{ via: '' }]);
  };
  const refOnChange = () => {
    setRefIsChecked(!refIsChecked);
    setAddRefInput([{ references: '' }]);
  };

  const encOnChange = () => {
    setEncIsChecked(!encIsChecked);
    setAddEncInput([{ enclosures: '' }]);
  };

  // * HANDLING THE ADDITION OF HTML INPUT ELEMENTS
  const addViaInputTag = () => {
    setAddViaInput((prev) => [...prev, { via: '' }]);
  };
  const addRefInputTag = () => {
    setAddRefInput((prev) => [...prev, { references: '' }]);
  };
  const addEncInputTag = () => {
    setAddEncInput((prev) => [...prev, { enclosures: '' }]);
  };

  // * HANDLING THE REMOVAL OF HTML INPUT ELEMENTS
  // Two ways to remove an item either by clicking remove button or click the button radio "No"
  const removeViaInputTag = (e, index) => {
    const inputs = [...addViaInput];
    const arrItemRemoved = inputs.filter((item, idx) => idx !== index);
    setAddViaInput(arrItemRemoved);
  };

  const removeRefInputTag = (e, index) => {
    const inputs = [...addRefInput];
    const arrItemRemoved = inputs.filter((item, idx) => idx !== index);
    setAddRefInput(arrItemRemoved);
  };
  const removeEncInputTag = (e, index) => {
    const inputs = [...addEncInput];
    const arrItemRemoved = inputs.filter((item, idx) => idx !== index);
    setAddEncInput(arrItemRemoved);
  };

  // * HADLING THE ONCHANGES FOR TEXT INPUTS SEPERATELY
  const handleViaTextInput = (e, index) => {
    const textViaInputs = [...addViaInput];
    // destructure
    const { name, value } = e.target;
    // access the index and name ex: at 0 index the value of via is ''
    // due to destrcuture we have access to name, value
    textViaInputs[index][name] = value;
    setAddViaInput(textViaInputs);
  };

  const handleRefTextInput = (e, index) => {
    const textRefInputs = [...addRefInput];
    const { name, value } = e.target;
    textRefInputs[index][name] = value;
    setAddRefInput(textRefInputs);
  };

  const handleEncTextInput = (e, index) => {
    const textEncInputs = [...addEncInput];
    const { name, value } = e.target;
    textEncInputs[index][name] = value;
    setAddEncInput(textEncInputs);
  };

  return (
    <Fragment>
      <label className='sm:text-xl mt-7'> Optional Items</label>
      
      {/****--------------1st RADIO BUTTON AND FIELDS-----------------****/}
      <div className='form-control block items-center text-xs my-1 sm:text-lg'>

        <label className='mb-2 mr-2'> Do you have a VIA?</label>
        <input
          type='radio'
          name='radio-1'
          id='radio-1'
          value='1'
          checked={viaIsChecked === true}
          onChange={viaOnChange}
          className='radio radio-primary mx-2 radio-xs checked:bg-blue-500 sm:radio-lg sm:m-0'
        />{' '}
        Yes
        <input
          type='radio'
          name='radio-1'
          id='radio-1'
          value='1'
          checked={viaIsChecked === false}
          onChange={viaOnChange}
          className='radio  mx-2 radio-xs radio-primary checked:bg-red-500 sm:radio-lg'
        />
        No
      </div>
      {viaIsChecked
        ? addViaInput.map((item, index) => (
            <div key={index}>
              <input
                name='via'
                id='via'
                value={item.via}
                onChange={(e) => handleViaTextInput(e, index)}
                type='text'
                className='block w-full text-black text-[8px] my-3 rounded-md py-2 pl-1 pr-2 shadow-sm focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-base sm:pl-9 sm:pr-3'
                placeholder='Enter The Via (Title, name of activity (Code), location when needed'
              />

              {/* Add button appears on last input field added */}
              {addViaInput.length - 1 === index && addViaInput.length < 3 && (
                <button
                  type='button'
                  className='btn mr-4 btn-sm sm:btn'
                  onClick={addViaInputTag}>
                  Add VIA
                </button>
              )}

              {addViaInput.length > 1 && (
                <button
                  type='button'
                  className='btn btn-sm sm:btn'
                  onClick={(e) => removeViaInputTag(e, index)}>
                  Remove VIA
                </button>
              )}
            </div>
          ))
        : null}

      {/****--------------2nd RADIO BUTTON AND FIELDS-----------------****/}
      <div className='form-control block items-center text-xs my-1 sm:text-lg'>
        <label className='mb-2 mr-2'> Do you have References</label>
        <input
          type='radio'
          name='radio-2'
          id='radio-2'
          value='2'
          checked={refIsChecked === true}
          onChange={refOnChange}
          className='radio radio-primary mx-2 radio-xs checked:bg-blue-500 sm:radio-lg sm:m-0'
        />{' '}
        Yes
        <input
          type='radio'
          name='radio-2'
          id='radio-2'
          value='2'
          checked={refIsChecked === false}
          onChange={refOnChange}
          className='radio  mx-2 radio-xs radio-primary checked:bg-red-500 sm:radio-lg'
        />
        No
      </div>
      {refIsChecked
        ? addRefInput.map((item, index) => (
            <div key={index}>
              <input
                name='references'
                id='references'
                value={item.references}
                onChange={(e) => handleRefTextInput(e, index)}
                type='text'
                className='block w-full text-black text-[8px] my-3 rounded-md py-2 pl-1 pr-2 shadow-sm focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-base sm:pl-9 sm:pr-3'
                placeholder='Enter The Via (Title, name of activity (Code), location when needed'
              />

              {/* Add button appears on last input field added */}
              {addRefInput.length - 1 === index && addRefInput.length < 3 && (
                <button
                  type='button'
                  className='btn mr-4 btn-sm sm:btn'
                  onClick={addRefInputTag}>
                  Add Ref
                </button>
              )}

              {addRefInput.length > 1 && (
                <button
                  type='button'
                  className='btn btn-sm sm:btn'
                  onClick={(e) => removeRefInputTag(e, index)}>
                  Remove Ref
                </button>
              )}
            </div>
          ))
        : null}
      {/****--------------3nd RADIO BUTTON AND FIELDS-----------------****/}
      <div className='form-control block items-center text-xs my-1 sm:text-lg'>
        <label className='mb-2 mr-2'> Do you have Enclosures</label>
        <input
          type='radio'
          name='radio-3'
          id='radio-3'
          value='3'
          checked={encIsChecked === true}
          onChange={encOnChange}
          className='radio radio-primary mx-2 radio-xs checked:bg-blue-500 sm:radio-lg sm:m-0'
        />{' '}
        Yes
        <input
          type='radio'
          name='radio-3'
          id='radio-3'
          value='3'
          checked={encIsChecked === false}
          onChange={encOnChange}
          className='radio  mx-2 radio-xs radio-primary checked:bg-red-500 sm:radio-lg'
        />
        No
      </div>
      {encIsChecked
        ? addEncInput.map((item, index) => (
            <div key={index}>
              <input
                name='enclosures'
                id='enclosures'
                value={item.enclosures}
                onChange={(e) => handleEncTextInput(e, index)}
                type='text'
                className='block w-full text-black text-[8px] my-3 rounded-md py-2 pl-1 pr-2 shadow-sm focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-base sm:pl-9 sm:pr-3'
                placeholder='Enter The Via (Title, name of activity (Code), location when needed'
              />

              {/* Add button appears on last input field added */}
              {addEncInput.length - 1 === index && addEncInput.length < 3 && (
                <button
                  type='button'
                  className='btn mr-4 btn-sm sm:btn'
                  onClick={addEncInputTag}>
                  Add Encl
                </button>
              )}

              {addEncInput.length > 1 && (
                <button
                  type='button'
                  className='btn btn-sm sm:btn'
                  onClick={(e) => removeEncInputTag(e, index)}>
                  Remove Encl
                </button>
              )}
            </div>
          ))
        : null}
    </Fragment>
  );
};

export default Radios;

UI of Radio buttons

Can’t select dropdown items in react-native-autocomplete-dropdown

I am having an issue with react-native-autocomplete-dropdown. I can’t select any items from the dropdown list. My code and screenshot of the dropdown is given below.

<View style={{flex: 0.97, flexDirection: 'column', marginLeft: 10}}>
        <View style={{flexDirection: 'row'}}>
          <Text
            style={{
              fontFamily: 'Titillium-Semibold',
              color: Colors.grey_888888,
              fontSize: 14,
            }}>
            Dropdown Items
          </Text>
          <Text
            style={{
              fontFamily: 'Titillium-Semibold',
              color: Colors.grey_888888,
              fontSize: 14,
            }}>
            *
          </Text>
        </View>
        <AutocompleteDropdown
          clearOnFocus={false}
          closeOnBlur={true}
          closeOnSubmit={false}
          onSelectItem={item => {
            item && setCustomerID(item.id);
          }}
          dataSet={[
            {id: '1', title: 'Alpha'},
            {id: '2', title: 'Beta'},
            {id: '3', title: 'Gamma'},
          ]}
          renderItem={(item, text) => (
            <Text style={{color: Colors.black, padding: 15}}>
              {item.title}
            </Text>
          )}
          inputContainerStyle={styles.dropdown}
        />
      </View>

screenshot

I think I am missing something here. Any suggestion would be well appreciated.

What is causing my Canvas element to overflow and what can I do to fix it?

I have a problem with sizing my canvas element properly. The result as seen below is a canvas element (green outline) that extends it’s height outside of it’s parent div. What is causing this problem and what can I do to fix it?

resulting

HTML: Here is the HTML code, there isn’t much to it.

<div id="container">
    <div id="content">
        <div id="menu">
            ...
        </div>
        <div id="canvas-container">
            <canvas>
    
            </canvas>
        </div>
    </div>
</div>

SCSS: The more interesting SCSS code.

* {
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    font-size: 16px;
    font-family: 'Inter', sans-serif,
}

#container {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;

    #content {
        outline: 2px solid rgb(0, 0, 0);
        width: 80%;
        height: 80%;

        #menu {
            padding: 1em;
            border-bottom: 2px solid black;

            select {
                padding: 1em;
            }

            a {
                background-color: rgb(91, 134, 195);
                text-decoration: none;
                font-weight: bold;
                padding: 0.8em;
                color: white;
            }

            a:hover {
                background-color: rgb(75, 122, 189);
            }

        }

        #canvas-container {
            width: 100%;
            height: 100%;

            canvas {
                outline: 2px solid green;
            }
        }

    }

}

Javascript: And lastly the JS code that actually does the sizing of the Canvas element.

var canvas = document.querySelector('canvas');
fitToContainer(canvas);

function fitToContainer(canvas){
  // Make it visually fill the positioned parent
  canvas.style.width ='100%';
  canvas.style.height='100%';
  // ...then set the internal size to match
  canvas.width  = canvas.offsetWidth;
  canvas.height = canvas.offsetHeight;
}

Why is this component not showing on the page in quasar?

So in my quasar project I have installed the antfu plugins of vue components and auto import and have also installed vue router.

This is what my mainpage.vue looks like and it’s supposed to be showing on the page:

<script setup>
import { useProducts } from "src/stores/products.js";
const { getRandomProducts, productsSections } = useProducts();
</script>

<template>
<div class="mainpage">
<HeroSection />

<ProductsSection
  v-for="section in productsSections"
  :id="section.id"
  :key="section.id"
  :title="section.title"
  :items="getRandomProducts(section.itemCount)"
  :icon="section.icon"
  :offset="left"
  class="mainpage__products"
  />
 </div>
 </template>

When I run this it’s showing nothing on the page, however if I remove the productssection, the hero section is showing perfectly fine.

This is my productssection.vue:

 <script>
 defineProps({
 title: String,
 offset: Number | String,
 items: Array,
 icon: Object,
 });
 </script>

 <template>
 <section class="products-section">
 <div class="title-box row">
  <box-icon
    v-if="icon"
    class="icon"
    :name="icon.name"
    :type="icon.type || ''"
  />
  <h2>{{ title }}</h2>
 </div>
 <ProductGrid
  class="products-section__grid"
  :items="items"
  :style="{
    paddingLeft: `${offset}px`,
    paddingRight: `${offset}px`,
  }"
  />
  </section>
  </template>

This is ProductGrid.vue

<script setup>
 import useTouch from "src/composables/useTouch.js";
  defineProps({
  items: Array,
  });
  const { isTouchDevice } = useTouch();
  </script>

  <template>
   <div v-dragscroll="!isTouchDevice" class="product-grid">
    <ProductCard v-for="item in items" :key="item.id" :item="item" />
      </div>
  </template>

This is ProductCard.vue

<script setup>
defineProps({
item: Object,
});
</script>

<template>
<div class="product-card">
<RouterLink
  :to="{ name: 'ProductPage', params: { productId: item.id } }"
  class="product-card__link"
>
  <div class="product__image">
    <img :src="`/images/products/${item.imageUrl}`" alt="product image" />
  </div>
</RouterLink>
<div class="product-card__content">
  <div class="product">
    <div class="product__info">
      <h5 class="product__name">{{ item.name }}</h5>
      <p class="product__description">
        {{ item.description }}
      </p>
    </div>
  </div>
  <div class="product-card__bottom">
    <ProductPrice class="product__price" :price="item.price" />
    <div class="product__buttons">
      <button class="btn btn--primary">
        Add to cart
        <box-icon
          name="cart"
          type="solid"
          animation="tada"
          color="white"
        ></box-icon>
      </button>
      <button class="btn btn--secondary">
        Add to wishlist
        <box-icon name="bookmark-heart" color="white"></box-icon>
      </button>
    </div>
    </div>
   </div>
   </div>
   </template>

ProductInfo.vue

 <script setup>
 import { useCategories } from "src/stores/categories.js";
 const props = defineProps({
  item: Object,
 });
 const { getCategoryTags } = useCategories();
 const fullTags = getCategoryTags(props.item.tags);
 const { width } = useWindowSize();
 </script>

 <template>
 <div class="product-info">
 <div class="product-info--inner">
  <div class="product-info__content">
    <div class="product-info__categories">
      <CategoryTag
        v-for="tag in fullTags"
        :key="tag.id"
        :name="tag.label"
      />
    </div>
    <h2 class="product-info__title">
      {{ item.name }}
    </h2>
    <p class="product-info__description">
      {{ item.description }}
    </p>
    <div class="product-info__price-bar">
      <ProductPrice
        :price="item.price"
        size="lg"
        class="product-info__price"
      />
    </div>
   </div>
   <div class="product-info__buttons">
    <button class="btn btn--primary">
      {{ width > 600 ? "Add to cart" : "Add" }}
      <box-icon
        name="cart"
        type="solid"
        animation="tada"
        color="white"
      ></box-icon>
     </button>
     <button class="btn btn--secondary">
       {{ width > 600 ? "Add to wishlist" : "Add" }}
      <box-icon name="bookmark-heart" color="white"></box-icon>
     </button>
     </div>
     </div>
   </div>
  </template>

This is ProductPrice.vue

<script>
const props = defineProps({
 size: String,
price: Number | String,
});
</script>

<template>
<div class="product-price">
<span class="product-price--currency" :class="{ lg: props.size === 'lg' }">
  USD
</span>
<span class="product-price--amount" :class="{ lg: props.size === 'lg' }">
  {{ price }}
</span>
</div>
</template>

And this is CategoryTag.vue

<script setup>
defineProps({
name: String,
});
</script>

<template>
<div class="category">
<p>{{ name }}</p>
</div>
</template>

This is the composable useTouch.js

 export default () => {
 const isTouchDevice = computed(
  () =>
  "ontouchstart" in window ||
  navigator.maxTouchPoints > 0 ||
  navigator.msMaxTouchPoints > 0
   );

  return {
  isTouchDevice,
   };
   };

And this is my pinia store, products.js

import { defineStore } from "pinia";

import { sampleSize } from "lodash";

export const useProducts = defineStore("products", {
state() {
return {
  products: [
    {
      id: "0",
      name: "product name",
      description:
        "lorem ipsum",
      price: "82",
      imageUrl: "image.jpg",
      tags: [1, 3, 8],
    },

and then it’s just a bunch of these products

      ],
    productsSections: [
    {
      title: "Check out this month's selection.",
      icon: { name: "trending-up" },
      itemCount: 10,
      id: "offer-month",
    },
    {
      title: "On sale",
      icon: { name: "discount", type: "solid" },
      itemCount: 8,
      id: "offer-special",
     },
    ],
   };
   },
   getters: {},
  actions: {
   getProductById(id) {
  return this.products.find((product) => product.id === id) ?? null;
  },
   getRandomProducts(size) {
  return sampleSize(this.products, size);
   },
  getProductsByCategory(categoryId) {
  if (categoryId === 0) {
    return this.products;
  }
  return this.products.filter((product) =>
    product.tags.includes(categoryId)
  );
  },
 },
  });

and the categories.js

import { defineStore } from "pinia";

export const useCategories = defineStore("categories", {
state() {
return {
  categories: {
    all: [
      {
        label: "new",
        id: "new",
        tagId: 3,
      },
      {
        label: "used",
        id: "used",
        tagId: 3,
      },
      {
        label: "categ1",
        id: "categ1",
        tagId: 3,
      },
      {
        label: "categ2",
        id: "categ2",
        tagId: 4,
      },
      {
        label: "categ3",
        id: "categ3",
        tagId: 5,
      },
      {
        label: "categ4",
        id: "categ4",
        tagId: 6,
      },
      {
        label: "categ5",
        id: "categ5",
        tagId: 7,
      },
      {
        label: "All",
        id: "all",
        tagId: 8,
      },
     ],
     },
     categoryTags: [
     { label: "new", id: 1 },
    { label: "used", id: 2 },
    { label: "categ1", id: 3 },
    { label: "categ2", id: 4 },
    { label: "categ3", id: 5 },
    { label: "categ4", id: 6 },
    { label: "categ5", id: 7 },
    { label: "all", id: 8 },
    ],
   };
   },
  getters: {
  allCategories() {
  const allCategories = [];
  Object.entries(this.categories).forEach(([_catName, categories]) => {
    allCategories.push(...categories);
  });
  return allCategories;
   },
    },
  actions: {
   getCategoryById(id) {
   return this.allCategories.find((category) => category.id === id) ?? null;
    },
   getCategoryTag(id) {
  return this.categoryTags.find((tag) => tag.id === id) ?? null;
  },
   getCategoryTags(ids) {
   return ids.map((id) => this.getCategoryTag(id)) ?? [];
  },
  },
  });

Why is this code not working?

Toggling the visibility of a component with an Input function in Angular

I have a component that accepts a callback function @Input() closeCallback: () => void;

and calls it in a close function like this :

  close() {
    this.closeCallback();
  }
<button class="close" (click)="close()">
        <img src="assets/img/share/icon_close_dark.svg" />
    </button>

So in the parent component I passed a function to it :

<ng-container  *ngIf="isPopupOpen">
<e2-fullscreen-popup
  [title]="'top promotions'"
  [closeCallback]="closePopup"
  >
...
</e2-fullscreen-popup>
</ng-container>
  closePopup() {
   
    this.isPopupOpen = false;
    console.log('this.isPopupOpen',this.isPopupOpen);
  }

so why I’m not able to remove the component when clicking on the button, even thou the logs themselves show that this.isPopupOpen is false?

JQuery: dinamically retrieve value from autoNumeric

I have a group of textbox on wich I configured an autoNumeric:

$("input[name$='something']").autoNumeric('init', {aSep: '.', aDec: ',', aSign: ' €', vMax: '99999999999.9999'});

When I post my form I want to reformat the values on the textbox:

function parseBeforeSubmit() {
    $("input[name$='something']").val(function(){
                                                    var myText = $(this)[0];
                                                    return myText.autoNumeric('get');
                                                });
}

obviously i cant get it working, what i’m seeing is that myText has a property called jQuery36000058939066319538821 wich contains autoNumeric, but it seems strange that I cant dinamically access che autoNumeric component and also it seems this autoNumeric component doesnt contains the unformatted numeric value.
Sure there’s something I’m missing or maybe I used the wrong approach?

Iterating API parameter in google app script

I’m trying to use this API to fetch data directly in my google spreadsheet, I’m using Google AppScript.

Below is my API

=ImportJSON("https://rest.yyy.com/v2/matches?date=2022-06-01(Date start - yyyy-mm-dd)_2022-07-02(Date end - yyyy-mm-dd)&per_page=2000&token=xxx-xxx-xxxx-xx&status=1,2,3,4 &paged=1")

There is a “Paged” value in the API parameter this parameter limits the output range.

How can I iterate the “paged” parameter so that I don’t have to change it manually? So that I could get all the data at once?

I’m doing this using Google App Script.

How to type this when using apply

How can I type the this argument when my function receives it?

import { generatePath } from 'react-router-dom';

type generatePathParamsType = Parameters<typeof generatePath>[1];

// Following type definition of 'this' is not working
const generatePathFactory = function (this: typeof ENV_DASHBOARD) {
  return function (args: generatePathParamsType = {}) {
    // 'this' implicitly has type 'any' because it does not have a type annotation.
    return generatePath(this.PATH, args);
  };
};

const ENV_DASHBOARD = {
  PATH: "/dashboard/:environmentId",
  generatePath: generatePathFactory.apply(this),
  TITLE: "Dashboard"
};

console.log(ENV_DASHBOARD.generatePath({ environmentId: "1" })); // '/dashboard/1'

Demo at codesandbox

ReactJS MaterialUI Modal not refreshing

i have a Modal:

enter image description here

with certain fields, if i open the dropdown and select one of the fields, it does change the state of the Object but doesnt render it in the UI (i reopen the dropdown with the selections so you can see whats behind):

enter image description here

the weird thing about it is, if i do it outside of the Modal, it does work, so it has anything todo with my Modal component?

Here is the BaseModal component:

declare interface IBaseModal {
    readonly sx: BaseModalStyle;
    readonly body?: React.ReactNode;
    readonly isOpen: boolean;
    readonly toggleModal: any;
}

const BaseModal: FC<IBaseModal> = ({sx, body, isOpen, toggleModal}: IBaseModal) => (
    <Modal open={isOpen} onClose={toggleModal}>
        <BaseModalView width={sx.width} height={sx.height}>
            {body}
        </BaseModalView>
    </Modal>
)

then i use it as follows in the view component:

<BaseModal
                sx={{width: 800, height: 600}}
                isOpen={isModalOpen}
                toggleModal={() => setModalOpen(isModalOpen)}
                body={modalBody}
            />
    const localizer = momentLocalizer(moment);
    const [events, setEvents] = useState<CalendarEvent[]>([])
    const [schedule, setSchedule] = useState<ISchedule>(initialScheduleEvent);
    const [isModalOpen, setModalOpen] = useState<boolean>(false);
    const [modalBody, setModalBody] = useState<React.ReactNode | undefined>();

    const handleSelectDate = (e: SlotInfo) => {
        setModalBody(<Grid container>
            <Grid item xs={6}>
                <Grid container direction="row" sx={{padding: 2}}>
                    <Grid item xs={12} sx={{marginBottom: 2}}>
                        <Typography variant="h5" align='center'>
                            Schedule your Post
                        </Typography>
                    </Grid>
                    <Grid item xs={12} sx={{marginBottom: 2}}>
                        <Divider/>
                    </Grid>
                    <Grid item xs={12} paddingBottom={3}>
                        <TextField
                            style={{marginBottom: 20}}
                            fullWidth
                            select
                            variant="outlined"
                            label="Plattform"
                            value={schedule.platform}
                            onChange={e => setSchedule(prevState => ({...prevState, platform: e.target.value}))}
                        >
                            {availableSocialMedias.map(item => (
                                <MenuItem key={item.socialMedia} value={item.socialMedia}>{item.socialMedia}</MenuItem>
                            ))}
                        </TextField>

                        <LocalizationProvider dateAdapter={AdapterDateFns}>
                            <DateTimePicker
                                renderInput={(props) => <TextField {...props} />}
                                label="Schedule Date and Time"
                                value={schedule.schedule.start}
                                onChange={(e) => {
                                    setSchedule(prevState =>  ({...prevState, schedule: {
                                            ...prevState.schedule, start: e!
                                        }}))
                                }}
                            />
                        </LocalizationProvider>
                        <TextField
                            fullWidth
                            margin="dense"
                            multiline
                            rows="5"
                            variant="outlined"
                            label="Post Content"
                            id="additional-info"
                            value={schedule.schedule.desc}
                            onChange={(e) => {
                                setSchedule(prevState =>  ({...prevState, schedule: {
                                        ...prevState.schedule, desc: e.target.value
                                    }}))
                            }}
                        />
                    </Grid>
                    <Grid item xs={12} sx={{width: '100%'}}>
                        <Stack spacing={2} direction="row" justifyContent='center'>
                            <Button variant='contained' onClick={() => createEvent()}>Post</Button>
                            <Button variant='contained' onClick={() => handleCloseModal()}>Close</Button>
                        </Stack>
                    </Grid>
                </Grid>
            </Grid>
            <Grid item xs={6} sx={{backgroundColor: '#F7706EFF', justifyContent: 'center'}}>
                <img style={{height: 250, width: 400}}
                     src={"https://web-static.wrike.com/blog/content/uploads/2020/01/Five-Features-of-a-Good-Monthly-Employee-Work-Schedule-Template.jpg?av=718acbc1e2b21264368f12b5cc57c0e2"}/>
                <img style={{height: 250, width: 400}}
                     src={"https://imageio.forbes.com/specials-images/imageserve/605e039657de8844e59d9140/Businesswoman-Planning-Schedule-Using-Calendar-And-Laptop/0x0.jpg?format=jpg&crop=922,615,x0,y0,safe&width=960"}/>
                <Typography align='center' variant='h6'>
                    Schedule for the whole week!
                </Typography>
            </Grid>
        </Grid>)

        setModalOpen(true);
    }

It also rerenders after i select a certain value in the dropdown for example. but the Modal does not update its value, and i dont get why… i hope for any help.

no-unsafe-optional-chaining does not work with “||” or condition

[no-unsafe-optional-chaining][1] is an amazing eslint rule, which help us identify why we are doing wrong with optional chaining..

I have one case where i need to perform a sort operation on id (in numbers) which could be in string type which make sense to throw error because the it could result in NaN if order is not a number

  const sortComparer = (a, b) => (+a?.order) - (+b?.order)

However, if i do handle no-unsafe-optional-chaining as follow it still throws error and does not work:

  sortComparer: (a, b) => (+a.order || 0) - (+b.order || 0),

The only way to make it work is like this:

  sortComparer: (a, b) => (a?.order ? +a.order : 0) - (b?.order ? +b.order : 0),

Does anyone know how to fix this in a better way to avoid this issue ?
[1]: https://eslint.org/docs/rules/no-unsafe-optional-chaining

I can’t find solution to this [closed]

You need to plan a road trip. You are traveling at an average speed of 40 miles an hour.
Given a distance in miles as input (the code to take input is already present), output to the console the time it will take you to cover it in minutes.

Sample Input:
150

Sample Output:
225

How to make an button to make a confirmation box to do a task in Jquery and HTML

In my HTML below button and <p>is used..

<button  class="btn btn-info" id ="btn">submit</button>
<p></p>

I have used Jquery to run my script whenever I click submit button as follows,

$(document).ready(function(){
        $("#btn").click(function(){
          $('#loading').show();
            $.ajax({
                type: 'POST',
                url: 'testme.php',
                success: function(data) {
                    //alert(data);
                    $("p").text(data);
                    $('#loading').hide();

                }
            });
   });
});

This works fine and I could see the loading screen until testme.php executes.

Now I need to make a confirmation box as below before executes…

enter image description here

Is some one clicks Yes I need to go ahead and run my testme.php if not I need to close the window box.

I have checked some examples in below site but could not find a method to combine it with my existing code. Can someone help me on this case?

https://www.jqueryscript.net/demo/Sliding-Confirm-Dialog-Plugin-with-jQuery-Bootstrap-Confirm/

Thanks in Advance!

JavaScript regex check random 6 digit number string

I have created one JavaScript variable which create random digit number string. I want to make unit testing where it will check in regex that random variable create 6 digit string. But I am not sure how to do that.

const randomNumberString= Math.floor(100000 + Math.random() * 900000)


console.log(randomNumberString)


// This is test I am trying but it does not work
expect(randomNumberString).toContain(randomNumberString.match(/^(ds*){6}$/g))