TypeError: Cannot read property ‘RNFSFileTypeRegular’ of null, js engine: hermes

These are my dependencies from package.json

 "dependencies": {
    "@expo/vector-icons": "^14.0.2",
    "@react-navigation/native": "^6.0.2",
    "expo": "~51.0.23",
    "expo-constants": "~16.0.2",
    "expo-font": "~12.0.9",
    "expo-linking": "~6.3.1",
    "expo-router": "~3.5.19",
    "expo-splash-screen": "~0.27.5",
    "expo-status-bar": "~1.12.1",
    "expo-system-ui": "~3.0.7",
    "expo-web-browser": "~13.0.3",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.74.3",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "~2.16.1",
    "react-native-reanimated": "~3.10.1",
    "react-native-reanimated-carousel": "^3.5.1",
    "react-native-safe-area-context": "4.10.5",
    "react-native-screens": "3.31.1",
    "react-native-web": "~0.19.10"
  },

And I’m using Expo bundlier.

This is my GettingStarted.jsx

import { View, Text } from 'react-native'
import React, { useState } from 'react'
import RNFS from 'react-native-fs'
import Carousel from 'react-native-reanimated-carousel'

export default function GettingStarted() {
  const [file, setFile] = useState([]);
  const dir = `${RNFS.PicturesDirectoryPath}social/assets/Img`
  const imgUrl = async () => {
    try {
      const exist = await RNFS.exists(dir)
      if (exist) {
        console.log("Directory Exist", dir);
      }
    } catch (error) {
      console.error('Error reading subdirectory:', error);
    }
  }
  imgUrl()
  return (
    <View>
      <Carousel >

      </Carousel>
    </View>
  )
}

Index.tsx

import { Text, View } from "react-native";
import GettingStarted from '@/app/(auth)/gettingStarted'

export default function Index() {
  return (
    <View
      style={{
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
      }}
    >
      <GettingStarted></GettingStarted>
    </View>
  );
}

Understanding Component-Based Architecture: Insights into Sencha Ext JS and Similar Frameworks

I’ve been working with Sencha Ext JS for a while and am particularly interested in its component-based architecture, which is one of its most powerful features. However, I’ve encountered some challenges in fully understanding how to effectively use and extend components, especially when it comes to building complex UI applications.

I’m finding the learning resources for Sencha Ext JS to be somewhat limited, and I’m looking for frameworks with similar architectural patterns to help deepen my understanding of these concepts.

The Specific Problem:
While working with Sencha Ext JS, I’ve been trying to tackle the following issues:

Create Custom Components: I want to create custom components that extend existing ones, but I’m having trouble understanding the best practices for doing so without introducing performance issues or breaking encapsulation.

Data Binding and Management: Managing data efficiently within components has been tricky. I’m unsure how to properly set up data stores and bind them to my components in a way that ensures data consistency and reactivity.

Component Lifecycle: I’m struggling with the component lifecycle methods and when to appropriately use them to manipulate the DOM or perform asynchronous operations.

What I’ve Tried:
Official Documentation: I’ve read through the official Sencha Ext JS documentation and tried to follow some example code, but the resources seem limited when it comes to more complex, real-world scenarios.

Online Tutorials: I’ve watched introductory tutorials but still feel unclear about the nuances of component interactions and state management in larger applications.

What I Am Seeking:
Frameworks with Similar Concepts: I’m looking for frameworks that offer similar component-based architectures and patterns. The goal is to understand these concepts better, which could provide insights that apply to mastering Ext JS.

Best Practices: I would appreciate advice on best practices for creating custom components, managing data efficiently, and utilizing lifecycle methods effectively.

Learning Resources: Recommendations for comprehensive learning resources, such as courses, guides, or documentation, that can aid in understanding complex UI frameworks.

Official Documentation: I’ve read through the official Sencha Ext JS documentation and tried to follow some example code, but the resources seem limited when it comes to more complex, real-world scenarios.

Online Tutorials: I’ve watched introductory tutorials but still feel unclear about the nuances of component interactions and state management in larger applications.

Implement persistance Increment of a value

I have a static HTML website. It has a feature where there is a form to be filled and once submitted a copy of the form is sent to the user by email. I used EmailJS for the functionality. That works fine.

However for each form I have an id and I want it to be auto-incremented for every copy sent. I don’t want to use localstorage because when the cache is cleared it gets removed. I need a permanent solution for incrementing the id for each invoice sent.

When a user fills the form the id must be a incremented value from the previous form.

I have no idea how to do this. I implemented a NodeJs server that too when refreshed goes to initial state.

ReactJS state dependends on another state [closed]

I have a component that contains a range date picker and interval components. The interval depends on the date range. The generateDefaultDateIntervalLimitations() function assigns available interval options, and the rest are disabled according to the date range.

My problem is that when the date changes, useEffect sets dateTimeInterval. Because the date has changed, it also changes the interval state. When the interval state changes, it sets dateTimeInterval again. This is normal, but my request depends on setDateTimeInterval, which is defined in the parent component. As soon as this changes, it re-renders the parent component, which has child components with React Query and Axios requests. This causes the request to be sent twice because the state changes first for the date and then for the interval. The interval itself can be changed as well, but only once.

There are 3 cases:

  1. When date changed, interval changed as well
  2. When date changed interval can be the same value for example date range if applied 3 months then interval is 30 seconds, if users changes it to 2 month then still interval is 30 seconds
  3. When user just only changes interval.
const generateDefaultDateIntervalLimitations = (t) => [
  {
    dateDifference: 2592000,
    dateUnit: "second",
    intervals: [
      { label: `30 ${t("sec")}`, value: 30, disabled: false },
      { label: `1 ${t("min")}`, value: 60, disabled: false },
      { label: `5 ${t("min")}`, value: 300, disabled: false },
      { label: `10 ${t("min")}`, value: 600, disabled: false },
      { label: `15 ${t("min")}`, value: 900, disabled: false },
      { label: `30 ${t("min")}`, value: 1800, disabled: false },
      { label: `1 ${t("hour")}`, value: 3600, disabled: false },
      { label: `12 ${t("hours")}`, value: 43200, disabled: false },
      { label: `24 ${t("hours")}`, value: 86400, disabled: false },
    ],
  },
  {
    dateDifference: 7776000,
    dateUnit: "second",
    intervals: [
      { label: `30 ${t("sec")}`, value: 30, disabled: true },
      { label: `1 ${t("min")}`, value: 60, disabled: true },
      { label: `5 ${t("min")}`, value: 300, disabled: true },
      { label: `10 ${t("min")}`, value: 600, disabled: true },
      { label: `15 ${t("min")}`, value: 900, disabled: false },
      { label: `30 ${t("min")}`, value: 1800, disabled: false },
      { label: `1 ${t("hour")}`, value: 3600, disabled: false },
      { label: `12 ${t("hours")}`, value: 43200, disabled: false },
      { label: `24 ${t("hours")}`, value: 86400, disabled: false },
    ],
  },
  {
    dateDifference: 13132800,
    dateUnit: "second",
    intervals: [
      { label: `30 ${t("sec")}`, value: 30, disabled: true },
      { label: `1 ${t("min")}`, value: 60, disabled: true },
      { label: `5 ${t("min")}`, value: 300, disabled: true },
      { label: `10 ${t("min")}`, value: 600, disabled: true },
      { label: `15 ${t("min")}`, value: 900, disabled: true },
      { label: `30 ${t("min")}`, value: 1800, disabled: true },
      { label: `1 ${t("hour")}`, value: 3600, disabled: false },
      { label: `12 ${t("hours")}`, value: 43200, disabled: false },
      { label: `24 ${t("hours")}`, value: 86400, disabled: false },
    ],
  },
  {
    dateDifference: 15724800,
    dateUnit: "second",
    intervals: [
      { label: `30 ${t("sec")}`, value: 30, disabled: true },
      { label: `1 ${t("min")}`, value: 60, disabled: true },
      { label: `5 ${t("min")}`, value: 300, disabled: true },
      { label: `10 ${t("min")}`, value: 600, disabled: true },
      { label: `15 ${t("min")}`, value: 900, disabled: true },
      { label: `30 ${t("min")}`, value: 1800, disabled: true },
      { label: `1 ${t("hour")}`, value: 3600, disabled: false },
      { label: `12 ${t("hours")}`, value: 43200, disabled: false },
      { label: `24 ${t("hours")}`, value: 86400, disabled: false },
    ],
  },
  {
    dateDifference: 31622400,
    dateUnit: "second",
    intervals: [
      { label: `30 ${t("sec")}`, value: 30, disabled: true },
      { label: `1 ${t("min")}`, value: 60, disabled: true },
      { label: `5 ${t("min")}`, value: 300, disabled: true },
      { label: `10 ${t("min")}`, value: 600, disabled: true },
      { label: `15 ${t("min")}`, value: 900, disabled: true },
      { label: `30 ${t("min")}`, value: 1800, disabled: true },
      { label: `1 ${t("hour")}`, value: 3600, disabled: true },
      { label: `12 ${t("hours")}`, value: 43200, disabled: false },
      { label: `24 ${t("hours")}`, value: 86400, disabled: false },
    ],
  },
  {
    dateDifference: 94694400,
    dateUnit: "second",
    intervals: [
      { label: `30 ${t("sec")}`, value: 30, disabled: true },
      { label: `1 ${t("min")}`, value: 60, disabled: true },
      { label: `5 ${t("min")}`, value: 300, disabled: true },
      { label: `10 ${t("min")}`, value: 600, disabled: true },
      { label: `15 ${t("min")}`, value: 900, disabled: true },
      { label: `30 ${t("min")}`, value: 1800, disabled: true },
      { label: `1 ${t("hour")}`, value: 3600, disabled: true },
      { label: `12 ${t("hours")}`, value: 43200, disabled: true },
      { label: `24 ${t("hours")}`, value: 86400, disabled: false },
    ],
  },
];
const DatePickerInterval = ({
  setDateTimeInterval,
  intervalStorageKey,
  intervalStorageOptions,
  isRangePicker,
  showTime,
  defaultDate,
  dateStorageKey,
  dateStorageOptions,
  dateIntervalLimitations,
}) => {
  const [options, setOptions] = useState(null);
  const { t } = useTranslation();
  const [date, setDate] = useState(null);
  const [interval, setInterval] = useState(null);

  const limitations = useMemo(
    () => dateIntervalLimitations || generateDefaultDateIntervalLimitations(t),
    [dateIntervalLimitations, t],
  );

  useEffect(() => {
    if (date) {
      const applyLimitations = (limitations) => {
        const difference = calculateDateDifference("second");
        return (
          limitations.find((lim) => difference <= lim.dateDifference)
            ?.intervals || []
        );
      };

      const calculateDateDifference = (unit) => {
        return date[1]?.diff(date[0], unit) || 0;
      };

      const limitedIntervals = applyLimitations(limitations);
      setOptions(limitedIntervals);
    }
  }, [date, limitations]);

  useEffect(() => {
    if (options?.length > 0) {
      setInterval(options.find((option) => !option.disabled)?.value || 0);
    }
  }, [options]);

  useEffect(() => {
    if (date && interval) {
      setDateTimeInterval({
        date: {
          dateBegin: date[0],
          dateEnd: date[1],
        },
        interval: interval,
      });
    }
  }, [date || (date && interval)]);

  return (
    <>
      <Interval
        setInterval={setInterval}
        interval={interval}
        storageKey={intervalStorageKey}
        storageOptions={intervalStorageOptions}
        options={options}
      />
      <CustomDatePicker
        isRangePicker={isRangePicker}
        showTime={showTime}
        date={date}
        defaultDate={defaultDate}
        setDate={setDate}
        storageKey={dateStorageKey}
        storageOptions={dateStorageOptions}
      />
    </>
  );
};

export default DatePickerInterval;

What i have tried is to use condition logic in useEffect but it does help in case when user updates availble interval it does not send request because it does not catch interval change, for rest cases it works

Event loop of node.js produces unpredictable results

While exploring the node.js event loop, I realized that poll events appear in some random order, rather than following the order described in the event loop.

The logic of the code is trivial: we recursively schedule exactly one setImmediate for each loop iteration. The code inside each setImmediate must schedule one setTimeout and make one request.

Demo:

const http = require("http");
const request = require('request');

const server = http.createServer(function (request, response) {
  response.end();
  console.log("I/O poll", request.url);
});

server.listen(3000, function () {
  console.log("Runing on port 3000");
});

let _i = 0;

var options = {
  'method': 'GET',
  'url': 'https://127.0.0.1:3000/test',
  'headers': {
  },
  form: {}
};

setImmediate(() => {
  console.log("root immediate");
  setImmediate(function loop() {
    let k = _i;
    console.log(`immediate nested => ${k}`, performance.now());
    setTimeout(() => {
      console.log(`setTimeout => ${k}`, performance.now());
    });
    request(options, function (error, response) {
      if (error) throw new Error(error);
      ///console.log(response.body, performance.now());
    });
    /// 50 iterations of event loop
    if (_i++ < 50) setImmediate(loop);
  });
});

When you run this code, you will see something like this:

root immediate
...
I/O poll /test
immediate nested => 19 587.776804
setTimeout => 18 588.651673
setTimeout => 19 588.908073
I/O poll /test
I/O poll /test
I/O poll /test
immediate nested => 20 591.348483
setTimeout => 20 592.245303
I/O poll /test
I/O poll /test
immediate nested => 21 599.421111
I/O poll /test
I/O poll /test
immediate nested => 22 609.22716
setTimeout => 21 609.4331
I/O poll /test
immediate nested => 23 620.868927
setTimeout => 22 621.377087
setTimeout => 23 621.886457
immediate nested => 24 624.343667
setTimeout => 24 625.086037
...

But this is not what is expected. I expected to see, for example, such a picture:

root immediate
...
immediate nested => 18 586.183739
setTimeout => 18 586.321573
I/O poll /test
immediate nested => 19 587.776804
setTimeout => 19 588.908073
I/O poll /test
immediate nested => 20 591.348483
setTimeout => 20 592.245303
I/O poll /test
...

Why is this happening? Explain what I misunderstand?

CORS Error When Sending POST Request from Client to Express Server

I am getting a CORS error when trying to submit a form from my website to my Express server. Here is the setup and the problem:

Server (Express) Code:

const express = require("express");
const cors = require("cors");

const app = express();
app.use(cors({
  origin: 'https://www.teckwithfeya.com'
}));
app.use(express.json());

app.post("/send", (req, res) => {
  console.log(req.body); // Log the received data
  res.send("Form submitted successfully");
});

app.listen(7000, () => {
  console.log("Server is running on port 7000");
});

Client-side JavaScript:

document.addEventListener("DOMContentLoaded", function () {
  const contactForm = document.getElementById("contactForm");
  contactForm.addEventListener("submit", function (event) {
    event.preventDefault();

    const formData = new FormData(contactForm);
    fetch("https://www.teckwithfeya.com/send", {
      method: "POST",
      body: formData
    })
    .then(response => response.text())
    .then(data => {
      console.log(data);
    })
    .catch(error => {
      console.error("Error:", error);
    });
  });
});

When I submit the form, I get the following CORS error in the browser console:

Access to fetch at ‘https://www.teckwithfeya.com/send’ from origin ‘https://www.teckwithfeya.com’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

I have set up CORS on my Express server with cors middleware.
I tried using both fetch with JSON and FormData.

How to get rid of devtools hint in input autofill in Chrome

Recently when I’m working with inputs in React / Javascript and I click into the inputs to type stuff like address etc, Chrome opens up this strange context menu which is unwanted by me. Is there a way to disable this? I’ve tried turning autofill off in Chrome settings (Autofill and passwords) but it doesn’t help.

enter image description here

Open existing Page as a Modal

I have the case that I can only edit/add CSS and Javascript. I have an existing link with an a tag inside a classed span. If I click on the a tag, I want to open the link as a modal.

Remember, I cannot change HTML or other attributes. I am fairly new to this thing so I came here to ask.

<span class="spanclass">
  <a href="thisismylink">MyLinkTargetText</a>
</span>

I want the a href to open the same page as a modal.
Is there a solution to this?

I tried various snippets from the internet, but none seemed to work they way I want them to. Help!

How can I solve [firebase_functions/internal] INTERNAL?

I’ve uploaded a Firebase function (code below) which uses Google Gemini API to generate workouts. Then, I use Dart to call it but, even though I’ve allowed public access to call it, it throws this error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_functions/internal] INTERNAL

#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
<asynchronous suspension>
#2      MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:22:24)
<asynchronous suspension>
#3      HttpsCallable.call (package:cloud_functions/src/https_callable.dart:49:37)
<asynchronous suspension>
#4      new GenerateWorkoutBloc.<anonymous closure> (package:energi/logic/blocs/generate_workout/generate_workout_bloc.dart:50:26)
<asynchronous suspension>
#5      Bloc.on.<anonymous closure>.handleEvent (package:bloc/src/bloc.dart:229:13)

I’ve allowed public access otherwise it showed a Firebase UNAUTHENITCATED error. Now I don’t know what INTERNAL stands for, so I would love it if you could explain it to me.

Here is the function:

const functions = require("firebase-functions");
const { GoogleGenerativeAI } = require("@google/generative-ai");

const apiKey = "key"; 
const genAI = new GoogleGenerativeAI(apiKey);

const model = genAI.getGenerativeModel({
  model: "gemini-1.5-pro",
});

const generationConfig = {
  temperature: 1.7,
  topP: 0.95,
  topK: 64,
  maxOutputTokens: 8192,
  responseMimeType: "application/json",
};

exports.generateWorkout = functions.https.onRequest(async (req, res) => {
  try {
    console.log('starting');
    const chatSession = model.generateContent({
      generationConfig,
      history: [
        {
          role: "user",
          parts: [
            {text: "You are a professional...."},
          ],
        },
        {
          role: "model",
          parts: [
            {text: "```json....`"},
          ],
        },
      ],
    });
  
    const result = (await chatSession).response;
    const responseText = await result.response.text();
    console.log(responseText);
    res.status(200).send(responseText);
  } catch (error) {
    console.error("Error generating workout:", error);
    res.status(500).send("Error generating workout");
  }
});

And here is how I call it:

try {
        HttpsCallable callable =
            FirebaseFunctions.instance.httpsCallable('generateWorkout');
        final response = await callable.call();
        print(response);

      } on FirebaseFunctionsException catch (error) {
        print(error.toString());

      } catch (e) {
        print(e.toString());
      }

ShadCN UI combobox only working with keyboard not with mouse

I have a very simple app that consists of only a combobox and a card (it is going to be embedded on a WordPress). NextJS, ShadCN ui.

The combobox for some reason only works with keyboard, not with the mouse. Even if I copy the examples directly from ShadCN ui website it does not work.

I am sure it is something easy but I cant figure it out.

Here is my code:

'use client'

import { ChevronsUpDown } from 'lucide-react'
import { Batch, batches } from '@/lib/batch'
import { Button } from '@/components/ui/button'
import {
  Command,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
} from '@/components/ui/command'
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from '@/components/ui/popover'
import { useState } from 'react'
import InfoCard from './info-card'

export function Combobox() {
  const [open, setOpen] = useState(false)
  const [value, setValue] = useState('')
  const [inputValue, setInputValue] = useState('')
  const [currentItem, setCurrentItem] = useState<Batch | null>(null)

  const filteredBatches = batches.filter((batch) =>
    batch.number.includes(inputValue)
  )

  const handleClick = (batch: Batch) => {
    console.log('clicked')
    setCurrentItem(batch)
    setOpen(false)
  }

  return (
    <>
      <Popover open={open} onOpenChange={setOpen}>
        <PopoverTrigger asChild>
          <Button
            variant='outline'
            role='combobox'
            aria-expanded={open}
            className='w-[500px] justify-between'
          >
            {value
              ? batches.find((batch) => batch.number === value)?.number
              : 'Type your batch number...'}
            <ChevronsUpDown className='ml-2 h-4 w-4 shrink-0 opacity-50' />
          </Button>
        </PopoverTrigger>
        <PopoverContent className='w-[500px] p-0'>
          <Command>
            <CommandInput
              placeholder='Search batch number...'
              value={inputValue}
              onValueChange={setInputValue}
            />
            <CommandEmpty>No batch found.</CommandEmpty>
            <CommandList>
              <CommandGroup>
                {filteredBatches.map((batch) => (
                  <CommandItem
                    key={batch.number}
                    value={batch.number}
                    onSelect={() => handleClick(batch)}
                    className='hover:cursor-pointer hover:bg-slate-400'
                  >
                    {batch.number} - {batch.fishery}
                  </CommandItem>
                ))}
              </CommandGroup>
            </CommandList>
          </Command>
        </PopoverContent>
      </Popover>

      <InfoCard batch={currentItem} />
    </>
  )
}

export default Combobox

I have it deployed here so you can see that it works with keyboard:
https://aisbatchnumbers.vercel.app/

Code is here:
https://github.com/santivdt/ais-batch-numbers

Hopefully someone knows the solution ..

Display text as code in IDE tooltip when describing my components

i m trying to create doc for my components while using them. Basically, i’m adding comments over all my functions headers like this :

/**
 * this is some text
 * @param text this is some text
 * @returns this is some text
 */
export default function component(props: any) {

I want to describe the tooltip when hovering my functions inside vscode.

I’d like to have something like the example in this image. Here, the code example is well formatted and easier to read.

example in vscode

Why is Animationend firing after a delay with timing function as linear?

I simply want the animationend event to fire as soon as the animation completes visually.

The most similar answer I could find for this was this, but unfortunately using linear in my cases did not solve the issue.

document.querySelector('h1.ani').addEventListener('animationend', (e) => {
  console.log("invoked");
});
* {
  margin: 0px;
  padding: 0px;
  box-sizing: border-box;
  font-family: Arial;
}

body {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

h1 {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background-color: green;
  letter-spacing: -500px;
  position: relative;
}

h1.ani {
  animation: morph 4s linear forwards;
}

h1 span {
  transition: opacity .5s ease;
}

h1 span.show {
  opacity: 1 !important;
}

h1.hide span {
  opacity: 0;
  transform: scale(0) translateY(100%);
  position: absolute;
}

@keyframes morph {
  0% {
    letter-spacing: -500px;
  }
  40% {
    letter-spacing: 0px;
  }
  60% {
    letter-spacing: 0px;
  }
  100% {
    letter-spacing: -500px;
  }
}
<h1 class="ani">
  <span>W</span>
  <span>e</span>
  <span>b</span>
  <span>&nbsp;</span>
  <span>D</span>
  <span>e</span>
  <span>v</span>
  <span>e</span>
  <span>l</span>
  <span>o</span>
  <span>p</span>
  <span>e</span>
  <span>r</span>
</h1>

Error Selecting data in Postgres using node

This is my get function

    const navigate = useNavigate();

    const [userData,setUserData] = useState({});

    useEffect(()=>{
        if(Cookies.get('auth') !== 'AUTHENTICATED'){
            navigate('/');
        }
        $(".navbar").css('display','block');
        let getUser = async () => {
            const result = await axios.get(`http://localhost:3000/get/user${Cookies.get('id')}`);
            setUserData(result.data);
            console.log(result.data);
        }
        getUser();
    },[]);

This is my get Route

app.get('/get/user:id', async (req,res) => {
    var id = parseInt(req.params.id);
    console.log(id);
    const result = db.query('SELECT * FROM users WHERE id = $1',[id]);
    console.log(result.rows);
});

I am having trouble with executing the query as the query is returning undefined value.
This is my output
This is my Database

I am getting the id as a string from path variable but even after using parseInt() it is not working

EDIT: I have tried to modify the endpoint as ‘/user/:id’ but it still does not work, still returns undefined.