How to make a fake progressbar

I need to generate a progress bar like the one on this site: https://vturb.com.br. “Basically” it loads quickly in the first moments of the video and gradually slows down until the end of the video.

The closest I could come up with was this:

const myVideo = document.querySelector('video');
const progressBar = document.querySelector('.progress > div')

myVideo.ontimeupdate = ({
  target
}) => {
  const progress = Math.round(Math.atan(target.currentTime) / (Math.PI / 2) * 100 * 1000) / 1000;

  progressBar.style.width = progress + '%';

};
.video-wrapper {
  position: relative;
  width: fit-content;
}

.progress {
  position: absolute;
  width: 100%
}

.progress>div {
  background-color: red;
  height: 100%;
  transition: width ease-in-out .5s;
}
<div class="video-wrapper">
  <video autoplay muted src="https://edisciplinas.usp.br/pluginfile.php/5196097/mod_resource/content/1/Teste.mp4" type="video/mp4"></video>
  <div class="progress" style="height: 8px;">
    <div style="width: 0%"></div>
  </div>
</div>

How i can resolve this error on react native Expo

i trying to use react-native-router but i have the follower error on the web console when i triying to look the app on web

enter image description here

but in the celphone it works correctly.

i dont know what to do

i tryed to change de webpack config bit it doesnt work

const path = require('path');
const createExpoWebpackConfigAsync = require('@expo/webpack-config');

module.exports = async function(env, argv) {
    const config = await createExpoWebpackConfigAsync(env, argv);
    config.module.rules.push({
        test: /.js$/,
        loader: 'babel-loader',
        include: [
            path.join(__dirname, 'node_modules/react-router-native'),
        ]
    });
    
    return config;
    } ``

Toggle Class on Top Level Containing Division Using Data Attribute on Link

As the title of this thread suggests, I’m trying to toggle a class on a div using data attributes on the link.

I’ve added my basic html and js. I’ve gotten it to toggle the class, but I need it to toggle a different class depending on which link is hovered.

I’ve added my HTML and javascript below. If anyone can help me fill in the blanks, I would be extremely grateful.

    var switchData = $("[data-switch]");
    var breakoutClass = switchData.attr('data-switch');
    $('.js-breakout-switch').hover(function() {
        $(this).parents('.js-product-breakout').toggleClass('show-' + breakoutClass);
    });
<div class="product-breakout js-product-breakout">
    <section class="breakout-item">
        <p class="breakout-item-text"><a class="breakout-item-link color-white js-breakout-switch" data-switch="01" href="">View Part</a></p>
    </section>
    <section class="breakout-item">
        <p class="breakout-item-text"><a class="breakout-item-link color-white js-breakout-switch" data-switch="02" href="">View Part</a></p>
    </section>
    <section class="breakout-item">
        <p class="breakout-item-text"><a class="breakout-item-link color-white js-breakout-switch" data-switch="03" href="">View Part</a></p>
    </section>
</div>

what is mean by prefilght request and how to stop that?

hi guys if anyone know this , please help me , i have login form which has this funtion , and also i have a backend server running on different port , which send the jwt token to the front end , but what the issue is when i click the button in frontend , i make preflight request , thats why i cannot able to access the token in frond end ,

[enter image description here]enter image description here

I just want to access the jwt token which send from the server, and also why please expalin why this preflight request was made every time i click the button , is there way to avoid these req

Compile vNode inside a function and have it appended to regular dom with vue3

This example is importing vue via a cdn link in a shopify site. The typical way of using vue like this is to create a vue app for a certain part of the page, so the below example assumes we are on a product page. What I am struggling with is that inside a certain function, for example openModal, we might want some vue code inside the function but this code will not be compiled.

For example:

<div id="main">
  <div class="header"></div>

  <!-- Mount the vue app here -->
  <div class="product-wrapper">
    <button @click="openModal">open modal</button>
  </div>

  <div class="footer"></div>
</div>

<script type="module">
const { createApp } = Vue

const product_app = Vue.createApp({
  compilerOptions: {
    delimiters: ['{', '}']
  },
  data() {
    return {
      sizeOptions: ['xs', 's', 'm']
    }
  },
  methods: {
    openModal() {
      // append modal to the DOM
      // ...

      const modal_inner = document.querySelector('.modal-inner')

      // vue template code
      // this of course will not be compiled by vue
      const modal_content = `
        <div v-for="size in sizeOptions"
          class="sizeSwatch"
        >{ sizeOption }</div>
      `;

      modal_inner.insertAdjacentHTML('beforeend', modal_content)
    }
  }
})

product_app.mount(document.querySelector('.product-wrapper'))
</script>

Since this is not in a vue app, and there is no build step, the above example is usually solved like this – wherein the vue template code we need for later is rendered in the app in a wrapper div with the display set to none, later we just clone it.

<div id="main">
  <div class="header"></div>

  <!-- Mount the vue app here -->
  <div class="product-wrapper">
    <button @click="openModal">open modal</button>

    <div class="hidden">
      <div v-for="size in sizeOptions" 
        class="sizeSwatch"
      >{ sizeOption }</div>
    </div>
  </div>

  <div class="footer"></div>
</div>

My idea was to do something like this but I don’t know how to do this and that is what this question is about, if the below example can be made to work.

<div id="main">
  <div class="header"></div>

  <!-- Mount the vue app here -->
  <div class="product-wrapper">
    <button @click="openModal">open modal</button>
  </div>

  <div class="footer"></div>
</div>

<script type="module">
const { createApp } = Vue

const product_app = Vue.createApp({
  compilerOptions: {
    delimiters: ['{', '}']
  },
  data() {
    return {
      sizeOptions: ['xs', 's', 'm']
    }
  },
  methods: {
    openModal() {
      // append modal to the DOM
      // ...

      const modal_inner = document.querySelector('.modal-inner')

      const modal_content = h(
        'div',
        this.sizeOptions.map(sizeOption) => {
          return h('div', sizeOption)
        })
      )

      // somehow append the vnode to the modal
    }
  }
})

product_app.mount(document.querySelector('.product-wrapper'))
</script>

How do I edit values on multiple rows and columns on a table with vue.js

I have this component to show database values of stock information from an API along with other information that are not from the API. I want to be able to update the columns that are not from the API for every stock. And I want to be able to update multiple records with a single update action, not one by one.

This is my code:

<template>
  <jet-form-section @submitted="updateEquitySecurities">
    <template #title> Equity Securities </template>

    <template #description> Update Equity Security Information. </template>

    <template #form>
      <div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
        <div
          class="p-6 rounded sm:rounded-lg overflow-x-auto border border-gray-100 dark:border-gray-200 dark:rounded"
        >
          <table class="w-full whitespace-nowrap">
            <thead>
              <tr class="text-left font-bold text-white">
                <th class="bg-blue-500 border-4 p-2 rounded">Name</th>
                <th class="bg-blue-500 border-4 p-2 rounded">Weight</th>
                <th class="bg-blue-500 border-4 p-2 rounded">Tracking Status</th>
                <th class="bg-blue-500 border-4 p-2 rounded">Security Rating</th>
                <th class="bg-blue-500 border-4 p-2 rounded">Target Entry Price</th>
                <th class="bg-blue-500 border-4 p-2 rounded">Target Exit Price</th>
              </tr>
            </thead>
            <tbody>
              <tr
              v-for="equitySecurity in equitySecurities"
              :key="equitySecurity.id"
              class="dark:bg-gray-700 text-gray-700 dark:text-gray-200 hover:bg-blue-200 dark:hover:bg-blue-300 focus-within:bg-blue-100"
            >
              <input
                type="hidden" v-model="form.equitySecurities.id"
              />
              <td class="border-2 p-2">
                {{ equitySecurity.name }}
              </td>
              <td class="border-2 p-2">
                <input
                  type="text" v-model="form.equitySecurities.weight"
                />
              </td>
              <td class="border-2 p-2">
                <input
                  type="text" v-model="form.equitySecurities.tracking_status"
                />
              </td>
              <td class="border-2 p-2">
                <input
                  type="text" v-model="form.equitySecurities.security_rating"
                />
              </td>
              <td class="border-2 p-2">
                <input
                  type="text" v-model="form.equitySecurities.target_entry_price"
                />
              </td>
              <td class="border-2 p-2">
                <input
                  type="text" v-model="form.equitySecurities.target_exit_price"
                />
              </td>
            </tr>
            <tr v-if="equitySecurities.length === 0">
              <td class="border-2 p-2" colspan="4">No Equity Security found.</td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </template>

    <template #actions>
      <jet-action-message :on="form.recentlySuccessful" class="mr-3">
        Updated.
      </jet-action-message>

      <jet-button :class="{ 'opacity-25': form.processing }" :disabled="form.processing">
        Update
      </jet-button>
    </template>
  </jet-form-section>
</template>

<script setup>
import JetButton from "@/Jetstream/Button.vue"
import JetFormSection from "@/Jetstream/FormSection.vue"
import JetActionMessage from "@/Jetstream/ActionMessage.vue"
import { useForm } from "@inertiajs/vue3"

const prop = defineProps({ equitySecurities: Object })

const form = useForm({
  equitySecurities: prop.equitySecurities.map((equitySecurity) => ({
    id: equitySecurity.id,
    name: equitySecurity.name,
    weight: equitySecurity.weight,
    tracking_status: equitySecurity.tracking_status,
    security_rating: equitySecurity.security_rating,
    target_entry_price: equitySecurity.target_entry_price,
    target_exit_price: equitySecurity.target_exit_price
  }))
});

const updateEquitySecurities = () => {
  form.put(route("securities.update-equity-nse"), {
    preserveScroll: true,
    errorBag: "updateEquitySecurities"
  })
}
</script>

I struggling to get the reactivity to work properly.

Problem I’m facing: (see screenshots)

  1. I expect values from the database (where available) to show in the input box, but it doesn’t (I can see a few values I seeded for testing in dev console),
  2. When I type in one row, it shows up on all rows,
  3. Despite (2), nothing gets sent to the backend when dump the request,
  4. When I modify a value in dev console, it doesn’t show up in form but the value gets sent to the backend.

Input shows up in all rows

Backend values not showing when available

Changes in dev console is reactive

I suspect my reactivity implementation is the culprit and I need help to sort this.

Regex for E164 format for numbers for all countries

I am wrting a regex to validate telephone numbers for e164 format . My requirement is after country code there should be space mandatory after then the number like

+91 1111111111 — > validate true
+911111111111 — > validate false.

Like this validate for all countries in general . I have written the below regex

 function validatePhoneForE164(phoneNumber) {
        const regEx = /^+?[1-9]sd{1,14}$/;
        return regEx.test(phoneNumber);
    };

console.log(validatePhoneForE164(‘+91 1111111111’))

this is working for US +1 1111111111 , but not working for others

 function validatePhoneForE164(phoneNumber) {
        const regEx = /^+?[1-9]sd{1,14}$/;
        return regEx.test(phoneNumber);
    };

console.log(validatePhoneForE164(‘+91 1111111111’))

this is working for US +1 1111111111 , but not working for others

Appending symbol code to HTML from a JS function

I am trying to append a html symbol code – ☀ which is a sun to an html span.innerHTML using a js function but what I get in is

<span class="condition symbol">&amp;#x2600;</span>

And in this way it shows ☀ instead of the sun symbol.

I tried using “, ”,”” while appending the symbol’s code but same.

const htmlElement=document.createElement('span');
... //adding the classes
htmlElement.textContent='&#x2600;';

Export every item from array as separate variable

I’m generating storybook documentation for react component. I already have a file with all versions of the prop for it.

Componet.stories.ts:

const stories: Story[] = data.map(
  (data, index) =>
    ({
      name: `Version ${index}`,
      args: {
        ...data
      }
    })
);


export const story0 = stories[0];
export const story1 = stories[1];
export const story2 = stories[2];
export const story3 = stories[3];
//...

I want to export each item from an array as a separate variable in a loop. Is it even possible?

Axios PUT not working to update record in React form with Typescript

I have a React formt that I am attempting to use to update a record. My back-end team had supplied me with an API that I have see work to create a record using Postman, but when I try to use and Axios PUT, I first get the error:

PUT http:// … /updateRecord/undefined

react_devtools_backend.js:2655 Unhandled Promise rejection: Request failed with status code 400 ; Zone: ; Task: Promise.then ; Value: AxiosError {message: ‘Request failed with status code 400’, name: ‘AxiosError’, code: ‘ERR_BAD_REQUEST’, config: {…}, request: XMLHttpRequest, …} undefined

then this 409 error:

PUT http:// … /updateRecord/(item id)

react_devtools_backend.js:2655 Unhandled Promise rejection: Request failed with status code 409 ; Zone: ; Task: Promise.then ; Value: AxiosError {message: ‘Request failed with status code 409’, name: ‘AxiosError’, code: ‘ERR_BAD_REQUEST’, config: {…}, request: XMLHttpRequest, …} undefined

I don’t know why the update isn’t working. I am also having a similar issue creating a record with a POST request, but I do not get any console errors and the record does not get create. I assume whatever I have wrong on this form is happening on that form as well. My form validation it working just fine, but I included it here for reference.

Right now I have a very basic Axios PUT written, but eventually want to add error handling and the ability to display a confirmation message.

DepartmentEdit.tsx

export function DepartmentEdit(props) {
    const { closeModal, refreshTable, selectedRecord,  ltUpdateUrl } = props;

    const validate = (fieldValues = values) => {   // these will need to be customized to required fields per table
        const temp = { ...errors };
        if ('name' in fieldValues)
            { temp.name = fieldValues.name ? '' : 'Department Name is required.'; }
        if ('description' in fieldValues)
            { temp.description = fieldValues.description ? '' : 'Description is required.'; }
        setErrors({
            ...temp
        });
        if (fieldValues === values)
            { return Object.values(temp).every(x => x === ''); }
    };

    const {
        errors,
        setErrors,
        handleInputChange,
        values,
        setValues,
    } = FormFunctions(initialValues, true, validate);

    React.useEffect(() => {
        if (selectedRecord !== null)
            {setValues({
                ...selectedRecord
        }); }
    }, [selectedRecord, setValues]);

   const curValue = values.isArchived === 1 ? false : true; 


// PUT Request
   async function editRecord(values: any) {
        await axios.put(`${ltUpdateUrl + (values.id)}`, {
            title: 'Success',
            body: 'The record had been successfully updated'
        });
        refreshTable();
    }

    const handleSubmit = e => {
        e.preventDefault();
        if (validate()){
          editRecord(selectedRecord);
          closeModal();
        }
    };

    return (
      <Form onSubmit={handleSubmit} >
          <Grid container spacing={0}>
              <Grid item md={8}>
                  <Controls.Input
                      type='text'
                      onChange={handleInputChange}
                      label='Department Name'
                      name='name'
                      value={values.name !== null ? values.name : ''}
                      error={errors.name}
                  />
              </Grid>
              <Grid item md={4}>
                  <Controls.ToggleSwitch
                      label1='Inactive'
                      label2='Active'
                      curValue={curValue}
                      value={values.isArchived}
                  />
              </Grid>
              <Grid item md={12}>
                  <Controls.Input
                      type='text'
                      onChange={handleInputChange}
                      label='Description'
                      name='description'
                      value={values.description !== null ? values.description : ''}
                      error={errors.description}
                  />
              </Grid>
          </Grid>
          <Grid>
                 <Controls.Button
                      type='submit'
                      text='Submit'
                      onClick={editRecord}
                  />
                  <Controls.Button
                      text='Cancel'
                      color='default'
                      onClick={closeModal}
                  />
          </Grid>
      </Form>
    );
}

FormFunctions.tsx

export function FormFunctions(initialValues, validateOnChange = false, validate) {
    const [values, setValues] = React.useState({} as any);
    const [errors, setErrors] = React.useState({} as any);

    const handleInputChange = e => {
        const { name, value } = e.target;
        setValues({
            ...values,
            [name]: value
        });
        if (validateOnChange)
          { validate({ [name]: value }); }
    };

    const resetForm = () => {
      setValues(initialValues);
      setErrors({});
    };
    return {errors, handleInputChange, resetForm, setErrors, setValues, values};
}

export function Form(props) {
    const classes = useFormStyles();
    const { children, ...other } = props;
    return (
        <form className={classes.root} autoComplete='off' {...other}>
            {props.children}
        </form>
    );
}

Not sure if this is my issues, but the value I am being passed for isArchived is 1/0 rather than True/False (the backend team is working to change that). That is why I have the CurValue variable to display the value in the checkbox.

Does NPM run scripts called dependencies when running npm i?

Is npm i supposed to run run scripts called dependencies when npm i is run?

It does in my case in the lastest version of node (v19.8.1) and I’m wondering if this is a bug?

To reproduce try this:

mkdir test
cd test
npm init -y

And just make the package.json look like this:

{
  "name": "temp",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "dependencies": "cd app",
    "echo": "echo "$PWD""
  },  
  "main": "index.js",
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cpx": "^1.5.0",
    "node-pretty-log": "*"
  }
}

And try running npm i. The following should be the output:

npm i
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path /Users/oleersoy/Temp/temp
npm ERR! command failed
npm ERR! command sh -c cd app
npm ERR! sh: line 0: cd: app: No such file or directory

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/oleersoy/.npm/_logs/2023-04-17T18_50_22_257Z-debug-0.log
oleersoy@Oles-MacBook-Pro temp % npm i
npm ERR! code 1
npm ERR! path /Users/oleersoy/Temp/temp
npm ERR! command failed
npm ERR! command sh -c cd app
npm ERR! sh: line 0: cd: app: No such file or directory

We can see that it tried to cd app, and since the directory app does not exist the error was created when it tried to run the dependencies script.

index.html does not read main.js

I’am trying to build simple map app.
I wrote some lines of code and have problem that index file does not read main.js

Here is the index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebgisOL</title>
    <link rel="stylesheet" href="resources/ol/ol.css">
    <link rel="stylesheet" href="main.css">
</head>
<body>
    <div id="map"></div>
    <script src="resources/ol/ol.js"></script>
    <script src="main.js"></script>
</body>
</html>

and main.js:

var mapView = new ol.View ({
  center: ol.proj.fromLonLat([16.631927, 52.277821]),
  zoom: 8
});

var map = new ol.Map ({
  target: 'map',
  view: mapView
});

var osmTile = new ol.layer.Tile ({
  title: 'Open Street Map',
  visible: true,
  source: new ol.source.OSM()
});

map.addLayer(osmTile);

also simple main.css:

#map {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;`
}

Errors appears in devtools:
Uncaught SyntaxError: Cannot use import statement outside a main.js:1 module

api.maptiler.com/tiles/hillshade/9/304/664.webp?key=get_your_own_D6rA4zTHduk6KOKTXzGB:1
Failed to load resource: the server responded with a status of 400 ()

Would appreciate on any suggestions.

Would appreciate on any suggestions.