How to call call function with parameters in gatsby Link-component

I am searching for the proper syntax for calling function with parameters and use return values of function as a state-parameter for a link.

Here you can see my code:

import React, { useState, useEffect } from 'react';
import { Link } from "gatsby";
import Layout from "../components/Layout";

const TestParam = (props) => {
const data = [ {
    "RezeptId": 1,
    "RezeptTitel": "Rezept 1: Hamburger"
},
{
    "RezeptId": 2,
    "RezeptTitel": "Rezept 2: Wraps"
}];

const getRezept = (parameter_1, parameter_2) => {
    const abc = [{
        "id": 1,
        "text": "addition für 1"
    },
    {
        "id": 2,
        "text": "addition für 2"
    }];
    // Do something
    // ...
    return abc[parameter_1];
  }

  return (
    <Layout>
         <h2>Rezepte</h2>
     <div>
        { data && data.map(rezept => {
             return(
              <div key={rezept.RezeptId}>
                   <Link to={`/ListRezept/${rezept.RezeptId}`} state={{ data: {_function_with_parameter(param1, param2)}}}>
                      <h1>{rezept.RezeptTitel.substring(0,25)}</h1>
                   </Link>
              </div>
             );
        })}
     </div>
     </Layout>
     );
        
     }

export default TestParam;

The “function_with_parameter()” value should be my call of function “get Rezepte” and I want to pass two paramters, which are 2 variable values.

Pseudocode of call function with parameter

state={{ data: {getRezept(${rezept.RezeptId}, ${rezept.RezeptTitel})}}}

Unfortunately it does not work 🙁

What is the proper syntax for calling “getRezepte” function with parameters and add the result of called function as a state-parameter in my Link?

For sure, the getRezept-function will have more logic inside later and also the “const data = […]” value will be the result of a data fetch.

JS Classes with same arguments

I have a JS Class and would like to be able to “reuse” it without running the constructor multiple times when I create the same classe with identical parameters.

The use case is for example a connection creation to a database that can be called from multiple functions at the same time and that may take a while to establish. For example, function1 in on part of the code calls MyClass(‘url1’) and function2 somewhere else calls MyClass(‘url1’) at the same time. I want to be able to avoid creating 2 connections to the database, while still be able to create MyClass(‘url22222’).

The class looks like:

class MyClass {
  constructor(url) {
    this.url = url;
    console.log("Constructing MyClass with", url);
  }
}

new MyClass("url1");
new MyClass("url1");
new MyClass("url22222");

Currently the output looks like:

Constructing MyClass with url1
Constructing MyClass with url1
Constructing MyClass with url22222

The goal is to have an output like:

Constructing MyClass with url1
Constructing MyClass with url22222

Thanks for your help !

I tried to store which url where created in an outside array but it does not look very pretty.
Also had a look at static initializer but it only run once per class regardless of the arguments provided as far as I understand.

Firestore getting docs via query in JS

I followed the firestore documents step by step, but when ı use the function I get the error in catch block. There is no any problem about authentication ı get problem in firestore section but ı didn’t understand the problem.

function signin(email, password) {
    signInWithEmailAndPassword(auth, email, password)
        .then((userCredential) => {
            const usersRef = collection(db, "users");
            const queryRef = query(usersRef, where("access-token", "==", userCredential.uid));
            const querySnapshot = getDocs(queryRef);
            querySnapshot.forEach((doc) => {
              console.log(doc.id, " => ", doc.data());
            })
            document.cookie = "signed-in : true" 
            console.log(document.cookie);
        })
        .catch((error) => {
            const errorCode = error.code;
            if(errorCode === "auth/invalid-credential"){
                toast.error("Yanlış giriş parametreleri girdiniz!");
            }...

this is my code block.

I tried to follow documentation, seen the other questions but couldn’t solve.

menu does not appear on mobile, safari browser

so i have this problem, on Chrome (mobile view) when i click burger menu btn (SVG icon), it shows me menu and other page links (as it should). but on safari it just does not show.

HTML:

    <div class="menuIcon" id="menuIcon">
        <img src="./Icons/menuIcon.svg" alt="burger menu icon">
    </div>
    <div class="closeIcon" id="closeIcon">
        <img src="./Icons/closeIcon.svg" alt="close icon">
    </div>

JS:

    const menuIcon = document.getElementById("menuIcon");
    const closeIcon = document.getElementById("closeIcon");
    const mobileLinks = document.getElementById("mobileLinks");

    menuIcon.addEventListener("click", function(){
        menuIcon.style.display = "none";
        closeIcon.style.display = "block";
        mobileLinks.style.display = "block"
    })

    closeIcon.addEventListener("click", function(){
        menuIcon.style.display = "block";
        closeIcon.style.display = "none";
        mobileLinks.style.display = "none"
    })

i tried clearing cache, did not worked, could not think any other way to make this happen, i want to menu show when i click on menu icon on mobile view safari browser

in safari console, error is: Not allowed to load local resource: file:///favicon.ico

but i dont have favicon linked or anything, just SVG icon.

Expo Router Tab Behavior on Different Device Sizes (Tablet menu bar looks diffrent from phone size)

I am using Expo Router for my application, particularly utilizing tabs for the menu bar. I have a specific styling requirement where icons should appear above the title on smaller phone screens. However, on tablets, the behavior changes to displaying the icon on the left and the title on the right. I would like to maintain the same styling behavior on tablets as well.

Versions:

Expo: ^50.0.14

Expo Router: ^3.4.8

Menu Bar Layout Code:

return (
  <Tabs
    screenOptions={{
      headerShown: true,
      headerTitleAlign: 'center',
      headerTintColor: COLORS.pureWhite,
      headerTitleStyle: {
        fontWeight: 'bold',
        fontSize: SIZES.xLarge,
        paddingBottom: SIZES.xSmall,
      },
      headerBackground: () => (
        <LinearGradient
          style={{ flex: 1 }}
          end={{ x: 1, y: 0.5 }}
          start={{ x: 0, y: 0.5 }}
          colors={[COLORS.lightPurple, COLORS.darkPurple]}
        />
      ),
      tabBarStyle: {
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center',
        height: Platform.OS === 'ios' ? 90 : 70,
        paddingBottom: Platform.OS === 'ios' ? 10 : 0,
      },
      tabBarLabelStyle: {
        fontSize: SIZES.extend.regular,
        fontFamily: 'Urbanist_600SemiBold',
      },
      tabBarInactiveTintColor: COLORS.darkBlack,
      tabBarActiveTintColor: COLORS.brightPurple,
    }}
  >
        <Tabs.Screen
        name="userProfile"
        options={{
          title: 'Profile',
          headerTitle: 'Profile Settings',
          tabBarIcon: ({ focused }: { focused: boolean }) => {
            return <NickName isMenuBar={true} active={focused} />;
          },
        }}
      />
      <Tabs.Screen
        name="index"
        options={{
          headerTitle: 'Broadcast Hub',
          title: 'Go Live',
          tabBarItemStyle: {
            flex: 1.3,
            height: 45,
            borderRadius: 50,
            justifyContent: 'center',
            backgroundColor: isDisabled
              ? COLORS.lightGray
              : COLORS.brightPurple,
          },
          tabBarIconStyle: { display: 'none' },
          tabBarLabelStyle: {
            fontSize: SIZES.extend.medium,
            marginTop: 0,
            marginLeft: 0,
            fontWeight: '600',
            color: COLORS.pureWhite,
            textTransform: 'uppercase',
          },
        }}
        listeners={() => ({
          tabPress: () => {
            handleGoLiveClick();
          },
        })}
      />
      <Tabs.Screen
        name="statistics"
        options={{
          title: 'Statistics',
          tabBarIcon: () => {
            return <Statistics />;
          },
        }}
        listeners={() => ({
          tabPress: ev => {
            ev.preventDefault();
            handleStatisticsClick();
          },
        })}
      />
    
  </Tabs>
);

Request:
Could you please assist me in achieving consistent styling behavior for tabs on both phone and tablet devices? Currently, the styling changes on tablets, and I would like to maintain the icon-above-title style as seen on phones. Any guidance or suggestions on how to achieve this would be greatly appreciated.

Thank you for your assistance.

I expected the menu bar to looks like in mobile (icons above the title)

my js scrolled change background color is not working

My HTML and CSS here, i have try to change the id and it still not working
So i just change the background-color of the navbar just once color and not see through stuff behind it

 <nav id="customNavbar" class="navbar navbar-expand-sm navbar-dark fixed-top navbar-fixed-top">
        <a href="#" class="navbar-brand"><img src="OIG4-removebg-preview.png" class="logo_img">MegaMan</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navLinks" aria-controls="navLinks" aria-expanded="true" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navLinks">
            <ul class="navbar-nav justify-content-center">
                <li class="nav-item">
                    <a href="" class="nav-link active item-color" aria-current="page">Home</a>
                </li>
                <li class="nav-item">
                    <a href="" class="nav-link item-color">About</a>
                </li>
                <li class="nav-item">
                    <a href="" class="nav-link item-color">Community</a>
                </li>
                <li class="nav-item">
                    <a href="" class="nav-link item-color">Support</a>
                </li>
            </ul>
        </div>
    </nav>
    <script>
        $(function () {
  $(document).scroll(function () {
    var $nav = $("customNavbar");
    $nav.toggleClass("scrolled", $(this).scrollTop() > $nav.height());
  });
}); 
    </script>
.navbar.scrolled {
    background-color: #010104;
}

filtering api data in react

So i’m trying to filter my spotify api data from rapid api through a searchbox and got this so far :

import React, { useEffect, useState } from 'react';
import { Box, Stack, Typography, TextField, Button } from '@mui/material';
import { musicOptions, fetchData } from '../utils/fetchData';

function SearchMusic() {
  const [search, setSearch] = useState('');
  const [music, setMusic] = useState([]);
  const [genres, setGenres] = useState([]);

  const handleSearch = async () => {
    if (search) {
      const musicData = await fetchData(
        `https://spotify23.p.rapidapi.com/search?q=${search}`,
        musicOptions
      );

      const searchedMusic = musicData.filter(
        (item) =>
          item.tracks.toLowerCase().includes(search) ||
          item.artists.toLowerCase().includes(search) ||
          item.albums.toLowerCase().includes(search) ||
          item.genres.toLowerCase().includes(search)
      );

      setSearch('');
      setMusic(searchedMusic);
    }
  };

  return (
    <Stack alignItems='center' mt='37px' justifyContent='center' p='20px'>
      <Typography
        fontWeight={700}
        sx={{
          fontSize: { lg: '44px', xs: '30px' },
        }}
        mb='50px'
        textAlign='center'
      >
        Expand Your Music <br />
        Knowledge
      </Typography>
      <Box position='relative' mb='72px'>
        <TextField
          sx={{
            input: {
              fontWeight: '700',
              border: 'none',
              border: '1px solid #082767',
              borderRadius: '4px',
            },
            width: { lg: '1000px', xs: '350px' },
            backgroundColor: '#fff',
            borderRadius: '40px',
          }}
          height='76px'
          value={search}
          onChange={(e) => setSearch(e.target.value.toLowerCase())}
          placeholder='Search Music'
          type='text'
        />
        <Button
          className='search-btn'
          sx={{
            bgcolor: '#082767',
            color: '#fff',
            textTransform: 'none',
            width: { lg: '175px', xs: '80px' },
            fontSize: { lg: '20px', xs: '14px' },
            height: '58px',
            position: 'absolute',
            right: '0',
          }}
          onClick={handleSearch}
        >
          Search
        </Button>
      </Box>
    </Stack>
  );
}

export default SearchMusic;

It keeps giving me this error “musicData.filter is not a function
at handleSearch”.
and i tried using split.(”).filter and it didn’t work too

doees anyone have an idea about what’s going on and how can i fix this?

Understanding Stripe Connect Integration for Donation Module in PHP/Laravel

Problem Overview:

Our platform’s current functionality is to allow companies to register and submit their bank details within the PHP/Laravel framework, bypassing the need for a separate Stripe account. We handle donations by transferring funds directly to the registered company’s bank account. However, we’re seeking assistance in understanding the Stripe Connect integration process to seamlessly incorporate a donation module into our platform.

Manual Company Stripe Account Creation:

  • Can we manually create a company Stripe-connected account without using the standard Stripe onboarding URL?

  • Which Stripe APIs should we use, and in what sequence?

  • What specific details are needed from companies for manual registration, and which APIs should we use in what order?

  • How can we verify a company’s bank account validity and set it as the primary bank for receiving donations?

  • How do we check if a company’s verification process is pending?

Using Stripe’s Onboarding UI:

  • What happens if a company selects a standard account when redirected to the onboarding URL generated by Stripe?

  • What is the process if they opt for an express account and are prompted for essential details like banking and personal information?

  • How do we ensure our platform supports payments in both USD and EUR without requiring companies to create separate Stripe accounts?

Expected Behavior:

  • Companies will register on our platform and connect to our Stripe account without having the stripe account.

  • Users will donate from the client side, and we will handle payout to their bank accounts on their behalf.

Overview of Implementation in Laravel:

We seek guidance on how to execute the functionality seamlessly within the Laravel framework. Any insights or high-level overview would be greatly appreciated.

Chrome Notification Not Showing Message or Handling Buttons Correctly on macOS

I’m developing a Chrome extension using Manifest V3 and using chrome.notifications.create to show notifications to the user. However, I’m facing a couple of issues on macOS:

  • The notification only displays the title, not the message.
  • An unwanted ‘Settings’ button appears in the options, which I didn’t add, and it doesn’t respond when clicked.

Here’s the code snippet that creates the notification:

chrome.notifications.create({
    type: 'basic',
    iconUrl: '/images/icon16.png',
    title: 'Download Notice',
    message: 'You have previously downloaded this file. Do you want to download it again?',
    buttons: [
        {title: 'Yes'},
        {title: 'No'}
    ],
    requireInteraction: true
}, (notificationId) => {
    // Callback code...
});

I have included “notifications” under permissions in my manifest.json and tried shortening the message text, but it still doesn’t show up. This is how the notification appears:
Notification Preview

My questions are:

  • How can I ensure that the message text is displayed in the notification?
  • Is there a way to remove or configure the ‘Settings’ button that appears in the notification options to link to the extension settings page?
  • Are these issues specific to macOS, or are they present in other operating systems as well?

Any help would be greatly appreciated!

Minimize header on sticky scroll is causing flicker in NextJS?

I’m trying to code a sticky header which minimizes on scroll in NextJS. It’s working fine. But there’s a flicker between the transition of header. How can we fix this? Here’s the code:

const [scrolled, setScrolled] = useState(false);

  if(window.screenY > 180){
    const [scrolled, setScrolled] = useState(true);
  }

  useEffect(() => {
    const handleScroll = () => {
    const isScrolled = window.scrollY > 180;
    
    if (isScrolled !== scrolled) {
      setScrolled(!scrolled);
    }
  };
    
  document.addEventListener('scroll', handleScroll);
  
  return () => {
    document.removeEventListener('scroll', handleScroll);
  };
}, [scrolled]);

Header

<header className={`z-50 px-6 lg:px-24 ${scrolled ? 'py-3 md:py-4 backdrop-blur-3xl dark:backdrop-brightness-50 bg-white/30 dark:bg-black/30 border-b border-black/[0.1] dark:border-white/[0.1] sticky top-0' : 'py-5 md:py-7 bg-transparent'}`}>
      <div className='xl:container columns-2 mx-auto flex items-center'>
        <div className={`w-full flex justify-start items-center ${scrolled ? 'h-auto' : 'h-[72px]'}`}>
          <Link href='/' title='Inside Dynamics'>
            {scrolled ? <LogoMini /> : <Logo />}
          </Link>
        </div>
        <div className={`w-full flex justify-end items-center ${scrolled ? 'h-auto' : 'h-[72px] py-6'}`}>
          <menu className='text:black dark:text-white font-light hidden md:block'>
            <li className='inline pb-1 border-primary hover:border-b mr-8 cursor-pointer'><a href='/#services'>Services</a></li>
            <li className='inline pb-1 border-primary hover:border-b mr-8 cursor-pointer'><a href='/#pricing'>Pricing</a></li>
            <li className='inline pb-1 border-primary hover:border-b mr-8 cursor-pointer'><a href='/#reviews'>Reviews</a></li>
            <li className='inline pb-1 border-primary hover:border-b mr-8 cursor-pointer'><a href='/#faq'>FAQ</a></li>
            <li className='inline pb-1 border-primary hover:border-b cursor-pointer'><Link href='/contact'>Contact</Link></li>
          </menu>
          <div className={`flex justify-center items-center ${scrolled ? 'ml-6' : 'ml-8'}`}>
            <ThemeSwitch />
            <button className='border border-neutral-200 hover:bg-neutral-50 active:border-primary dark:border-neutral-500 dark:hover:bg-neutral-950 p-4 ml-3 rounded-full block md:hidden' aria-label='Mobile Menu'>
              <RiMenu4Line className='size-5'/>
            </button>
          </div>
        </div>
      </div>
    </header>

RMarkdown: render JavaScript code chunk console output

I would like to write some JavaScript in RMarkdown and print the results into the knitted document. Is there some simple way to render stuff into the document, e.g. with console.log() calls? I found out I can create new div elements and append them to the document’s DOM, however, that would require a lot of boilerplate as a general solution.

E.g. say I have the following code chunk:

```{js}
function foo() {
   return "foo"
}

console.log(foo())
```

I would like some output chunk like this get rendered below:

> foo

Any ideas?

ExtJS multiple child applications inside primary

I’m trying to use multiple Applications inside one parent Application.

Here is example fiddle like this:

Ext.application({
    name : 'Parent app',
    launch : function() {

        Ext.application({
            name: 'ChildApp1',
            sayHello: function(){
                console.log('ChildApp 1');
            }
        });

        Ext.application({
            name: 'ChildApp2',
            sayHello: function(){
                console.log('ChildApp 2');
            }
        });

But when I’m trying to interact between apps, it seems that last App rewrites whole primary namespace.

I am trying to dynamically access a specific App, but I get only the App created last.

const appName = 'ChildApp1';
Ext.app.Application.instance.getApplication(appName).sayHello(); // calls ChildApp2 method

How is it possible to dynamicly call (I don’t know app name in advance) multiple applications methods from each other ?

Am I right with classes architecture/definition or not?

How to use within a php string?

I am new to php. I wish to store </script> as a string in php. My project involves storing an entire HTML template within a single php string, then printing this string using JavaScript, all withing the same php file. After escaping all characters, I tried to store the code within a string, however the entire thing breaks when I use </script> within the HTML code and try to store it.

<?php 
$htmltemplate='<!DOCTYPE html> ...html code ... </script>...html';
?>

<script>
var h = "<?php echo $htmltemplate;?>";
document.getElementsByClassName("result1")[0].textContent= h;
</script>

This script completely breaks if I don’t give a space(hence invalidate) in between the closing script tag within my HTML template. If I give a space, the entire HTML template code works properly as a string.

I tried using a workaround by using string concatenation as $h="<"."/script>"; however this still ends up breaking. The only thing that works is adding a space between ‘<‘ and the rest of my code, but that wouldn’t be correct. What options do I have?

focus doesn’t start from body of angular component

when i click on a link to navigate to certain page , if i press the tab key, focus starts on a browser elements (search bar), not at the top of a new page like a visually-impaired user would expect even i set the tab-index value?
but it works fine when i reload the page
this is my page component

    @Component({
  selector: 'app-rental-contracts-page',
  template: '<router-outlet></router-outlet>',
  host: {
    class:'lc-grid__item--wrapper'

  }
})
export class RentalContractsPageComponent implements OnInit {

  constructor() { 
  }

  ngOnInit() {
  }

}

and this my module

const routes: Routes = [
  {
    path: '',
    component: RentalContractsPageComponent,
    children: [
      {
        path: '',
        component: RentalContractsListPageComponent,
        data: { title: "Baux" },
      },
      {
        path: 'term/:term',
        component: RentalContractsListPageComponent
      },
      {
        path: 'create',
        component: CreateRentalContractPageComponent
      },
      {
        path: 'create/:ownerId',
        component: CreateRentalContractPageComponent
      }
      ,
      {
        path: 'create/:ownerId/:partId',
        component: CreateRentalContractPageComponent
      }

    ]
  }
];


@NgModule({
  declarations: [RentalContractsPageComponent, CreateRentalContractPageComponent, RentalContractsListPageComponent],
  imports: [
    CommonModule,
    RouterModule.forChild(routes),
    TranslateModule,
    NgbModule,
    FormsModule,
    ContractsModule.forRoot(environment),
  ]
})
export class RentalContractsPageModule { }