How to make text selection work when inside view and is inside TouchableWithoutFeedback in React Native in android

I have a situation where I have a post, post has content in it, when user clicks on post’s content on the home user should be redirected to another page and user is also able to select the text on the same Home Screen.

I have tried doing this

<TouchableWithoutFeedback
    accessibilityRole="text"
    onPress={navigateToSomeScreen}
    onLongPress={() => { return null}}
>
    <View
        accessibilityRole="text"
    >
        <Text
            style={[theming.theme.post_title_text]}
            selectable
        >
            enter code here
        </Text>
    </View>
</TouchableWithoutFeedback>

But still its not working. When long press on the text nothing happens. I works on iOS but it’s not working properly on android.

Any suggestions or any advices how can achieve it?

Google direction time with traffic

I use google maps for my website, i want to get directions during traffic, how can i get estimated time during traffic in google maps directions ?

i use the following code to get directions without traffic.

function direction(){
    var directionsService = new google.maps.DirectionsService();
    var directionsRenderer = new google.maps.DirectionsRenderer();


    var nmap = new google.maps.Map(document.getElementById('direction-map'), mapOptions);
    directionsRenderer.setMap(nmap);

    calcRoute();
}

function calcRoute() {

    var blng = parseFloat($("#beginning-lng").val());
    var blat = parseFloat($("#beginning-lat").val());

    var dlng = parseFloat($("#destination-lng").val());
    var dlat = parseFloat($("#destination-lat").val());

    var start = new google.maps.LatLng(blat, blng);
    var end = new google.maps.LatLng(dlat, dlng);
    var request = {
        origin: start,
        destination: end,
        travelMode: 'DRIVING',
        avoidTolls: true
    };
    directionsService.route(request,  function (result, status) {
        if (status == 'OK') {
            directionsRenderer.setDirections(result);
            console.log(result);
            var distance = result.routes[0].legs[0].distance.value / 1000;
            var time = result.routes[0].legs[0].duration.value / 60;
        }
    });
}

Add a variable in RegExp

I would like to use a variable in RegExp in this function.

checkSocial(platform, link) {
let reg = new RegExp(/^(?:https?://)?(www.facebook.com/)(?:S+)/);
return reg.test(link);
}

Doing this:

let reg = new RegExp(`/^(?:https?://)?(www.${platform}.com/)(?:S+)/`);

or this:

let reg = new RegExp('^(?:https?://)?(www.' + platform + '.com/)(?:S+)');

didn’t work. How can I add a variable?

How can I validate a pdf file in my form using react-hook -form?

I am using react hook form for my project. I want to know how can i validate input type=’file’. It should only accept pdf. It was successfully inserted into database now when i want that only pdf should should be allowed. I am using react hook form v7. If someone knows plz suggest me. Thanks in advance!

Here’s my code:

import React from 'react'

import { useForm } from 'react-hook-form';
import { ToastContainer, toast } from 'react-toastify';


export const Workshop = () => {
  const { register, handleSubmit, formState: { errors }, reset } = useForm();

  const onSubmit = async (data, e) => {

    const formData = new FormData();
    formData.append('workshop',data.workshop)
    formData.append('participants',data.participants)
    formData.append('startdate',data.startdate)
    formData.append('selectedfile',data.selectedfile[0])
    formData.append('establishmentdate',data.establishmentdate)
    console.log(data)
    reset()
    const requestOptions = {
      method: 'POST',
      // headers: { 'Content-Type': 'application/json' },
      body: formData
    };



    const response = await fetch("http://localhost:3001/workshop", requestOptions);
    try {
      if (response.status == 200) {
        toast.success("Successfully added");
      }
    }
    catch {
      toast.error("Invalid");
    }
    const jsonData = await response.json();
    console.log(jsonData)

    // toast.error("Invalid"); 


  };

  return (
    <div className="container ">
      <ToastContainer />
      <form onSubmit={handleSubmit(onSubmit)}>
        <div class="mb-3 mt-5" >
          <h2>Details of Workshops/Seminars








          </h2>
          <label for="exampleFormControlInput1" class="form-label">Name of the workshop/ seminar





          </label>
          <input type="text" class="form-control w-25" name="workshop" id="exampleFormControlInput1" {...register("workshop", { required: true, pattern:{value:/^[a-zA-Z]+$/ ,message:'Only characters allowed'}})} />
          {errors.workshop && errors.workshop.type === "required" && (
        // <span role="alert">This is required</span>
        <div style={{color:'red'}}> This is required</div>
        
      )}
      
        {errors.workshop && errors.workshop.type === "pattern" && (
        <div style={{color:'red'}}> Only characters allowed</div>
      )}
        </div>
        <div class="mb-3 w-25 ">
          <label for="exampleFormControlTextarea1" class="form-label">Number of Participants






          </label>
          <input type="text" class="form-control" id="exampleFormControlTextarea1" name="participants" {...register("participants", { required: true, pattern:{value:/^[0-9b]+$/ ,message:'Only characters allowed'}})} />
          {errors.participants && errors.participants.type === "required" && (
        // <span role="alert">This is required</span>
        <div style={{color:'red'}}> This is required</div>
        
      )}
      
        {errors.participants && errors.participants.type === "pattern" && (
        <div style={{color:'red'}}> Only numbers allowed</div>
      )}
        </div>
        <div class="mb-3 w-25">
          <label for="exampleFormControlTextarea1" class="form-label">Date From – To









          </label>
          <input type="date" class="form-control" id="exampleFormControlTextarea1" name="startdate" {...register("startdate",{required:true})} />
          {errors.startdate && errors.startdate.type === "required" && (
        // <span role="alert">This is required</span>
        <div style={{color:'red'}}> This is required</div>
        
      )}
      
        {errors.startdate && errors.startdate.type === "valueAsDate" && (
        <div style={{color:'red'}}> Only numbers allowed</div>
      )}
        </div>

        <div class="mb-3 w-25">
          <label for="exampleFormControlTextarea1" class="form-label">Link to the Activity report on the website(Upload PDF)










          </label>
          <input type="file" class="form-control" id="exampleFormControlTextarea1" name="selectedfile" {...register('selectedfile', {
            required:true,
            
          })} />
          
        </div>
        <div class="mb-3 w-25">
          <label for="exampleFormControlTextarea1" class="form-label">Date of establishment of IPR cell











          </label>
          <input type="date" class="form-control" id="exampleFormControlTextarea1" name="establishmentdate" {...register("establishmentdate",{required:true})} />
          {errors.establishmentdate && errors.establishmentdate.type === "required" && (
        // <span role="alert">This is required</span>
        <div style={{color:'red'}}> This is required</div>
        
      )}
      
        {errors.establishmentdate && errors.establishmentdate.type === "valueAsDate" && (
        <div style={{color:'red'}}> Only numbers allowed</div>
      )}
        </div>




        <button type="submit" class="btn btn-primary me-md-2">Submit</button>
        <button type="button" class="btn btn-primary me-md-2" >Download Excel</button>
        <button class="btn btn-primary me-md-2" >Download PDF</button>
        <button class="btn btn-primary me-md-2" >Download Word</button>


        
       
      </form>
    </div>
  )
}

How should I fix this?

How to get the url of a website with an extension?

How to get the url of a website with an extension?
im trying to get the url of a website with an extension and display it

but if i try to get it normally it returns:

chrome-extension://bilkbnaojbkfbinghcpobifhemelfope/index.html

which is the html file of the extension

how would i make it give me the actual https website that im on?

my 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>Document</title>
</head>
<body>

    <h1 id="url"> url goes here </h1>


    
    <script src="script.js" ></script>
</body>
</html>

my script.js:

const urlEl = document.getElementById("url")
window.setInterval(function doTheTing() {
        urlEl.innerText = document.URL
    }, 1000)

my manifest.json:

{
“manifest_version”: 2,

"name": "url thing",
"version": "0.1.0",
"description": "",

"browser_action": {
    "default_popup": "index.html"
},

"content_scripts": [{
"js": ["script.js"],
"matches": ["https://*/*"]
}],


"permissions": ["activeTab"]

}

thanks for the help!

Nuxt dynamicly appended elements ignoring styling

I’ve run into an issue where elements that get appended with Javascript ignore all styling.

In this specific case I’ve got buttons where I want to have ripple effects uppon clicking the code works as following:

I got elements in my HTML with the class material-button

After the elements are loaded the following code will be executed:

mounted() {
// To make sure the code runs after the elements are rendered i used $nextTick
  this.$nextTick(() => {
    function createRipple(event) {
      const button = event.currentTarget;
      const circle = document.createElement("span");
      const diameter = Math.max(button.clientWidth, button.clientHeight);
      const radius = diameter / 2;

      circle.style.width = circle.style.height = `${diameter}px`;
      circle.style.left = `${event.clientX - (button.offsetLeft + radius)}px`;
      circle.style.top = `${event.clientY - (button.offsetTop + radius)}px`;
      circle.classList.add("ripple"); 

      const ripple = button.getElementsByClassName("ripple")[0];

      if (ripple) {
        ripple.remove();
      }

      button.appendChild(circle);
    }

    const buttons = document.querySelectorAll(".material-button");
    for (const button of buttons) {
      button.addEventListener("click", createRipple);
    }
  })
}

I thought it was because the styling was inside a scoped <style> tag so I tried the following things:

  • I added the styling to a <style> tag without the scope attribute to my component
  • I added the styling to a <style> tag without the scope attribute to my default.vue
  • I added the styling to my global.scss

None of these attempts have worked for me. I’m pretty sure however that the styling is indeed ignored and that my problem is not caused somewhere else, because the ripple element is infact appended as proven by this screenshot:

enter image description here

However i can see that span.ripple is nowhere to be found in the styling:

enter image description here

Click JS button on page load

I want my webpage to auto click a button when the page is loaded. This is my button:

<button class="configure-product configure-product-simple elementor-button" type="button" data-price="95" data-product_id="1934">Stel samen!</button>

I think this button calls a JS function of a wordpress plugin, so that you open the product configurator. If i copy this button html on another page tho it wont work. It will only work on the product page.

Im very new to developing, so i could really use some help. Does anyone have any ideas how to implement this?

How to move image but not its position in CSS

As you can see in the image attached, the airplane image is moving to left intentionally. But I don’t want its position to move out of the alignment. I want to have something like parallax effect but on hover like this website is doing. https://digitalsilk.com/I have just started website development. I want to know How I can have these image transition from: https://digitalsilk.com/ . But I am not able to recreate that transition. I am having trouble with one thing that is moving the back airplane image a little to the left without moving its position (like a parallel effect) You can see the main page gallery of the website attached in desktop view.

<div id="outter-image">
  <div class="tilt-box">
    <div class="tilt-bg-image-box">
      <img class="bg-image" src="https://www.digitalsilk.com/wp-content/themes/digitalsilk/assets/images/seo_pages/recent-projects/tecnam_bg.webp" />
    </div>
    <img class="overlay-image" src="https://www.digitalsilk.com/wp-content/themes/digitalsilk/assets/images/seo_pages/recent-projects/webp/Tecam_recent_mockup-min.webp" />
  </div>
</div>

<style>
  .overlay-image {
    top: -20px;
    right: -20%;
    position: absolute;
    width: 60%;
    aspect-ratio: auto 299 /566;
    height: 120%;
    transition: transform .6s ease-in-out, opacity .5s;
    opacity: 0;
    transform: perspective(1000px) rotateY( -60deg);
  }
  
  .tilt-bg-image-box {
    transition: transform .6s ease-in-out, opacity .5s, -webkit-transform .6s ease-in-out;
  }
  
  .bg-image {
    transition: transform 1s .4s linear, opacity .5s, -webkit-transform 1s .4s
  }
  
  .tilt-box:hover .bg-image {
    transform: translate3d(-8%, 0, 0);
  }
  
  .tilt-box:hover .overlay-image {
    opacity: 1;
    -webkit-transform: perspective(1000px) rotateY( -20deg);
    transform: perspective(1000px) rotateY( -20deg);
  }
  
  .tilt-box:hover .tilt-bg-image-box {
    transform: perspective(1000px) rotateY(20deg);
  }
  
  .tilt-box:hover .bg-image {
    transition: transform 4s .4s linear, opacity .5s, -webkit-transform 4s .4s
  }
</style>

Browser shows blank page in reactJS

Hi I am new in reactjs when i am open live server it show blank page on browser. The code of snake.html file is:

<html>
    <head>
        <title>Snake Game with Sahin</title>
    </head>
    <body>  
        <canvas id="canvas" width="400" height="400"></canvas> 
        <script src="snake.js"></script>
    </body>
</html>

snake.js :

var canvasContext = canvas.getContext('2d');
    var canvas=document.getElementById("canvas")
    class Snake{
        constructor(x,y,size){....

Browser Image is here

page blocked by chrome

I am trying to create a chrome extension, that will redirect to custom html file. the page is blocked by the browser

manifest.json

{
    "manifest_version": 3,
    "name": "Hello World!",
    "version": "0.1.0",
    "content_scripts": [
        {
            "matches": ["<all_urls>"],
            "js": ["src/blocker.js"]
        }
    ],
    "permissions": ["storage", "activeTab", "tabs"],
    "action": {
        "default_popup": "src/html/popup.html"
    }
}

blocker.js

window.location.href = chrome.runtime.getURL("html/popup.html");

Page blocked Image

Array sort with primary and secondary value [duplicate]

Is there a way to sort an array of objects using a primary and secondary value? What i mean is an array like this:

[
    { primary: 0, secondary: 'a' },
    { primary: 1, secondary: 'a' },
    { primary: 1, secondary: 'b' },
    { primary: 0, secondary: 'b' }
]

will be sorted using the primary value, so the first two objects with the primary value of 0 come first then the values of 1 come second, and then it will be again sorted by the secondary value and it will result in the array becoming

[
    { primary: 0, secondary: 'a' },
    { primary: 0, secondary: 'b' },
    { primary: 1, secondary: 'a' },
    { primary: 1, secondary: 'b' }
]

im havent really touched the Array.sort() before so im trying to find out how to do this, any help will be appreciated!

Is there a way how to show last grid line ngx chart

I am using a line chart and showing a data within 24 hours time frame:

<ngx-charts-line-chart
  #chart
  [view]="[1200, 700]"
  [scheme]="actualColors"
  [showXAxisLabel]="showXAxisLabel"
  [showYAxisLabel]="showYAxisLabel"
  [xAxis]="xAxis"
  [yAxis]="yAxis"
  [xAxisLabel]="xAxisLabel"
  [yAxisLabel]="yAxisLabel"
  [timeline]="timeline"
  [results]="data"
  [xAxisTickFormatting]="dateTickFormatting"
  [autoScale]="true"
  [xScaleMin]="start"
  [xScaleMax]="end"
  [activeEntries]="activeEntries"
  [yScaleMin]="actualMinSpeed"
  [yScaleMax]="actualMaxSpeed"
>

Also the xScaleMin and xScaleMax are equal to currentDay minium and maximum value, so my view looks like this:

enter image description here

I am struggling to find a way how to show last grid line and the time with 23:59 , is it possible please?

Disable re-rendering of Google map component in Reactjs

I have a base component as defined

import React, { useEffect, useState, useRef } from 'react';
import { GoogleApiWrapper, InfoWindow, Marker } from 'google-maps-react';

// TODO: Create  a resuable LzMap with styles injected and more
export function OverviewPage(props) {
    
    // SOME UseEffect | Code etc

    return (
        <Box position="relative">
            
            <LzMap
                google={props.google}
                zoom={zoom}
            >
                <InfoWindow
                    options={{ maxWidth: 250, minWidth: 150, disableAutoPan: true }}
                    ref={infoWindowRef}
                ></InfoWindow>
             </LzMap>
            // SOME MORE CODE

        </Box>
    );
}

export default GoogleApiWrapper({
    apiKey: process.env.REACT_APP_GOOGLE_API_KEY
})(OverviewPage);

My LzMap component is defined as

import React, { useState, useRef } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Map } from 'google-maps-react';
import mapStyles from 'model/CRM_mapStyle.json';

const useStyles = makeStyles(theme => ({
}));

function LzMap({
    children,
    google,
    zoom
}) {
    const classes = useStyles({});
    const [maps, setMaps] = useState(null);

    const applyMapStyles = (mapProps, map) => {
        map.setOptions({
            styles: mapStyles
        });
        setMaps(map);
    };

    console.log("Rendering");

    return (
        <Map
            containerStyle={{
                position: 'relative',
                width: '100%',
                height: '93vh'
            }}
            onReady={(mapProps, map) => applyMapStyles(mapProps, map)}
            fullscreenControl={false}
            google={google}
            zoom={zoom}
            minZoom={3}
            draggable
            zoomControl={false}
            controlSize={false}
            scaleControl={false}
            mapTypeControl={false}
            streetViewControl={false}
        >
            {children} 
        </Map>
    );
}

export default React.memo(LzMap);

I am trying to make not to re-render again and again. However re-rendering is happening again and again. What is the way I can stop this re-rendering to happen and only update children inside map component.