When pressed button in react, console log shows the result but page does not - html

I am new to react and web. I have an issue when calling the function console shows it but i can not show it in my page.
usePriest = (evt, id) => {
const num = 3;
const { rear,bottom2,bottom3,bottom,player1, player2, player3, player4, mycards } = this.state;
var whichPlayer;
switch(num){
case 1:
whichPlayer = player1[0];
rear[1]=whichPlayer;
rear[0]=card6;
break;
case 2:
whichPlayer = player2[0];
bottom[1]=whichPlayer;
bottom[0]=card6;
break;
case 3:
whichPlayer = player3[0];
bottom2[1]=whichPlayer;
bottom2[0]=card6;
break;
case 4:
whichPlayer = player4[0];
bottom3[1]=whichPlayer;
bottom3[0]=card6;
break;
}
// bottom[1]=whichPlayer;
// bottom[0]=card6;
// console.log(bottom);
}
and i call my function in here
else if (mycards[0]==="/static/media/priest.ae71698d.jpg") {
return ( <div>
<button className="button_card1_use" onClick={(evt) => this.usePriest(evt, 1)}>Use</button>
<button className="button_card1_discard">Discard</button>
<div className="about1"><p>Priest</p>
Player is allowed to see another player's hand. </div></div>
)
}
What should i return in function or do something in order to be able to show it on the page.

You just need to call a setState at the end of the function in order tot reflect the changes -:
usePriest = (evt, id) => {
const num = 3;
// your old code
this.setState({ rear,bottom2,bottom3,bottom,player1, player2, player3, player4, mycards })
}
Actually in JS things get copied by reference, so effectively we are mutating the state directly. This is a better solution for the same -:
usePriest = (evt, id) => {
const num = 3;
const { rear,bottom2,bottom3,bottom,player1, player2, player3, player4, mycards } = this.state;
var whichPlayer;
switch(num){
case 1:
this.setState({whichPlayer: player1[0], rear: [...rear, 0: card6, 1: whichPlayer]});
break;
case 2:
this.setState({whichPlayer: player2[0], bottom: [...bottom, 0: card6, 1: whichPlayer]});
break;
case 3:
this.setState({whichPlayer: player3[0], bottom2: [...bottom2, 0: card6, 1: whichPlayer]});
break;
case 4:
this.setState({whichPlayer: player4[0], bottom3: [...bottom3, 0: card6, 1: whichPlayer]});
break;
}
}

Related

How can I test/validate the header hierarchy of a section in cypress?

i want to enforce the structure that headers follow a hierarchy. Meaning if you go from bottom to top of the dom, thr next heading must be <= current or + 1.
Here is the console log of my headings in one of my sections for example:
Yielded:
0: h2.mt-4
1: h3.mt-16.text-base.w-64
2: h4.mt-0.font-normal.text-sm
3: h4.mt-0.font-normal.text-sm
4: h4.mt-0.font-normal.text-sm
5: h3.mt-16.text-base.w-64
6: h4.mt-0.font-normal.text-sm
7: h4.mt-0.font-normal.text-sm
8: h4.mt-0.font-normal.text-sm
9: h4.mt-0.font-normal.text-sm
10: h3.mt-16.text-base.w-64
11: h4.mt-0.font-normal.text-sm
12: h4.mt-0.font-normal.text-sm
This would be valid ^
Yielded:
0: h2.mt-4
1: h3.mt-16.text-base.w-64
2: h4.mt-0.font-normal.text-sm
3: h4.mt-0.font-normal.text-sm
4: h4.mt-0.font-normal.text-sm
5: h3.mt-16.text-base.w-64
6: h4.mt-0.font-normal.text-sm
7: h4.mt-0.font-normal.text-sm
8: h4.mt-0.font-normal.text-sm
9: h4.mt-0.font-normal.text-sm
10: h3.mt-16.text-base.w-64
11: h1.mt-0.font-normal.text-sm
12: h1.mt-0.font-normal.text-sm
And this is not ^^^
So far I can loop through the sections and get each sections headers, but a bit stumped on how to loop through and force that rule. It would require comparing the current header and the next one in the array.
What I have so far:
Cypress.Commands.add("checkHeadingHeirarchy", () => {
cy.get("section").each(($section) => {
cy.get($section).within(() => {
cy.get("h1,h2,h3,h4,h5,h6"); //now what?...
});
});
});
#agoff: The console.log shows us the first $el and then the $list[index + 1]:
This is the $el: jQuery.fn.init [h2.mt-4]
This is the $el: <h3 data-cy=​"header" class=​"mt-16 text-base w-64">​Engineering​</h3>​
#agoff: This works, but its hacky:
Cypress.Commands.add("checkHeadingHeirarchy", () => {
cy.get("section").each(($section) => {
cy.get($section).within(() => {
cy.get("h1,h2,h3,h4,h5,h6").each(($el, index, $list) => {
// Don't run the validation on the last item in the list
if (index !== $list.length - 1) {
// Get the size of the current and next header
const currSize = getHeaderNumber($el);
const nextSize = getHeaderNumber($list, index + 1);
try {
expect(currSize <= nextSize || currSize + 1 === nextSize).to.eql(
true
);
} catch {
console.log("Failed on current size:", currSize);
console.log("Failed on next size:", nextSize);
throw error;
}
}
});
});
});
});
// helper function to get header number
const getHeaderNumber = ($el, index) => {
console.log("Going to parse this:", $el.get(index ?? 0));
try {
console.log("Got this:", parseInt($el.get(index ?? 0).tagName.slice(1)));
return parseInt($el.get(index ?? 0).tagName.slice(1));
} catch {
console.log("ERROR ON:", $el.get(index ?? 0));
}
};
You can yield the index of the elements yielded, as well as the entire list. Using that, we can easily compare the next yielded item.
Cypress.Commands.add("checkHeadingHeirarchy", () => {
cy.get("section").each(($section) => {
cy.wrap($section).within(($sectionWithin) => {
cy.get("h1,h2,h3,h4,h5,h6").each(($el, index, $list) => {
// Don't run the validation on the last item in the list
if (index !== $list.length - 1) {
// Get the size of the current and next header
const currSize = getHeaderNumber($el)
const nextSize = getHeaderNumber($list[index + 1])
expect(currSize <= nextSize || currSize + 1 === nextSize).to.eql(true);
}
});
});
});
});
// helper function to get header number
const getHeaderNumber = ($el) => {
const tagName = $el.prop('tagName') ?? $el.get(0).tagName
return parseInt(tagName.slice(1), 10);
}

Copying a section from Google Docs to another Doc using Apps Script

I've successfully used this code to copy the entirety of one doc into another doc:
const newestFile = DocumentApp.openById("ID").getBody();
const archive = DocumentApp.openById("ID").getBody();
let index = 12;
let el, type;
for (let i = 0; i < newestFile.getNumChildren(); i++){
el = newestFile.getChild(i);
type = el.getType();
switch (type){
case DocumentApp.ElementType.PARAGRAPH:
archive.insertParagraph(index,el.copy());
index++;
break;
case DocumentApp.ElementType.LIST_ITEM:
archive.insertListItem(index,el.copy());
index++;
break;
case DocumentApp.ElementType.TABLE:
archive.insertTable(index,el.copy());
index++;
break;
}
}
However, I now need to copy a portion of a doc into another doc, and I can't figure it out. If I knew how to get the body index of any element I could do it the same way, but I don't know if that's even possible. The text I need to copy out will always be preceded by a specific text ("Current Week") and end immediatly before a specific text ("ARCHIVE").
Description
Here is a simple example of how to copy between certain text. I've only covered paragraphs and tables but any other type of Element can be handled.
Test Document
Script
function myFunction() {
try {
let doc = DocumentApp.getActiveDocument();
let body = doc.getBody();
let count = body.getNumChildren();
doc = DocumentApp.create("dummy");
let copy = doc.getBody();
let start = false;
for( let i=0; i<count; i++ ) {
let child = body.getChild(i);
if( child.getType() == DocumentApp.ElementType.PARAGRAPH ) {
if( child.asParagraph().findText("Current Week") ) start = true;
if( start ) copy.appendParagraph(child.asParagraph().copy());
if( child.asParagraph().findText("ARCHIVE") ) break;
}
else if( child.getType() == DocumentApp.ElementType.TABLE ) {
if( start ) copy.appendTable(child.asTable().copy());
}
}
}
catch(err) {
console.log("Error in myFunction - "+err)
}
}
Reference
https://developers.google.com/apps-script/reference/document/body#getChild(Integer)
https://developers.google.com/apps-script/reference/document/element-type
https://developers.google.com/apps-script/reference/document/body

retrieving EntryID for Checkbox item in Google Sheets Form not working

I used the code from #contributorpw on this post get Entry ID which is used to pre-populate fields (Items) in a Google Form URL and added the extended list of form types from #SourceFli (in same post).
I get the error message: "Exception: The parameters (String) don't match the method signature for FormApp.CheckboxItem.createResponse". That checkbox has only 1 option: "yes".
The rest of all my form items are only TEXT items and work fine.
function getPreFillEntriesMap(){
var ssOrder = SpreadsheetApp.openById(ORDER_SPREADSHEET_ID);
var orderFormUrl = ssOrder.getFormUrl();
var orderForm = FormApp.openByUrl(orderFormUrl);
var form = orderForm;
// var form = FormApp.openById(id);
var items = form.getItems();
var newFormResponse = form.createResponse();
var itms = [];
for(var i = 0; i < items.length; i++){
var response = getDefaultItemResponse_(items[i]);
if(response){
newFormResponse.withItemResponse(response);
itms.push({
id: items[i].getId(),
entry: null,
title: items[i].getTitle(),
type: "" + items[i].getType()
});
}
}
var ens = newFormResponse.toPrefilledUrl().split("&entry.").map(function(s){
return s.split("=")[0];
});
ens.shift();
return Logger.log(itms.map(function(r, i){
r.entry = this[i];
return r;
}, ens));
}
function getDefaultItemResponse_(item){
switch(item.getType()){
case FormApp.ItemType.TEXT:
return item.asTextItem().createResponse("1");
break;
case FormApp.ItemType.MULTIPLE_CHOICE:
return item.asMultipleChoiceItem()
.createResponse(item.asMultipleChoiceItem().getChoices()[0].getValue());
break;
case FormApp.ItemType.CHECKBOX:
return item.asCheckboxItem()
.createResponse(item.asCheckboxItem().getChoices()[0].getValue());
break;
case FormApp.ItemType.DATETIME:
return item.asDateTimeItem()
.createResponse(new Date());
break;
case FormApp.ItemType.DATE:
return item.asDateItem()
.createResponse(new Date());
break;
case FormApp.ItemType.LIST:
return item.asListItem()
.createResponse(item.asListItem().getChoices()[0].getValue());
break;
case FormApp.ItemType.PARAGRAPH_TEXT:
return item.asParagraphTextItem()
.createResponse(item.asParagraphTextItem().createResponse("some paragraph"));
break;
case FormApp.ItemType.CHECKBOX_GRID:
return item.asCheckboxGridItem()
.createResponse(item.asCheckboxGridItem().createResponse([item.asGridItem().getColumns[0], item.asGridItem().getRows[0]]));
break;
case FormApp.ItemType.DURATION:
return item.asDurationItem()
.createResponse(item.asDurationItem().createResponse(2, 20, 20));
break;
case FormApp.ItemType.GRID:
return item.asGridItem()
.createResponse(item.asGridItem().createResponse([item.asGridItem().getColumns[0], item.asGridItem().getRows[0]]));
break;
case FormApp.ItemType.SCALE:
return item.asScaleItem()
.createResponse(item.asScaleItem().createResponse(1));
break;
case FormApp.ItemType.TIME:
return item.asTimeItem()
.createResponse(item.asTimeItem().createResponse(1, 1));
break;
default:
return undefined;
}
}
response of createResponse(responses) of Class CheckboxItem is String[]. In your script, the string is used. I thought that this might be the reason of your issue. So how about the following modification?
From:
return item.asCheckboxItem()
.createResponse(item.asCheckboxItem().getChoices()[0].getValue());
To:
return item.asCheckboxItem()
.createResponse([item.asCheckboxItem().getChoices()[0].getValue()]);
Reference:
createResponse(responses)

dynamic view of the syncfusion schedule angular component

In the parameterization of the Schedule to Angular component I would like to know if it is possible to somehow define the start time and end time for a day.
I would like to define for each day what is the start time and the end time.
As this example I realized that the start time and end time is for every day, I would like to set the start time and end time for each day.
const resourceObject = {
text: p.nome, id: p.id,
color: '#848484', workDays: daysNumber,
startHour: '13:00', endHour: '18:00'
};
We have prepared the below sample to have different work hours per day using DataBinding event.
https://stackblitz.com/edit/angular-fxqnrc-njutc8?file=app.component.ts
Please refer below UG.
https://ej2.syncfusion.com/angular/documentation/api/schedule/#setworkhours
if (this.flag) {
if (
this.scheduleObj.currentView !== "Month" &&
this.scheduleObj.currentView !== "Agenda"
) {
var currentViewDates = this.scheduleObj.getCurrentViewDates();
for (var i = 0; i < currentViewDates.length; i++) {
switch ((currentViewDates[i] as any).getDay()) {
case 0:
this.scheduleObj.setWorkHours(
[currentViewDates[i]],
"06:00",
"14:00"
);
break;
case 1:
this.scheduleObj.setWorkHours(
[currentViewDates[i]],
"08:00",
"14:00"
);
break;
case 2:
this.scheduleObj.setWorkHours(
[currentViewDates[i]],
"07:00",
"20:00"
);
break;
case 3:
debugger;
this.scheduleObj.setWorkHours(
[currentViewDates[i]],
"09:00",
"13:00"
);
break;
case 4:
debugger
this.scheduleObj.setWorkHours(
[currentViewDates[i]],
"06:00",
"14:00"
);
break;
case 5:
debugger
this.scheduleObj.setWorkHours(
[currentViewDates[i]],
"08:00",
"15:00"
);
break;
case 6:
this.scheduleObj.setWorkHours(
[currentViewDates[i]],
"07:00",
"19:00"
);
}
}
}
this.flag = false;
}

Adobe AIR 3.2 Glitch

I just finished a successful build of my program last night. Then, I get up this morning, and after an update fro Adobe AIR 3.1 to AIR 3.2, I find THIS bug!
The same build under 3.1 works perfectly. However, as soon as 3.2 is installed, the following code after stopDrag fails silently. Mind you, it only fails in the packed and installed AIR application. It works perfectly when I test it inside of Adobe Flash Professional CS5.5
WHAT is going on? Here's the code I'm dealing with. Again, this works without error for Adobe AIR 3.1, but fails for 3.2. I cannot get to any other MouseEvent.MOUSE_UP events in my program at this point, due to my structure.
I omitted the irrelevant parts of the code. All the same, there is a lot, due to the fact that I don't know where the error occurs exactly. Instead of everything that is supposed to happen happening, stopDrag is the last line of code that fires in this block.
tile5.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler5);
function mouseUpHandler5(evt:MouseEvent):void
{
Mouse.cursor = "paw";
var obj = evt.target;
var target = obj.dropTarget;
obj.stopDrag();
if (target != null && target.parent == hsSlot1)
{
brdgcheck(5, 1);
}
}
function brdgcheck(tile:int, slot:int)
{
var ck_brdg_l:String = "osr.Langue.brdg_l" + String(slot);
var ck_brdg_t:String = "osr.Langue.brdg_t" + String(tile);
var ck_slotfilled:String = "Slot" + String(slot) + "Filled";
var ck_tile:String = "tile" + String(tile);
var ck_slot:String = "hsSlot" + String(slot);
var ck_txtTile:String;
switch(tile)
{
case 1:
ck_brdg_t = osr.Langue.brdg_t1;
ck_txtTile = tile1.txtTile1.text;
break;
case 2:
ck_brdg_t = osr.Langue.brdg_t2;
ck_txtTile = tile2.txtTile2.text;
break;
case 3:
ck_brdg_t = osr.Langue.brdg_t3;
ck_txtTile = tile3.txtTile3.text;
break;
case 4:
ck_brdg_t = osr.Langue.brdg_t4;
ck_txtTile = tile4.txtTile4.text;
break;
case 5:
ck_brdg_t = osr.Langue.brdg_t5;
ck_txtTile = tile5.txtTile5.text;
break;
}
switch(slot)
{
case 1:
ck_brdg_l = osr.Langue.brdg_l1;
break;
case 2:
ck_brdg_l = osr.Langue.brdg_l2;
break;
case 3:
ck_brdg_l = osr.Langue.brdg_l3;
break;
case 4:
ck_brdg_l = osr.Langue.brdg_l4;
break;
case 5:
ck_brdg_l = osr.Langue.brdg_l5;
break;
}
if (ck_brdg_l == ck_brdg_t)
{
osr.Sonus.PlaySound("concretehit");
this[ck_slotfilled].visible = true;
switch(slot)
{
case 1:
Slot1Filled.txtSlot1.text = ck_txtTile;
break;
case 2:
Slot2Filled.txtSlot2.text = ck_txtTile;
break;
case 3:
Slot3Filled.txtSlot3.text = ck_txtTile;
break;
case 4:
Slot4Filled.txtSlot4.text = ck_txtTile;
break;
case 5:
Slot5Filled.txtSlot5.text = ck_txtTile;
break;
}
this[ck_tile].visible = false;
this[ck_slot].visible = false;
if (hsSlot1.visible == false && hsSlot2.visible == false && hsSlot3.visible == false && hsSlot4.visible == false && hsSlot5.visible == false)
{
osr.Gradua.Score(true);
osr.Gradua.Evaluate("brdg");
btnReset.visible = false;
hsChar.visible = false;
if (osr.Gradua.Fetch("brdg", "arr_act_stcnt") < 4)
{
bga.gotoAndPlay("FINKEY");
win_key();
}
else
{
bga.gotoAndPlay("FINNON");
}
}
else
{
osr.Gradua.Score(true);
}
}
else
{
osr.Gradua.Score(false);
osr.Sonus.PlaySound("glassbreak");
switch(tile)
{
case 1:
tile1.x = 92.85;
tile1.y = 65.85;
break;
case 2:
tile2.x = 208.80;
tile2.y = 162.85;
break;
case 3:
tile3.x = 324.80;
tile3.y = 65.85;
break;
case 4:
tile4.x = 437.80;
tile4.y = 162.85;
break;
case 5:
tile5.x = 549.80;
tile5.y = 65.85;
break;
}
}
}
EDIT: I found a good workaround, to use "if (hsSlot1.hitTestPoint(mouseX,mouseY) && hsSlot1.visible == true)"
However, a solution to this problem would still be appreciated!