I build an app using react native.when I am pulling page in safari browser to down , refresh loader is coming. I dont want pull to refresh loader in safari browser.Can anybody give any suggestions to remove the pull to refresh loader, please.
Category: javascript
Category Added in a WPeMatico Campaign
Gatsby Link absolute path
By using Link component in Gatsby.js I will not be able to directed by clickin on a link to back to previous urls ,
e.g: I have this url site.com/article/id let’s say I am in the id page , so in this case when I use Link I will not be able to go to site.com/article/id2 but instead I will be only be able to go site.com/article/id/article/id2 . How to fix this ?
Regex run test on New regular expression
I’m trying to use the test method on a new regular expression:
const arr = ["g", "e", "g"];
const exp = new RegExp("/^g/");
const filteredArr = arr.filter((item) => exp.test(item))
But the returned array is empty
When I directly run test method on the expression it’s working:
const filteredArr = arr.filter((item) => /^g/.test(item))
I do need to use the new keyword because I would like to run the test with dynamic values instead of “g”. How should I do it?
Customizing query responses with transformResponse
docs aren’t enough clear for me https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#customizing-query-responses-with-transformresponse
I’ve got an API call with createApi
getDashboard: builder.query<DashboardResponse, { id: string }>({
query: params => ({
url: `/v2/companies/${params.id}/dashboard`,
method: 'GET',
params: {
id: params.id
}
}),
})
and response looks like this:
{
"yearly_balance": {
"year": 2022,
"profit": {
"amount": 441394.4,
"currency": "PLN"
},
"loss": {
"amount": 298008.75,
"currency": "PLN"
},
"balance": {
"amount": 143385.65,
"currency": "PLN"
}
},
"current_social_security": {
"date": "2022-05-01",
"due_date": "2022-06-20",
"due_dates_number": 1,
"amount": [
{
"amount": 3066.0,
"currency": "PLN"
}
]
},
"current_taxes": {
"date": "2022-05-01",
"first_due_date": "2022-06-30",
"first_tax_kind": "quarterly",
"due_dates_number": 0,
"sum": [
{
"amount": 0.0,
"currency": "PLN"
}
]
}
}
I need to transform the response from this above to camelCase. I know that I need to add a function transformResponse but honestly I don’t know how it works there. I’m a begginer in redux things.
Recursively convert an object fields from camelCase to UPPERCASE
I have tried to recursively convert an object fields from camelCase to UPPERCASE.
For some reason it wont work, I have tried many different ways from here in stackoverflow.
Would apprecaite for all the help, thanks.
const o = {
KeyFirst: "firstVal",
KeySecond: [
{
KeyThird: "thirdVal",
},
],
KeyFourth: {
KeyFifth: [
{
KeySixth: "sixthVal",
},
],
},
};
function renameKeys(obj) {
return Object.keys(obj).reduce((acc, key) => {
const value = obj[key];
const modifiedKey = `${key[0].toLowerCase()}${key.slice(1)}`;
if (Array.isArray(value)) {
return {
...acc,
...{ [modifiedKey]: value.map(renameKeys) },
};
} else if (typeof value === "object") {
return renameKeys(value);
} else {
return {
...acc,
...{ [modifiedKey]: value },
};
}
}, {});
}
console.log(renameKeys(o));
Someone help me? #JavaScript #VSCode [closed]
I have this question to do:
[…]
Create 2 JavaScript files.
The first one will export a function called “getFlag()”.
This function will receive a parameter of type “string” and must search inside the process.argv array for the desired flag that is the parameter informed and return the value of the flag.
The second will import the function and pass the parameter.
We will run the second file in the terminal, passing the flags “–name” and “–greeting” so that the greeting and the person’s name are printed.
[…]
I need it for a school project, but I couldn’t do it.
Can anyone give me an idea how I could do it?
My react strapi redirect returns a 400 error
I follow the strapi car tutorial in order to learn how to manage my database via react.
In short, I copied the code from the tutorial by following the steps. I made some adjustments.
But here when I confirm the form I get a 400 error (POST http://localhost:1337/api/restaurants 400 (Bad Request)
Off, the quoted link actually works.
I attach the code here. I am a Strapi beginner and I do not understand this problem.
Thanks
import React from 'react';
import axios from 'axios';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
modifiedData: {
name: '',
description: '',
categories: [],
},
allCategories: [],
error: null,
};
}
componentDidMount = async () => {
try {
const response = await axios.get('http://localhost:1337/api/categories');
this.setState({ allCategories: response.data.data });
} catch (error) {
this.setState({ error });
}
};
handleInputChange = ({ target: { name, value } }) => {
this.setState(prev => ({
...prev,
modifiedData: {
...prev.modifiedData,
[name]: value,
},
}));
};
handleSubmit = async e => {
e.preventDefault();
try {
const response = await axios.post(
'http://localhost:1337/api/restaurants',
this.state.modifiedData
);
console.log(response);
} catch (error) {
this.setState({ error });
}
};
renderCheckbox = category => {
const {
modifiedData: { categories },
} = this.state;
const isChecked = categories.includes(category.id);
const handleChange = () => {
if (!categories.includes(category.id)) {
this.handleInputChange({
target: { name: 'categories', value: categories.concat(category.id) },
});
} else {
this.handleInputChange({
target: {
name: 'categories',
value: categories.filter(v => v !== category.id),
},
});
}
};
return (
<div key={category.id}>
<label htmlFor={category.id}>{category.attributes.name}</label>
<input
type="checkbox"
checked={isChecked}
onChange={handleChange}
name="categories"
id={category.id}
/>
</div>
);
};
render() {
const { error, allCategories, modifiedData } = this.state;
if (error) {
return <div>An error occured: {error.message}</div>;
}
return (
<div className="App">
<form onSubmit={this.handleSubmit}>
<h3>Restaurants</h3>
<br />
<label>
Name:
<input
type="text"
name="name"
onChange={this.handleInputChange}
value={modifiedData.name}
/>
</label>
<label>
Description:
<input
type="text"
name="description"
onChange={this.handleInputChange}
value={modifiedData.description}
/>
</label>
<div>
<br />
<b>Select categories</b>
{allCategories.map(this.renderCheckbox)}
</div>
<br />
<button type="submit">Submit</button>
</form>
</div>
);
}
}
export default App;
NgxChartsModule import slows down the page load
I’m using NgxChartsModule in one of the modules which is lazy loaded. The import statement in the example.module.ts is causing severe impact in page load time.
imports: [
CommonModule,
NgxChartsModule
]
I’m only using bar chart and line chart. Is there any way I can import just those two to improve the loading time. Or is there any other way to bypass this issue.
Correct truncation of URL by length
How to truncate encoded URL by max length without make it invalid?
function truncateUrl(url, maxlength) {
return url.substring(0, maxlength)
// Try to remove invalid encoded sectors at the end.
.replace(/(%[0-9A-F]{2}%?[%0-9A-F])$/gi, '');
}
function checkUrl(url) {
try {
decodeURI(url);
return 'VALID: ' + url;
}
catch {
return 'INVALID: ' + url;
}
}
var source = 'https://test.com/uslugi/remont-kvartir/?region_name=%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0%20%D0%B8%20%D0%9C%D0%BE%D1%81%D0%BA%D0%BE%D0%9C';
console.log(checkUrl(truncateUrl(source, 136)));
console.log(checkUrl(truncateUrl(source, 135)));
console.log(checkUrl(truncateUrl(source, 134)));
console.log(checkUrl(truncateUrl(source, 133)));
console.log(checkUrl(truncateUrl(source, 132)));
console.log(checkUrl(truncateUrl(source, 131)));
console.log(checkUrl(truncateUrl(source, 130)));
How to make check to work in all cases?
Add localStorage to this Rich Text Editor
Can you please help me add localStorage thing to the code below. I’m not good at creating Javascript code and still learning about it. The code is located below.
How to create button that runs python code?
I’m learning python currently and I’ve made a password generator. I would like to make it so the script runs when you press a button, so you don’t have to refresh the page to get a new password. I’m not sure where to start so any help would be appreciated.
Below is my python script. I’m using flask.
<py-script>
num = "0123456789"
lowercase = "abcdefghijklmnopqrstuvwxyz"
uppercase = lowercase.upper()
special = "!@#$%^&*()_+~`|}{[]:;?><,. /-="
all = num+lowercase+uppercase+special
from random import choice
password = "".join(
choice(all) for i in range(16)
)
print (password)
</py-script>
How to use or create functionality of a BaseOpenTelemetryComponent for functional components?
This library: https://www.npmjs.com/package/@opentelemetry/plugin-react-load, works only in Class-based react components. Can anyone guide how to use or create similar functionality for functional-based components?
I have also gone through openTelemetry issues, and found out here: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/178 That this functionality is missing, but any suggestions on how to achieve this?
why jquery timedatepicker is not taking the data we had clicked i safari browser only
In jQuery datetime picker the data and time is not taking and also not allowing the data in safari browser only. The datetime picker is working fine in all browsers except the safari browser.
Is there any documentation that only related to safari browser only.
Mark clicked menu item as active
So I was wondering how to make the menu item that has been clicked, shown as ‘active’/’highligted’, so the user can see which page they are on?
I’ve made this menu bar.
/* Add a black background color to the top navigation */
.topnav_menu {
background-color: #333;
overflow: hidden;
display: flex;
align-items: center;
}
/* Style the links inside the navigation bar */
.topnav_menu a {
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
cursor: pointer;
}
/* Change the color of links on hover */
.topnav_menu a:hover,
.engine_dropdown:hover .engine_dropbtn {
background-color: #ebebeb;
color: black;
}
/* Add a color to the active/current link */
.topnav_menu a.active {
background-color: #197cd8;
color: white;
}
<div class="topnav_menu">
<a href="#profile">Profile</a>
<a href="#index">Test Runs</a>
<a href="#dashboard">Dashboard</a>
<a href="#dbOperations">TRT Tools</a>
</div>
After the item has been clicked it should appear highlighted.
Popup modal for adblock
Hi i just want a popup modal for a javascripts , it usually detects the adblockers and tell them to disable the adblocker before entering the site , i got this code from codepen and it sayys attach your own popup modal except javascript so can i get any help who can add me a simple popup modal css for this script link to the main script – https://codepen.io/WebDEasy/pen/dxoaWB
setTimeout(function() {
var adblockEnabled = false;
// add test element and get its styles
document.body.innerHTML += '<div class="adsbygoogle" id="ad-detector"></div>';
var adElement = document.getElementById('ad-detector');
var adElementStyle = getComputedStyle(adElement, null);
if(adElementStyle.display === 'none') { // Adblock enabled
document.getElementsByClassName('message')[0].innerHTML = 'Adblock detected!';
document.getElementsByClassName('message')[0].classList.add('ab');
} else { // Adblock disabled
document.getElementsByClassName('message')[0].innerHTML = 'Adblock disabled! :)';
document.getElementsByClassName('message')[0].classList.add('no-ab');
}
}, 1500);