Making an inactive browser tab active again automatically using react js

Im building a react app. in the app, Im receiving a message through an API and if I receive a message, the message automatically display to the user.

But the problem is if the user is on another tab, they cannot see whether a message is received. I want to make the react app tab active immediately if the user is browsing on another tab after receiving a message. Is there a way in react to make the tab automatically active?

Going from a zoom in picture >> open a new tab

Infant coder here, used a template for my site where I wanted to showcase my work. The problem is the UX is really bad; in my portfolio section, I want the users to click on one of the images so it opens a new tab, instead of zoom in on a photo. I’ve tried to modify the JS and create a new function new tab but when I do that it stops all the other scrips on the page and no info shows up. Maybe someone on here can help? Here’s the link to the template I’ve used: https://templateflip.com/templates/super-folio/

here’s the part of the code that’s tripping me up:

 /**
   * Big Picture Popup for Photo Gallary
   */
   document.querySelectorAll(".bp-gallery a").forEach((function(e) {
    var caption = e.querySelector('figcaption')
    var img = e.querySelector('img')
    // set the link present on the item to the caption in full view
    img.dataset.caption = '<a class="link-light" target="_blank" href="' + e.href + '">' + caption.innerHTML + '</a>';
    window.console.log(caption, img)
     e.addEventListener("click", (function(t){
       t.preventDefault();
       BigPicture({
        el: t.target,
        gallery: '.bp-gallery',
      })
     })
    )
  }))

When I changed it, I did:

 /**
   * Big Picture Popup for Photo Gallary
   */
   document.querySelectorAll(".bp-gallery a").forEach((function(e) {
    var caption = e.querySelector('figcaption')
    var img = e.querySelector('img')
    function NewTab() {
        window.open(
          "a", "_blank");
    )
  }))

Which worked, but made all of the other text on the page disappear or unresponsive.

Any help you could provide would be great!

Multiple Horizontal Scroll on Datatables

As far as I know, Datatables (or any other table), cannot have two horizontal scrolls. I have added Fixed Columns from Datatables and fixed up to 6 columns out of 20 or so. The first 6 columns have taken almost 70% of the table view, so on the remaining 30%, other data cannot be seen properly.

Is there any way I can add another Horizontal Scroll on the Fixed Columns (I know this beats the purpose of fixing the columns)??

IonInput getting error with React Hook Form

Try to use a IonInput on a project.

const { register, handleSubmit, formState: { errors } } = useForm({
        
        mode: "onTouched",
        reValidateMode: "onChange"
    });

    const fields = [
        {
            label: "Firstname",
            required: true,
            requiredOptions: {

                maxLength: 10
            },
            props: {
                
                name: "firstname",
                type: "text",
                placeholder: "Enter a username"
            }
        },

        {
            label: "Age",
            required: true,
            requiredOptions: {

                min: 18,
                max: 99
            },
            props: {
                
                name: "age",
                type: "number",
                inputmode: "numeric",
                placeholder: "Enter your age"
            }
        }
    ];

    console.log(errors);
    
    const onSubmit = (data : any) => {
        
        console.log(data);
    }

    return (
        <IonPage>
            <IonHeader>
                <IonToolbar>
                    <IonTitle>React Hook Form</IonTitle>
                </IonToolbar>
            </IonHeader>
            <IonContent fullscreen>
                <IonHeader collapse="condense">
                    <IonToolbar>
                        <IonTitle size="large">React Hook Form</IonTitle>
                    </IonToolbar>
                </IonHeader>

                <IonCardSubtitle className="ion-text-center ion-margin">An example using React Hook Form</IonCardSubtitle>

                <form onSubmit={ handleSubmit(onSubmit) }>

                    { fields.map((field, index) => {

                        const { label, required, requiredOptions, props } = field;

                        return (
                            <IonItem key={ `form_field_${ index }` } lines="full">

                                <>
                                    <IonLabel position="fixed">{ label }</IonLabel>
                                    <IonInput { ...props } { ...register(props.name, { required, ...requiredOptions }) } />
                                </>
                                { required && errors[props.name] && <IonIcon icon={ alertCircleOutline } color="danger" /> }
                            </IonItem>
                        );
                    })}

                    <IonButton type="submit" className="ion-margin-top" expand="full">Submit</IonButton>
                </form>
            </IonContent>
        </IonPage>
        );

Will Get this error:

Type ‘{ onChange: ChangeHandler; onBlur: ChangeHandler; ref:
RefCallBack; name: string; min?: string | number | undefined; max?:
string | number | undefined; … 7 more …; inputmode?: undefined; }
| { …; }’ is not assignable to type ‘IntrinsicAttributes & IonInput
& Pick<HTMLAttributes, “onBlur” | “onChange” |
… 250 more … | “onTransitionEndCapture”> & StyleReactProps &
RefAttributes<…>’. Type ‘{ onChange: ChangeHandler; onBlur:
ChangeHandler; ref: RefCallBack; name: string; min?: string | number |
undefined; max?: string | number | undefined; … 7 more …;
inputmode?: undefined; }’ is not assignable to type ‘IonInput’.
Types of property ‘”max”‘ are incompatible.
Type ‘string | number | undefined’ is not assignable to type ‘string | undefined’.
Type ‘number’ is not assignable to type ‘string | undefined’.

My Dependencies:

  • @ionic/react”: “^6.0.0”
  • react-hook-form”: “^7.27.0”

I did some research through internet but didnt get a fix. May anyone help?
Moreover, are there any other forms framework are good for ionic project? Thanks!!

Calling out to an API for each element in an array

I have an array of objects. Each object is a profile of a dog including name, breed, etc. I want to be able to map through the array, get the breed of dog, and call out to an API for a random image of that breed. Below is a portion my React code that I tried (and failed). To my understanding, it’s not working because useEffect only will call out once even though I’m mapping through the array. It is possible to call out for each breed I map through?

    const urlDogBase = "https://dog.ceo/api/breed/"
    const urlEnding = "/images/random"
    const [dogImage, setDogImage] = useState({})

    let availableDogs = DogData.map((dog,index) => {
        const dogUrl = dog.breed
        const fullUrl = `${urlDogBase}${dogUrl}${urlEnding}`

        useEffect(()=>{ 
            fetch(fullUrl)
              .then((response) => response.json())
              .then((data) => setDogImage(data.message))
              .catch(() => console.log("oops error"));
          }, []);

        return(
            <img src={dogImage} />
        )
    })

React.js – How to access children’s children?

I’m trying to add more nodes to the taskRefContainer. Currently there is only one node and I’m accessing it with children but when I add an extra <div> so I can add an <input type="range" /> to that div the children obviously change. I’ve commented out the part that breaks it in the code below.

import { useState, useEffect, useRef } from "react";
import "./App.css";
import { initialTracks } from "./initialTracks";

function App() {
  const [tracks, setTracks] = useState(initialTracks);
  const [isPlaying, setIsPlaying] = useState(true);
  const tracksContainerRef = useRef();

  useEffect(() => {
    const audioContext = new (window.AudioContext ||
      window.webkitAudioContext)();
    for (const audio of tracksContainerRef.current.children) {
      audioContext
        .createMediaElementSource(audio)
        .connect(audioContext.destination);
    }
    audioContext.resume();
  }, []);
  useEffect(() => {
    for (const audio of tracksContainerRef.current.children) {
      if (isPlaying) {
        audio.pause();
      } else {
        audio.play();
      }
    }
  }, [isPlaying]);
  return (
    <div>
      <h1>Audio Mixer</h1>
      <button onClick={() => setIsPlaying(!isPlaying)}>play</button>
      <div ref={tracksContainerRef}>
        {tracks.map(({ path }, i) => (
          // <div key={i}>
          <audio key={path} src={path} />
          // <input type="range" />
          // </div>
        ))}
      </div>
    </div>
  );
}
export default App;

Why doesn’t the Canvas API support the Lucida Console font?

According to an answer in a previous question the Canvas API “allows use of any font that can otherwise be used by the user agent with a CSS stylesheet” yet while I can normally use Lucida Console in my browser it fails to load in Canvas.

Here is the font assignment that fails:

ctx.font = '15px Lucida Console, Comic Sans MS';

It has no trouble loading Comic Sans.

Or you can look at the whole example here: https://jsfiddle.net/zt6m1qeg/1/

How to pass id and store the id in variable for updating the post in redux and formik

  • How to update the Post by passing initialvalue and id in put request

    TableList.js

    import React from ‘react’;
    import { connect } from ‘react-redux’;
    import { Form, Table } from ‘react-bootstrap’;
    import { editPost, } from ‘../actions/listActions’;
    import {Formik} from ‘formik’
    import * as Yup from ‘yup’

    class TableList extends React.Component {

    componentDidMount() {
     this.props.loadTableList();
    

    }

     handleEdit = (id,list, setFieldValue) => {
     setFieldValue('name', list.name);
     setFieldValue('email', list.email);
     setFieldValue('phone', list.phone);
     setFieldValue('street', list.street);
     setFieldValue('website', list.website)
    

    }

    render() {
    const { tableList } = this.props;

     return (
         <>
       <div style={{ margin: 110 }}>
    
         <Formik 
    
         initialValues={{
         name: '',
         email: '',
         phone: '',
         website: '',
          address : {
             street: ''}
    
         }}
    
         validationSchema={validation}
    
    
         onSubmit={(initialValues)=>{
            this.props.addNewpost(initialValues);
    
         }}
    
         >
             {({errors,handleSubmit,handleChange,touched})=>(
    
                 <Form onSubmit={handleSubmit}>
                     <h3>ADD USER</h3>
                 <div>
                  <input placeholder="Name" name="name"  onChange={handleChange} />
                  {touched.name && errors.name ? (<small className='text-danger'>{errors.name}</small>) : null}
                  </div>
                <div>
                <input placeholder="Email" name="email" onChange={handleChange}/>                                                                             {touched.email && errors.email ? (<small className='text-danger'>{errors.email}  </small>) : null}
                </div>
                <div>
               <input placeholder="Phone no" name="phone" onChange={handleChange}  />
               {touched.phone && errors.phone ? (<small className='text-danger'>{errors.phone}  </small>) : null}
                  </div>
                  <div>
              <input placeholder="Website" name="website" onChange={handleChange} />
              {touched.website && errors.website ? (<small className='text-danger'>{errors.website}</small>) : null}
                </div>
                <div>
              <input placeholder="Street" name='street' onChange={handleChange} />
              {errors.street && touched.street ? (<small className='text-danger'>{errors.street}</small>) : null}
              </div>
              <div>
              <button  type='submit'  onSubmit={handleSubmit}>ADD</button>
                </div>
    
    
    
                 </Form>
    
             )        
             }
          </Formik>  
                         {tableList.map((user) => {
                             return <tr key={user.name}>
                                 <td>{user.id}</td>
                                 <td>{user.name}</td>
                                 <td>{user.email}</td>
                                 <td>{user.address.street}</td>
                                 <td>{user.phone}</td>
                                 <Link to='/'>{user.website}</Link>
                                 <td>
                                     <button onClick={() =>       this.props.deletePosts(user.id)}>Delete</button>
                                 </td>
                                 <td>
                              <button onClick={() => this.handleEdit( user.id,user,setFieldValue)}>Edit</button>
                                 </td>
                             </tr>
    
                         })}                 
    
                 </tbody>
    
                 </Table>
    
    
             </div>
         </>
     )
    

    }
    }

       const mapStateToProps = (state) => {
    return {
       tableList: get(state, ['listReducer', 'posts'], [])
    

    }
    }

       const mapDispatchToProps = (dispatch) => {
    

    return {
    updatePost: (id,name,email,phone,website)=>dispatch(editPost(id,name,email,phone,website))

    }
    }

    export default connect(mapStateToProps, mapDispatchToProps)(TableList)

    • listaction.js

    export const editPost = (id,name,email,phone,website,address)=>{
    return (dispatch)=>{

     axios.put(`https://jsonplaceholder.typicode.com/users/${id}`,name,email,phone,website,address)
    
     .then(response => {
         dispatch({
             type: actionTypes.EDIT_POST,
             payload: response.data
         })
    
         console.log(response.data);
     })
     .catch(error => {
         console.log(error);
    
     })
    

    }
    }

    • reducer.js

      case actionTypes.EDIT_POST:
      console.log(action.payload)
      return{
      …state,
      posts: action.payload,

I want to filter data in one array on one specific field with different condition in nodejs with mongodb But I Get the Result only last Condition

the below code gives the list of attendance whose WorkStatus is “P”, it takes last $and value($and: {$eq: [“$$attendance.WorkStatus”, “P”],},) from $filter, but i want to get count of each WorkStatus separately(i.e. “MIS”,”A”,”P”).

{$facet: {totalCount: [{ $count: “sum” }],aggregatedData: [{$project: {date: “$date”,
attendance: { $filter: { input: “$attendance”,as: “attendance”,cond: {$and: { $eq [“$$attendance.WorkStatus”, “MIS”], }, $and: {$eq: [“$$attendance.WorkStatus”, “A”],},$and: { $eq: [“$$item.WorkStatus”, “P”]

How to make current tab page that im on Bold

Im using react and that the last thing I have to do is make the tab that I am on Bold. So if I am on the home page then it’ll be bold, but if I switch to Pricing tab, that one will instead turn bold.
This is my navigation bar using bootstrap

    function Navbar(){
    return(
        <div>
            <nav className="navbar navbar-expand-lg navbar-light ">
                <a className="navbar-brand" href="#">
                    <img src={require("../imgs/plumbing.png")} width="50" height="50" className="d-inline-block align-top" />
                    <b>Pistol Pete's Plumbing Perfection</b>
                </a>
                <div className="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul className="navbar-nav ">
                        <li className="nav-item">
                            <a className="nav-link" href="/Home">Home </a>

                        </li>
                        <li className="nav-item">
                            <a className="nav-link" href="/Pricing">Pricing</a>
                        </li>
                        <li className="nav-item">
                            <a className="nav-link" href="/Staff">Staff</a>
                        </li>
                    </ul>
                </div>
            </nav>

        </div>
    )
}export default Navbar;

How to get the Last updated item in Google sheets

I’m trying to find a solution online but it’s not been fruitful so far, I want to fetch the data in Columns 1,2,3,4,5,6,7 that is last edited in Sheet1 and then feed it into Sheet2.

Giving you an example, If the data is edited in Sheet1 C2 that data should be added into Sheet2 in A2 and B2

What I’m trying to achieve is, if anyone updated Sheet one, I want to know the last update in Sheet 2, is it possible to do this via scrip?

Sheet1 Screenshot

enter image description here

Sheet2 Screenshot

enter image description here

I tried a lot of script editing and tried to modify it… so far nothing worked for me. šŸ™

View Google Sheet