I have several elements on a page, some have z-index explicitly written in their CSS and some have not. Is it possible to get their z-index order to, for instance, attach a data-z-index to each element? It is not a problem if the original z-index is override by a new order.
Category: javascript
Category Added in a WPeMatico Campaign
My app hungs wen make a new fetch request from a custom hook
the app is supossed to make an API request from an user input, i created a custom hook to handle the logic on the first render with the default value it renders the info but after the form submits and gives the new handler it freezes you can watch it live in this code sandbox: https://vy0ll7.csb.app/search
import { Link } from "react-router-dom";
import { useRef} from "react";
import Card from "../components/Card";
import useSearch from "../hooks/useSearch";
import { useSingleMeal } from "../hooks/useSingleMeal";
const SearchMeal = () => {
const inputRef = useRef("");
const { data, error, loading, setAPI_URL } = useSearch();
const { setSingleMeal } = useSingleMeal();
const handleSubmit = (e) => {
e.preventDefault();
let searchTerm = `https://www.themealdb.com/api/json/v1/1/search.php?s=${inputRef.current.value.replace(
" ",
"-"
)}`;
setAPI_URL(searchTerm);
inputRef.current.value = "";
};
if (error) return <h1>no matches ,{error.message}</h1>;
return (
<section>
<h1>search Meal </h1>
<form onSubmit={handleSubmit}>
<input type="text" name="search" ref={inputRef} />
<button>search</button>
</form>
{loading && <p>loading...</p>}
<menu className="grid">
<Link to="/single">
<Card title={data[0]} onClick={() => setSingleMeal(data[0])} />
</Link>
</menu>
</section>
);
};
export default SearchMeal;
and heres the hook
import { useState, useEffect } from "react";
const useSearch = () => {
const [data, setData] = useState([]);
const [error, setError] = useState(null);
const [loading, setLoading] = useState(false);
const [API_URL, setAPI_URL] = useState(
`https://www.themealdb.com/api/json/v1/1/search.php?s=alfredo`
);
const getIngredients = (arr) => {
let y = [],
i = 1;
while (
arr[`strIngredient${i}`] !== null &&
arr[`strIngredient${i}`] !== ""
) {
y = [
...y,
{ ingredient: arr[`strIngredient${i}`], amount: arr[`strMeasure${i}`] }
];
i++;
}
return y;
};
useEffect(() => {
let array = new Array(1);
const fetchItems = async () => {
try {
setLoading(true);
let response = await fetch(API_URL);
if (!response.ok) throw Error("did not receive expected data");
let listItems = await response.json();
// 1 title, 2 image, 3 instructions, 4 ingredients
return [
listItems?.meals[0]?.strMeal,
listItems?.meals[0]?.strMealThumb,
listItems?.meals[0]?.strInstructions,
getIngredients(listItems?.meals[0])
];
} catch (err) {
setError(err);
} finally {
setLoading(false);
}
};
for (let i = 0; i < array.length; i++) {
array[i] = fetchItems();
}
setData(array);
}, [API_URL]);
return { data, error, loading, setAPI_URL };
};
export default useSearch
getting the length of an array of elements when the number can change (adding or removing elements)
So I don’t have code for the question but Im curious to know if i wanted to create a ul of li’s and want to add and remove the li’s, I know the number of li’s will be dynamic. So how do I get the number of li’s (array indexes) when its adding or removing. I have tried doing
const len = document.querySelectorAll(“li”) and this will only return the length of the array static, if I add or remove li’s it wont change the length of the array
Copy Image Google Apps Script
I built a script that copies the contents of document A and pastes it into a new document, document X. Document B,C,D etc are also copied into document X. All the contents copy over great and everything works wonderfully. However, I recently added an image to document A that isn’t copying over correctly. The image does show up in the new document (document x), but instead of showing the actual image it just shows a gray box with a caution triangle in it. I’ve attached a screenshot of the before and after.
Any tips for getting the image to copy over correctly?
Here’s the code:
//Now let's use an array to create a list of optional documents we want to assemble.
// We know the cover page is always first so let's add it as the first element of the array.
var listofDocs = new Array(newDoc.getId())
...
//log the array which you've built
console.log("List of docs are: "+listofDocs)
// Now take the array of documents we created, and add their elements to the newDoc one element at a time and one doc at a time.
// Open up the coverpage and tell the system to look at the body of the doc
var basedoc = DocumentApp.openById(listofDocs[0])
var body = basedoc.getBody()
//Open the specified document from listofDocs (one at a time),append each element onto the newDoc one at a time.
for (var i = 1; i < listofDocs.length; ++i){
console.log("looking for elements in: "+ DriveApp.getFileById(listofDocs[i]))
var otherBody = DocumentApp.openById(listofDocs[i]).getBody()
var totalElements = otherBody.getNumChildren()
for (var j=0; j < totalElements; ++j){
var element = otherBody.getChild(j).copy()
var type = element.getType()
console.log("Found an element. Type: "+ type +" in doc: "+ listofDocs[i])
if (type == DocumentApp.ElementType.PARAGRAPH) body.appendParagraph(element)
else if (type== DocumentApp.ElementType.TABLE) body.appendTable(element)
else if (type == DocumentApp.ElementType.LIST_ITEM) body.appendListItem(element)
- The image was originally a “wrapped” image. I changed it to “inline” thinking that may help, but no luck.
- I tried adding the following code, but this had no effect.
else if (type == DocumentApp.ElementType.INLINE_IMAGE) body.appendImage(element)
Is there a way to remove Maybe and Scalars with GraphQl Codegen?
I’m using GraphQl Codegen with the typescript and typescript-operations plugins, but the file generated contains a tone of Maybe and Scalars making the file look very messy.
export type Formation = {
availability?: Maybe<Scalars['String']>;
certificate?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
id: Scalars['ID'];
imageId?: Maybe<Scalars['ID']>;
imageUrl?: Maybe<Scalars['String']>;
languageIds?: Maybe<Array<Scalars['ID']>>;
languages?: Maybe<Array<Maybe<Taxonomy>>>;
levelId?: Maybe<Scalars['ID']>;
location?: Maybe<Taxonomy>;
locationId?: Maybe<Scalars['ID']>;
objective?: Maybe<Scalars['String']>;
professionIds?: Maybe<Array<Scalars['ID']>>;
requirementIds?: Maybe<Array<Scalars['ID']>>;
sectorIds?: Maybe<Array<Scalars['ID']>>;
tagIds: Array<Scalars['ID']>;
title: Scalars['String'];
typeId?: Maybe<Scalars['ID']>;
updatedAt: Scalars['String'];
urlFormation?: Maybe<Scalars['String']>;
};
Is it possible to output the primitive type:
string | null
Instead of:
Maybe<Scalars["String"]>
Thanks!
Error when update @adonisjs/ally version 2.1.3 to 4.1.3
After I updated @adonisjs/ally version from 2.1.3 to 4.1.3 and then I got error Cannot find module 'Model. I comment AllyProvider line and run again, It’s not error but I can’t login both facebook and google. I’m not sure, I do something wrong. (I use adonis 4.1.0) Thank for your suggestion. I spend many time for update adonisjs ally version to 4.1.3
JavaScript Function not getting any values from WordPress form SELECT element
I’m having a difficulty with WordPress form.
I am writing a code which will be working based on entries from WordPress form. But the issue is when I try passing values from the form to JS function using HTML, it works perfectly. But when I try to upload the script files and link the script file with form, then the issue begins.
HTML code
<select name='city' class='city' id="field_cityname-0">
<option value>Location</option>
<option value='Option 1'>Option 1</option>
<option value='Option 2'>Option 2</option>
<option value='Option 3'>Option 3</option>
<option value='Option 4'>Option 4</option>
<option value='Option 5'>Option 5</option>
<option value='Option 6'>Option 6</option>
<option value='Option 7'>Option 7</option>
</select>
JS Function
var map;
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
//map settings
});
let markers = [];
const cities = {
//Map markers
};
const addmarker = (lat, lng, name ) => {
return new google.maps.Marker({
});
};
//Test function for check values passing or not
var newElement = document.getElementById("field_cityname-0");
newElement.addEventListener('change', function(){
console.log(this.value + " city selected");
});
document.querySelector('#field_cityname-0').addEventListener('change', function(e) {
e.preventDefault();
if( this.value != '' && cities.hasOwnProperty( this.value ) ) {
markers.forEach( mkr => mkr.setMap( null ) );
let obj = cities[ this.value ];
markers.push( addmarker( obj.lat, obj.lng, obj.name ) );
console.log("The city is "+this.value);
return true;
}
alert('Oh no ' + this.value + ' not found')
})
}
window.initMap = initMap;
With HTML select element, I changed the //Test function position from inside to outside the initMap function or from outside to inside, it worked perfectly. Passed values properly.
But with WordPress form if I change the position of //Test function from inside to outside the initMap function, the JS code received the data from form SELECT element. But if I put the //Test function again inside of the initMap function, it’s not working. No values receiving from Form and I can’t figure out why.
Is there a any way to pass the values when using with WordPress form?
field_cityname-0 is the id of WordPress form select element.
Type ‘string’ is not assignable to type ‘PostCard Layout’ when I am trying to assign it to @Input
I’m getting the error
Type ‘string’ is not assignable to type ‘PostCard Layout’
In my html component when I try to set the class styling variables from the class component is when it errors out for me. Happening with the @Input() layout: PostCardLayout; section.
I found what I would feel as a dirty fix but will prob allow me to make more mistakes in the future by going into to the tsconfig.json file and setting "strictInputTypes": false,
import { Component, HostBinding, Input } from '@angular/core';
export type PostCardLayout = 'list' | 'grid' | 'grid-sm';
@Component({
selector: 'app-post-card',
templateUrl: './post-card.component.html',
styleUrls: ['./post-card.component.scss']
})
export class PostCardComponent {
@Input() post;
@Input() layout: PostCardLayout;
@HostBinding('class.post-card') classPostCard = true;
@HostBinding('class.post-card--layout--list') get classPostCardLayoutList(): boolean {
return this.layout === 'list';
}
@HostBinding('class.post-card--layout--grid') get classPostCardLayoutGrid(): boolean {
return this.layout === 'grid';
}
@HostBinding('class.post-card--layout--grid-sm') get classPostCardLayoutGridSm(): boolean {
return this.layout === 'grid-sm';
}
constructor() { }
}
Here is the HTML component
<app-post-card
[post]="post"
[layout]="{
classic: 'grid',
list: 'list',
grid: 'grid-sm'
}[layout]"
></app-post-card>
HTML Button, Controls disabled/inactive in grid-container
New to HTML,JavaScript, CSS. This is first time i have ever asked for help online.
I can’t understand why all my controls are inactive in this CSS Tab container. The code works fine switching between tabs, but none of the button or controls are clickable. Sure I’m overlooking something easy..
I really would appreciate anyone’s help!
Full index page…
<!DOCTYPE html>
<html>
<head>
<title id = "DeviceNameP">Test System</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial; background: linear-gradient(to bottom right, #0066cc 0%, #ffffff 100%) fixed;}
.caret {
width: 0;
height: 0;
display: inline-block;
border: 6px solid transparent;
}
.caret.down{
border-top-color: black; position: relative; top: 5px;
}
.caret.right{
border-left-color: black;
}
.caret.up{
border-bottom-color: black;
}
.caret.left{
border-right-color: black;
}
hr { display: block; margin-before: 0.5em; margin-after: 0.5em; margin-start: auto; margin-end: auto; overflow: hidden; border-style: inset; border-width: 1px;}
.item1 { grid-area: header; }
.item2 { grid-area: menu; border-bottom: 1px solid #ccc;}
.item3 { grid-area: main; height:1fr; border-left: 1px solid #ccc; border-right: 2px solid #ccc; overflow: auto;}
.item4 { grid-area: right; height:1fr; overflow: auto; }
.item5 { grid-area: footer; border-top: 1px solid #ccc;}
.grid-container {
display: grid;
grid-template-columns: 1.5fr 1fr;
grid-template-rows: 75px 35px auto 25px;
grid-template-areas:
'header header '
'menu menu '
'main right'
'footer footer';
grid-gap: 0px;
background-color: inherit; /* 2196F3 the tab */
padding: 4px 4px;
/* width: 100vw; */
/* height: 100vh; */
}
.grid-container div {
background-color: inherit;
text-align: left;
padding: 0px 4px;
font-size: 12px;
}
.grid-container iframe {display:block; width: 100%; height: 500px; border: none; margin: 0; padding:4px 0px;}
@media only screen and (orientation: portrait ) {
.grid-container {
grid-template-rows: 75px 35px auto auto 25px;
grid-template-areas:
'header header '
'menu menu '
'main main'
'right right'
'footer footer';
}
.item4 { border: 3px solid yellow; padding-before: 5px;}
}
/* Style the tab */
.tab {
overflow: hidden;
border: none;
}
/* Style the buttons inside the tab */
.tab button {
background-color: #inherate;
float: left;
border: 1px solid #ccc;;
outline: none;
cursor: pointer;
padding: 4px 16px;
transition: 0.3s;
font-size: 14px;
border-radius: 8px 8px 0px 0px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #66ff66;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: none;
}
</style>
</head>
<body>
<div class="grid-container">
<div class="item1" >
<div>
<h2 id="DeviceName" >Device Name</h2>
<img src="{{url_for('static', filename='logo.png')}}" style="position: absolute; top: 0px; right: 0; width: 50px;height: 50px; border: none;"></img>
</div>
</div>
<div class="item2">
<div class="tab">
<button id = "Start_Tab" class="tablinks" onclick="openStatusTab(event, 'Status')">Device Status</button>
<button class="tablinks" onclick="openSettingsTab(event, 'Settings')">Device Settings</button>
<button class="tablinks" onclick="openTab(event, 'Network') ">User Access </button>
</div>
</div>
<div class="item3">
<div id="Status" class="tabcontent" >
<h3>Settings</h3>
<div>
<div style="margin-top:10 px">
<label> </label> <br>
<button id = "Save_Button" onclick="SaveValues()" >Save Changes</button>
<button id = "Cancel_Button" onclick="FillValues()">Cancel</button>
<button id = "Restart_Button" onclick="DoCommand('Restart','')">Restart Device</button>
<button id = "RestartDef_Button" onclick="DoCommand('Restart','ResetDefaults')">Reset To Defaults</button>
<label> </label> <br>
</div>
</div>
</div>
</div>
<div class="item3">
<div id="Settings" class="tabcontent">
<style>
table.input td.desc {text-align: right; }
table.input td.ip {text-align: right; width: 10px; }
</style>
<div>
<div style="margin-top:10 px">
<label> </label> <br>
<button id = "Save_Button" onclick="SaveValues()" >Save Changes</button>
<button id = "Cancel_Button" onclick="FillValues()">Cancel</button>
<button id = "Restart_Button" onclick="DoCommand('Restart','')">Restart Device</button>
<button id = "RestartDef_Button" onclick="DoCommand('Restart','ResetDefaults')">Reset To Defaults</button>
<label> </label> <br>
</div>
<h3 style="margin-bottom: 2px;">Device Settings</h3>
<table class="input" style= "border: 1px solid #ccc;">
<tr>
<td class="desc"><label>Location Name:</label> </td> <td><input type="text" class="VText" id="LocationName_V" ></td>
</tr>
<tr>
<td class="desc"><label>Device Name:</label></td> <td><input type="text" class="VText" id="DeviceName_V";></td>
</tr>
</table>
<hr>
<h3 style="margin-bottom: 2px;">Device Type</h3>
<table class="input" style= "border: 1px solid #ccc;">
<tr>
<td class="desc"><label>Device Type:</label></td>
<td>
<select id="DeviceType_V" class="VText">
<option value="0">Gate Access</option>
<option value="1">Countdown Timer</option>
<option value="2">Vending Machine</option>
<option value="3">Access Period</option>
<option value="4">Access Period (Scan In/Scan Out)</option>
</select>
</td>
</tr>
<tr>
<td class="desc"><label>Timer (sec):</label> </td>
<td><input type="number" class="VText" id="TimerSec_V"; value="15" ></td>
</tr>
<tr>
<td class="desc"><label >Cost$:</label> </td>
<td><input type="number" class="VText" id="TimerSec_V"; value="0.00" ></td>
</tr>
</table>
</div>
</div>
</div>
<div class="item3">
<div id="Network" class="tabcontent" >
<style>
table.input td.desc {text-align: right; }
table.input td.ip {text-align: right; width: 10px; }
</style>
</div>
</div>
<div class="item4">
<div id="StatusHelp" class="tabcontent" >
<h3>Settings description</h3>
{% include 'StatusHelp.html' %}
</div>
</div>
<div class="item4">
<div id="SettingsHelp" class="tabcontent">
<h3>Settings description</h3>
{% include 'SettingsHelp.html' %}
</div>
</div>
<div class="item4">
<div id="NetworkHelp" class="tabcontent" >
<h3>Network</h3>
{% include 'NetworkHelp.html' %}
</div>
</div>
<div class="item5">Footer</div>
</div>
<script>
function openStatusTab(evt, TabName) {
Hidesections();
document.getElementById(TabName + "Help").style.display = "block";
document.getElementById(TabName).style.display = "block";
evt.currentTarget.className += " active";
//document.getElementById(TabName).innerHTML = "";
//GetinnerHTML(TabName);
//GetinnerHTMLHelp(TabName);
}
function openSettingsTab(evt, TabName) {
Hidesections();
document.getElementById(TabName + "Help").style.display = "block";
document.getElementById(TabName).style.display = "block";
console.log(evt.currentTarget.className);
evt.currentTarget.className += " active";
//LoadSettings();
//FillValues();
//GetinnerHTML(TabName);
//GetinnerHTMLHelp(TabName);
}
function openTab(evt, TabName) {
Hidesections();
document.getElementById(TabName + "Help").style.display = "block";
document.getElementById(TabName).style.display = "block";
evt.currentTarget.className += " active";
//GetinnerHTMLHelp(TabName);
}
function GetinnerHTML(TabName) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(TabName).innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "/" +TabName + ".html", true);
xmlhttp.send();
}
function GetinnerHTMLHelp(TabName) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(TabName + "Help").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "/" +TabName + "Help.html", true);
xmlhttp.send();
}
function Hidesections()
{
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
}
var myObj;
function LoadSettings() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myObj = JSON.parse(this.responseText);
document.getElementById("DeviceName").innerHTML = "Device Name:" + myObj.DeviceName;
document.getElementById("DeviceNameP").innerHTML = myObj.DeviceName;
//document.getElementById("DeviceNameP").innerHTML = myObj.Testing;
}
};
xmlhttp.open("GET", "/API/GetSettings", true);
xmlhttp.send();
}
//window.onload = LoadSettings();
document.getElementById("Start_Tab").click();
function FillValues()
{
var i, ValueFields, tablinks;
ValueFields = document.getElementsByClassName("VText");
for (i = 0; i < ValueFields.length; i++) {
// console.log(ValueFields[i].id);
// console.log(ValueFields[i].id.substr(ValueFields[i].id.length - 2 ));
// console.log(myObj.hasOwnProperty(ValueFields[i].id.substr(0,ValueFields[i].id.length - 2 )));
// console.log(Object.keys(myObj));
if(ValueFields[i].id != "" && ValueFields[i].id.endsWith("_V") && myObj.hasOwnProperty(ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )))
{
ValueFields[i].value = myObj[ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )];
ValueFields[i].name = 'Name' + i;
ValueFields[i].autocomplete = 'off';
}
}
ValueFields = document.getElementsByClassName("VCheck");
for (i = 0; i < ValueFields.length; i++) {
if(ValueFields[i].id != "" && ValueFields[i].id.endsWith("_V") && myObj.hasOwnProperty(ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )))
{
ValueFields[i].checked = (myObj[ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )] == 'true');
ValueFields[i].name = 'NameCheck' + i;
ValueFields[i].autocomplete = 'off';
}
}
}
function SaveValues()
{
var i, ValueFields, tablinks;
ValueFields = document.getElementsByClassName("VText");
for (i = 0; i < ValueFields.length; i++) {
if(ValueFields[i].id != "" && ValueFields[i].id.endsWith("_V") && myObj.hasOwnProperty(ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )))
{
myObj[ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )] = ValueFields[i].value;
}
}
ValueFields = document.getElementsByClassName("VCheck");
for (i = 0; i < ValueFields.length; i++) {
if(ValueFields[i].id != "" && ValueFields[i].id.endsWith("_V") && myObj.hasOwnProperty(ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )))
{
if(ValueFields[i].checked)
myObj[ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )] = 'true';
else
myObj[ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )] = 'false';
}
}
console.log(myObj);
var xhr = new window.XMLHttpRequest()
xhr.open('POST', '/API/savesettings', true)
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
xhr.send(JSON.stringify(myObj))
}
function DoCommand(Action,Command)
{
/* var i, ValueFields, tablinks;
ValueFields = document.getElementsByClassName("VText");
for (i = 0; i < ValueFields.length; i++) {
if(ValueFields[i].id != "" && ValueFields[i].id.endsWith("_V") && myObj.hasOwnProperty(ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )))
{
myObj[ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )] = ValueFields[i].value;
}
}
ValueFields = document.getElementsByClassName("VCheck");
for (i = 0; i < ValueFields.length; i++) {
if(ValueFields[i].id != "" && ValueFields[i].id.endsWith("_V") && myObj.hasOwnProperty(ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )))
{
if(ValueFields[i].checked)
myObj[ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )] = 'true';
else
myObj[ValueFields[i].id.substr(0,ValueFields[i].id.length -2 )] = 'false';
}
}
*/
var myCod = { Action , Command};
console.log(myCod);
var xhr = new window.XMLHttpRequest()
xhr.open('POST', '/API/Command', true);
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
xhr.send(JSON.stringify(myCod));
<!-- if(Action == "Restart" ) location.reload(); -->
}
</script>
</body>
</html>
Why google translate is no showing in extension google, but on local site it is showing?
my code:
<div id="google_translate_element"></div>
<script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'pl'
}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
On local site it it showing:
but not in the extension:
Someone can explain me why? And how can I add it to popup extension?
ReferenceError: window is not defined in JavaScript
Redux Reducer Array – Find Object Matches and Merge SubArray Properties
I am building a keyword generator for an app, where it takes in a list of cities and generates those cities meshed into keyword groups by category.
I have tried doing a few other options with .map on the state and .find to get the matches, but I am struggling with properly merging things to look like my final solution. Any references or help to getting it done would be greatly appreciated.
const generatedKeywords = (state = [], action) => {
switch (action.type) {
case types.KEYWORD_GENERATOR_TOOL_ADD_GENERATED_KEYWORDS: {
return [...state, ...action.payload];
}
default: {
return state;
}
}
};
I currently pass in with an action something like:
[
{
cityName: "Los Angeles",
keywords: ["Los Angeles HVAC Repair", "HVAC Installation Los Angeles"]
},
{
cityName: "Sacramento",
keywords: ["Sacramento HVAC Repair", "HVAC Installation Sacramento"]
}
]
This does the job when I pass in the first action, but subsequent actions end us not merging the objects with the same cityName. This is
[
{
"cityName": "Los Angeles",
"keywords": [
[
"Los Angeles Roofing",
"Roofers in Los Angeles"
]
]
},
{
"cityName": "Sacramento",
"keywords": [
[
"Sacramento Roofing",
"Roofers in Sacramento"
]
]
},
{
"cityName": "Los Angeles",
"keywords": [
[
"HVAC Company in Los Angeles",
"Los Angeles HVAC Inspection"
]
]
},
{
"cityName": "Sacramento",
"keywords": [
[
"HVAC Company in Sacramento",
"Sacramento HVAC Inspection"
]
]
}
]
I would like it to look like this:
[
{
"cityName": "Los Angeles",
"keywords": [
[
"Los Angeles Roofing",
"Roofers in Los Angeles",
"HVAC Company in Los Angeles",
"Los Angeles HVAC Inspection"
]
]
},
{
"cityName": "Sacramento",
"keywords": [
[
"Sacramento Roofing",
"Roofers in Sacramento",
"HVAC Company in Sacramento",
"Sacramento HVAC Inspection"
]
]
},
]
Make splashscreen overlap elements
i am trying to make my splash screen overlap the website.
The splash screen gets pushed away by the elements that i want on the background.
www.rabbadz.com shows my splashscreen on the bottom.
here is my HTML
<!DOCTYPE html>
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: “355bfb40-16e9-48aa-93c3-d9eb93775989”,
});
});
Rabbadz
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,600&subset=latin-ext" rel="stylesheet">
<!-- CSS -->
<link href="assets/css/main.css" rel="stylesheet">
<!-- JS -->
<script src="assets/js/vendor/modernizr-2.8.3.min.js"></script>
<script src="assets/js/vendor/jquery-1.12.0.min.js"></script>
<script src="assets/js/plugins/animate-headline.js"></script>
<script src="assets/js/main.js"></script>
</head>
<body>
<audio id="myAudio">
<source src="assets/sound.mp3" type="audio/mpeg">
</audio>
<!--logo-->
<img src="assets/images/logo.png" class="logo">
<!-- Options headline effects: .rotate | .slide | .zoom | .push | .clip -->
<div class="hero-section hero-section--color clearfix zoom">
<!--we are rabbadz-->
<div class="anitext">
<div class="title-01 title-01--11 text-center">
<h2 class="title__heading">
<div class="hero-section__words text-center">
<div class="title__effect is-visible">WE ARE RABBITS</div>
<div class="title__effect">WE ARE BADASS</div>
<div class="title__effect">WE ARE RABBADZ</div>
</div>
</h2>
<div class="title__description">Coming soon to the metaverse.</div>
<!-- Options btn color: .btn-success | .btn-info | .btn-warning | .btn-danger | .btn-primary -->
<div class="title__action"><a href="https://mint.rabbadz.com" class="btn btn-primary">MINT</a></div>
</div>
</div>
</div>
</div>
</div>
<!--Particles-->
<div
id="particles-js"></div>
<script src="assets/js/particles.js"></script>
<script src="assets/js/app.js"></script>
<!-- splashscreen-->
<div class="scene content-hidden scene">
<div class="scene">
<div class="moon"></div>
</div>
<script type="text/javascript">
function stars(){
let count = 500;
let scene = document.querySelector('.scene');
let i = 0;
while(i < count){
let star = document.createElement("i");
let x = Math.floor(Math.random() * window.innerWidth);
let y = Math.floor(Math.random() * window.innerHeight);
let duration = Math.random() * 10;
let size = Math.random() * 2;
star.style.left = x+'px';
star.style.top = y+'px';
star.style.width = 1+size+'px';
star.style.height = 1+size+'px';
star.style.animationDuration = 5+duration+'s';
star.style.animationDelay = duration+'s';
scene.appendChild(star);
i++
}
}
stars();
</script>
<!--Rabbadverse button-->
$(function() {
var scene = $(‘.scene’),
enterButton = scene.find(‘.knop’);
setTimeout(function() {
scene.removeClass(‘content-hidden’);
}, 500);
enterButton.on(‘click’, function(e) {
e.preventDefault();
scene.addClass(‘content-hidden’).fadeOut();
});
var anitext = $('.forest'),
enterButton = scene.find('.knop');
setTimeout(function() {
forest.removeClass('content-hidden');
}, 500);
enterButton.on('click', function(e) {
e.preventDefault();
forest.addClass('content-hidden').fadeOut();
});
});
</script>
var x = document.getElementById(“myAudio”);
function playAudio() {
x.play();
}
function pauseAudio() {
x.pause();
}
</body>
Render component object inside array dynamically based on props
This should be pretty simple but keep giving me error:
Here is my array:
const section = [
{
trigger: {
title: 'Data',
icon: <Icon />,
editIcon: <Edit onClick={e => console.log(e)} />,
},
component: (
<ListOne
/>
),
},
{
trigger: {
title: 'OTHER PERSONAL DATA',
icon: <Like />,
editIcon: <Edit onClick={e => this.goToOtherPersonalData(e)} />,
},
component: (
<ListTwo
}
/>
),
},
...
]
What i wanna do is display some component from the array based on a boolean prop like this:
const section = [
propIsTrue && {
trigger: {
title: 'Data',
icon: <Icon />,
editIcon: <Edit onClick={e => console.log(e)} />,
},
component: (
<ListOne
/>
),
},
{
trigger: {
title: 'OTHER PERSONAL DATA',
icon: <Like />,
editIcon: <Edit onClick={e => this.goToOtherPersonalData(e)} />,
},
component: (
<ListTwo
}
/>
),
},
...
]
But doesn’t seems to be the correct syntax and give me error:
Uncaught TypeError: Cannot read properties of undefined (reading 'onClick')
So my answer is: Which is the correct way to dynamically display components based on passed prop?
Thanks in advance
How to remove/unset specific array in javascript?
How to remove/unset specific array in javascript? I tried to use splice but i get different result. I think I’m missing something here.
var arr = [12, 3, 150];
var min = 100;
var max = 200
for (var key2 in arr) {
if (min > arr[key2] || arr[key2] >= max) {
arr.splice(key2, 1);
}
}
console.log(arr);
Current code output: [ 3, 150 ]
Expected output: [150]





