Telash
Telash
RReactiflux
Created by Telash on 9/8/2024 in #react-forum
Why the left code isn't working but the right one is?
Turns out I was returning an object and I must wrap it with something in order to make the jsx work
4 replies
RReactiflux
Created by Telash on 7/18/2024 in #react-forum
How can I exclude the street name out of the string this component give me?

import React, { useState, useRef } from 'react';
import {
useLoadScript,
Autocomplete,
} from '@react-google-maps/api';
import { ConstructionOutlined } from '@mui/icons-material';

const libraries = ['places'];

const GoogleMapsDropdown = ({
setHotelForTransfer,
placeInList,
hotelForTransfer,
setIsEnglishOnlyToggle,
handleFieldChange,
typeOfTransfer,
initialValue,
isValid,
equalDepartureHotelValue,
setTimeToRenderBasedOnArrival,
hotelForDepartureRefs,
setHotelForDepartureRefs,
testDispatch
}) => {
const [location, setLocation] = useState(initialValue);
const autocompleteRef = useRef(null);

const handlePlaceSelected = () => {
const newValue = autocompleteRef.current.value;
setLocation(newValue); // Update state with the selected value
alterTabHotelField(newValue);
isEnglishOnlyInput(newValue);
};

function testDeptRefs(newValue) {
const newArrayOfRefs = [...hotelForDepartureRefs];
newArrayOfRefs[placeInList] = newValue;
setHotelForDepartureRefs(newArrayOfRefs);
}

function alterTabHotelField(newValue) {
const e = { target: { value: newValue || "", name: "hotel" } };
handleFieldChange(e, placeInList, typeOfTransfer);
if (typeOfTransfer === "arr") {
handleFieldChange(e, placeInList, "dept");
}
}

function isEnglishOnlyInput(content) {
// setIsEnglishOnlyToggle
const pattern = /^[!@#\$%\^\&*\)\(+=._-\s0-9a-zA-Z`~\[\]\{\}:;"'<>,./?\\|]*$/;




if (pattern.test(content)) {
testDispatch(placeInList, true)
} else {
testDispatch(placeInList, false)
}

}


return (
<><Autocomplete onPlaceChanged={handlePlaceSelected}>
<input
className={(isValid === false && initialValue === '') ? 'hotel-search-input-invalid' : 'hotel-search-input'}
value={typeOfTransfer === "arr" ? location : hotelForDepartureRefs[placeInList]}
ref={autocompleteRef}
onChange={(event) => {

setLocation(event.target.value);
alterTabHotelField(event.target.value);
isEnglishOnlyInput(event.target.value);
}} // Update state and call alterTabHotelField
inputProps={{
placeholder: 'test',
}}
/>
</Autocomplete>
{/* <button type="button" onClick={() => testDispatch()}>Test dispatch</button> */}
</>

);
};

export default function App({
setHotelForTransfer,
placeInList,
hotelForTransfer,
handleFieldChange,
typeOfTransfer,
initialValue,
isValid,
equalDepartureHotelValue,
setTimeToRenderBasedOnArrival,
hotelForDepartureRefs,
setHotelForDepartureRefs,
setIsEnglishOnlyToggle,
testDispatch
}) {
const { isLoaded } = useLoadScript({
googleMapsApiKey: '',
libraries,
});

return (
<div ref={isLoaded ? mapContainerStyle : null}>
{isLoaded && (
<GoogleMapsDropdown
setHotelForTransfer={setHotelForTransfer}
placeInList={placeInList}
hotelForTransfer={hotelForTransfer}
handleFieldChange={handleFieldChange}
typeOfTransfer={typeOfTransfer}
initialValue={initialValue}
isValid={isValid}
equalDepartureHotelValue={equalDepartureHotelValue}
setTimeToRenderBasedOnArrival={setTimeToRenderBasedOnArrival}
hotelForDepartureRefs={hotelForDepartureRefs}
setHotelForDepartureRefs={setHotelForDepartureRefs}
setIsEnglishOnlyToggle={setIsEnglishOnlyToggle}
testDispatch={testDispatch}
/>
)}
</div>
);
}

// Optional styling for the map container (can be customized)
const mapContainerStyle = {
width: '400px',
height: '400px',
};

import React, { useState, useRef } from 'react';
import {
useLoadScript,
Autocomplete,
} from '@react-google-maps/api';
import { ConstructionOutlined } from '@mui/icons-material';

const libraries = ['places'];

const GoogleMapsDropdown = ({
setHotelForTransfer,
placeInList,
hotelForTransfer,
setIsEnglishOnlyToggle,
handleFieldChange,
typeOfTransfer,
initialValue,
isValid,
equalDepartureHotelValue,
setTimeToRenderBasedOnArrival,
hotelForDepartureRefs,
setHotelForDepartureRefs,
testDispatch
}) => {
const [location, setLocation] = useState(initialValue);
const autocompleteRef = useRef(null);

const handlePlaceSelected = () => {
const newValue = autocompleteRef.current.value;
setLocation(newValue); // Update state with the selected value
alterTabHotelField(newValue);
isEnglishOnlyInput(newValue);
};

function testDeptRefs(newValue) {
const newArrayOfRefs = [...hotelForDepartureRefs];
newArrayOfRefs[placeInList] = newValue;
setHotelForDepartureRefs(newArrayOfRefs);
}

function alterTabHotelField(newValue) {
const e = { target: { value: newValue || "", name: "hotel" } };
handleFieldChange(e, placeInList, typeOfTransfer);
if (typeOfTransfer === "arr") {
handleFieldChange(e, placeInList, "dept");
}
}

function isEnglishOnlyInput(content) {
// setIsEnglishOnlyToggle
const pattern = /^[!@#\$%\^\&*\)\(+=._-\s0-9a-zA-Z`~\[\]\{\}:;"'<>,./?\\|]*$/;




if (pattern.test(content)) {
testDispatch(placeInList, true)
} else {
testDispatch(placeInList, false)
}

}


return (
<><Autocomplete onPlaceChanged={handlePlaceSelected}>
<input
className={(isValid === false && initialValue === '') ? 'hotel-search-input-invalid' : 'hotel-search-input'}
value={typeOfTransfer === "arr" ? location : hotelForDepartureRefs[placeInList]}
ref={autocompleteRef}
onChange={(event) => {

setLocation(event.target.value);
alterTabHotelField(event.target.value);
isEnglishOnlyInput(event.target.value);
}} // Update state and call alterTabHotelField
inputProps={{
placeholder: 'test',
}}
/>
</Autocomplete>
{/* <button type="button" onClick={() => testDispatch()}>Test dispatch</button> */}
</>

);
};

export default function App({
setHotelForTransfer,
placeInList,
hotelForTransfer,
handleFieldChange,
typeOfTransfer,
initialValue,
isValid,
equalDepartureHotelValue,
setTimeToRenderBasedOnArrival,
hotelForDepartureRefs,
setHotelForDepartureRefs,
setIsEnglishOnlyToggle,
testDispatch
}) {
const { isLoaded } = useLoadScript({
googleMapsApiKey: '',
libraries,
});

return (
<div ref={isLoaded ? mapContainerStyle : null}>
{isLoaded && (
<GoogleMapsDropdown
setHotelForTransfer={setHotelForTransfer}
placeInList={placeInList}
hotelForTransfer={hotelForTransfer}
handleFieldChange={handleFieldChange}
typeOfTransfer={typeOfTransfer}
initialValue={initialValue}
isValid={isValid}
equalDepartureHotelValue={equalDepartureHotelValue}
setTimeToRenderBasedOnArrival={setTimeToRenderBasedOnArrival}
hotelForDepartureRefs={hotelForDepartureRefs}
setHotelForDepartureRefs={setHotelForDepartureRefs}
setIsEnglishOnlyToggle={setIsEnglishOnlyToggle}
testDispatch={testDispatch}
/>
)}
</div>
);
}

// Optional styling for the map container (can be customized)
const mapContainerStyle = {
width: '400px',
height: '400px',
};
5 replies
RReactiflux
Created by Telash on 2/27/2024 in #help-js
telash – 16-40 Feb 27
Like, arr1=[1,2,3] arr2=arr1 in order to pop 3 from arr1, i can now do arr2.pop(), but why? i can simply do arr1.pop()
6 replies
RReactiflux
Created by Telash on 2/27/2024 in #help-js
telash – 16-40 Feb 27
Like, why in order to change arr1 I would want to make another variable
6 replies
RReactiflux
Created by Telash on 2/27/2024 in #help-js
telash – 16-40 Feb 27
Yeah I know that, im asking why pass by reference exist, instead of that, simply use the first variable that you referencing
6 replies
RReactiflux
Created by Telash on 6/13/2023 in #react-forum
ugh, how do I center an image to fit its parent div? I tried many things
Uhh thanks, didnt expect someone to answer after this long lol
5 replies
RReactiflux
Created by Telash on 9/28/2023 in #react-forum
SPA or not
Can you give me an example?
4 replies
RReactiflux
Created by Telash on 9/19/2023 in #react-forum
Should I pass props or use imports inside the component?
In this case
20 replies
RReactiflux
Created by Telash on 9/19/2023 in #react-forum
Should I pass props or use imports inside the component?
I also think props is silly coz more code
20 replies
RReactiflux
Created by Telash on 9/19/2023 in #react-forum
Should I pass props or use imports inside the component?
Ok, ty:>
20 replies
RReactiflux
Created by Telash on 9/19/2023 in #react-forum
Should I pass props or use imports inside the component?
Changing at runtime meaning?
20 replies
RReactiflux
Created by Telash on 9/19/2023 in #react-forum
Should I pass props or use imports inside the component?
They can be props, idk which way is best
20 replies
RReactiflux
Created by Telash on 9/19/2023 in #react-forum
Should I pass props or use imports inside the component?
Responded in 4s
20 replies
RReactiflux
Created by Telash on 9/19/2023 in #react-forum
Should I pass props or use imports inside the component?
Bro did you just
20 replies
RReactiflux
Created by Telash on 9/19/2023 in #react-forum
Should I pass props or use imports inside the component?
Same arrows images that flips between 3 images
20 replies