Make a clickable div in Golang Template

I would like to make a table where you can click on the rows using bulma and gin/gonic with golang.

—-I am familiar with Angular and other js frameworks that enable the ease of adding (click) event listeners and tying in a function. I’d like to be able to add the equivalent of (click)=”doThisFunc()”.

I would prefer to not use a javascript framework if there’s a package in golang that would enable the same types of functionality in golang templates.

Please let me know of any packages/ideas/tips that you think would fit this type of capacity.

Thank you!

(p.s. if there’s a way to embed a lightweight javascript framework like Solid, alpine, or svelte into a golang app without changing the go gin app much I’d also love to hear about that)

Mapped Array with component not rendering on page

I’m Building a quiz app which gets the questions and answers from an API, it comprises of the start page and another page to display the questions and answers, I previously set a state start to switch between the Boolean values to know when to render the questions , but my mapped array of request isn’t rendering on the page with the Question component.
The App code as well as the Question is below

const [start, setStart] = React.useState(true)
console.log(start)

function renderNextPage() {
  setStart(false)
}


const [request, setRequest] = React.useState([])


React.useEffect(() => {
  fetch('https://opentdb.com/api.php?amount=5')
    .then(res => res.json())
    .then(data => setRequest(data.results.map(({
      question,
      correct_answer,
      incorrect_answers
    }) => ({
      question,
      correct_answer,
      incorrect_answers
    }))))
}, [])



const questionElements = request.map(req => {
  return ( <
    Question question = {
      req.question
    }
    />
  )
})

return (
  start ? < Start handleClick = {
    renderNextPage
  }
  />  : {questionElements}

)
}



// QUestion Component

export default function Question(props) {

  return ( <div >
    <h1 > {
      props.question
    }
    working </h1>

    <
    /div>

  )
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.1/umd/react-dom.production.min.js"></script>

How to print matching data from an array in react component?

I need check is today someone’s birthday & print all the filtered names in react component one by one.

Ex : Happy Birthday Lakshan Test!

    const birthdays = [{
          name: "Bob Marley",
          birthmonth: 6,
          birthdate: 13
        },
          {
            name: "Lakshan Test",
            birthmonth: 6,
            birthdate: 13
          },
          {
            name: "Peter Pan",
            birthmonth: 7,
            birthdate: 4
          },
        ];
    
        const today = new Date();
    
    
        birthdays.find((it) => {
          if (it.birthdate === today.getDate() && it.birthmonth === today.getMonth()) {
            alert("Happy Birthday!" + it.name);
            
          } else {
            alert("Have a nice day!);
          }
        })

How to get firestore collection id for each document && adding data in subcollection

So, this is my problem.
I’m trying to add a review in a subcollection from a collection named “explore_books”.
The problem is i don’t know how to add my data in the subcollection and how to get current id of a book.
My main goal is to push this comment on an already existing book, added from firebase. After that, i will get my data, but before that, i’m missing how to push my data, without creating a new doc (book).
enter image description here

 //const testId = firestore().collection('explore_books').doc().id;
  //const docId = firestore().collection('explore_books').
  const submitComment = async () => {
    console.log('ID CARTE: ');
    firestore()
      .collection('explore_books/' + testId + '/reviews')
      .add({
        userId: userId,
        comment: comment,
        userName: userName,
      })
      .then(() => {
        console.warn('Comment added!');
        Alert.alert('Comentariu adaugat cu succes');
        setComment(null);
      })
      .catch(error => {
        console.warn('Something went wrong.', error);
      });
  };

Retrieve bytea type as blob or file

I have a db model in postgres (using prisma) as follows:

model files {
  id    Int     @id
  title String?
  file  Bytes?
}

file is a bytea type and I’m using it to store files. When I retrieve the file, I get the results like this:

{"type":"Buffer","data":[104,101,108,108,111]}

How can I either retrieve it as a blob so I can send it to the front end to read as a file, or read that buffer data in javascript?

How to filter out an array based on another array in typescript

I have the following array of items as follows

data:

{   createdByName: "jane"
    createdOn: "2022-07-11T10:51:42.0652079+00:00"
    Id: "5f3660ed-b4af-45e6-8549-5d496f88e0ab"
}
{ createdByName: "kate"
    createdOn: "2022-01-11T10:51:42.0652079+00:00"
    Id: "5f3660ed-b4af-45e6-8549-5d496f88e0ab"
}
{createdByName: "Tom"
    createdOn: "2022-06-15T19:57:29.8228072+00:00"
    Id: "5f3660ed-b4af-45e6-8549-5d496f88e0ab"
}

a user can select a multiple months and it should filter out those results based on those months

selectedMonth = ['January', 'February']

previously i didnt have an array and the user could only select one option so i was filtering the data out as follows which worked fine.

this.selectedMonth="January"
    this.data.filter(x => moment(x.createdOn).format('MMMM') === this.selectedMonth)

output 
{createdByName: "kate" createdOn: "2022-01-11T10:51:42.0652079+00:00" Id: "5f3660ed-b4af-45e6-8549-5d496f88e0ab"}

But now how do i filter the data based on the array ? i am not sure how to change my query to accommodate that?
so if selectedMonth = ['January', 'February','July']

expected output should be:

{createdByName: "jane" createdOn: "2022-07-11T10:51:42.0652079+00:00" Id: "5f3660ed-b4af-45e6-8549-5d496f88e0ab" }{createdByName: "kate" createdOn: "2022-01-11T10:51:42.0652079+00:00" Id: "5f3660ed-b4af-45e6-8549-5d496f88e0ab"}

Why Css and js and png files not loaded in UI when access to page through Nginx?

****Why Css and js and png files not loaded in UI when access to
another container through nginx container?
anyone can solve this problem
this is my nginx.conf file

  http {
              
             include    /etc/nginx/mime.types;
             index    index.html index.htm index.php;
             default_type application/octet-stream;
             log_format   main '$remote_addr - $remote_user [$time_local]  $status '
                 '"$request" $body_bytes_sent "$http_referer" '
                 '"$http_user_agent" "$http_x_forwarded_for"';
             sendfile     on;
    
        # Weather Report Reverse Proxy
             server {
                listen 80;
                server_name localhost 127.0.0.1;
          
    
                location / {
                    proxy_pass          http://google.com/;
                    proxy_set_header    X-Forwarded-For $remote_addr;
                }
    
                location /admin {
                    proxy_pass          http://lp.commissionengine.administration.web.kw/;
                    proxy_set_header    X-Forwarded-For $remote_addr;
                }
    
                location /fake {
                    include  /etc/nginx/mime.types;
                    proxy_pass          http://fakeserver/;
                    proxy_set_header    X-Forwarded-For $remote_addr;
                }
            }
          
    }******

How can I make the #block end the game when it hits the character?

Im trying to get the #block to end the game and give the score once it hits the character. At the moment it just continues to go without ending the game. Its like it doesn’t see the character so it just continues to run. Before I added the images they were just boxes and the game worked fine. After adding the images the game Dosent respond as before.

Also the score just goes up without the character having to successfully jump. How do I fix that?

var character = document.getElementById("character");
var block = document.getElementById("block");
var counter=0;

function jump(){
    if(character.classList == "animate"){return}
    character.classList.add("animate");
    setTimeout(function(){
        character.classList.remove("animate");
    },300);
}
var checkDead = setInterval(function() {
    let characterTop = parseInt(window.getComputedStyle(character).getPropertyValue("top"));
    let blockLeft = parseInt(window.getComputedStyle(block).getPropertyValue("left"));
    if(blockLeft<20 && blockLeft>-20 && characterTop>=130){
        block.style.animation = "none";
        alert("Game Over. score: "+Math.floor(counter/100));
        counter=0;
        block.style.animation = "block 1s infinite linear";
    }else{
        counter++;
        document.getElementById("scoreSpan").innerHTML = Math.floor(counter/100);
    }
}, 10);
*{
    padding: 0;
    margin: 0;
    overflow-x: hidden;
    overflow-y: hidden;
}
.game{
    width: 1000px;
    height: 500px;
    border: 1px solid black;
    margin: auto;
    margin-top: 5px;
    position: relative;
}

.background-img-size {
    width: 1000px;
    height: 500px;
    content: url("https://p4.wallpaperbetter.com/wallpaper/957/704/964/pokemon-fields-ruby-1920x1200-nature-fields-hd-art-wallpaper-preview.jpg");
    position: absolute;
}

#character{
    display: inline-block;
    position: relative;
    margin-top: 39%; 
}


.animate{
    animation: jump 0.3s linear;
}
@keyframes jump{
    0%{bottom: 300px;}
    30%{bottom: 200px;}
    70%{bottom: 150px;}
    100%{bottom: px;}
}

#block{
    display: inline-block;
    position: relative;
    margin-top: 39%;
    left: 500px;
    animation: block 3s infinite linear;
    
}


@keyframes block{
    0%{left: 900px}
    100%{left: -170px}
}

p{
    text-align: center;
}
<!DOCTYPE html>
<html lang="en" onclick="jump()">
<head>
    <meta charset="UTF-8">
    <title>Jump Game</title>
    <link rel="stylesheet" href="index.css">   

</head>
<body>
    <div class="game" >
      <img class="background-img-size">
        <div id="character"> <img src="https://www.serebii.net/swordshield/pokemon/101.png" width="80" height="80"></div>
        <div id="block"> <img src="https://www.serebii.net/swordshield/pokemon/027.png" width="80" height="80"></div>
        <!-- <div id="block"> <img src="https://www.serebii.net/swordshield/pokemon/094.png"></div> -->
    </div>
    <p>Score: <span id="scoreSpan"></span></p>
    <script src="index.js"></script>
</body>
</html>

How to remove the item you click on from the Firestore?

I have created banks displayed from the database in the form of cards.
How can I take the id of the document I click on and delete this card from the database?

function getBanks() {
  db.collection("banks").onSnapshot((snapshot) => {
    let banks = [];
    snapshot.docChanges().forEach((change) => {
      const bank = change.doc.data();
      if (change.type === "added") {
        banks.push(bank);
        generateBanks([bank]);
      } else if (change.type === "removed") {
        console.log("Removed bank: ", bank );
      }
    });
  });
}

function generateBanks(banks) {
  banks.forEach((bank) => {
    ...
    const bank_delete_el = document.createElement("button");
    bank_delete_el.classList.add("delete");
    bank_delete_el.innerText = "Delete";

    });
  });
}

Use TIF file in ArcGIS JS

I have a server in NodeJS and have a TIF file on that server. And I have client application. How can I connect TIF file on server with client. I’ve tried res.sendFile(filePath) and connected with ImageLayer from @arcgis/core. But it showed Unexpected token I in JSON at position 0. What’s the best way to connect data on tif format. Data I’m using is from https://globalwindatlas.info/download/gis-files. I’ve enabled CORS on server.Thanks in advance.


multiply table via js

I want to make auto multiply table in HTML via JS, when the user put his number of columns and rows of the table, the page will print him table with all the number of the multiply number of row with the columns.
For example if I put 5 columns over 4 rows it will print table like that:

1  |  2  |  3  |  4  |  5
2  |  4  |  6  |  8  |  10
3  |  6  |  9  |  12 |  15
4  |  8  |  12 |  16 |  20

Right now this is my HTML code:

<html>
    <head>
        <meta charset="utf-8">
        <title>
            Multiply Table
        </title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <table class="workTable">
            <tr>
                <td>
                    <input type="number" placeholder="Columns Number" id="txtColumns">
                </td>
                <td>
                    <input type="number" placeholder="Rows Number" id="txtRows">
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <button id="btn">
                        send
                    </button>
                </td>
            </tr>
            <div>
                <table id="table" class="table" border="1">
                    <!---print table-->
                </table>
            </div>
        </table>
        <script src="script.js"></script>
    </body>
</html>

And this is my JS:

let go = document.getElementById('btn');
let table = document.getElementById('table');

go.addEventListener('click', () => {
  let numCol = document.getElementById('txtColumns').value; //Get the value of txtColumns at the button click moment.
  let numRow = document.getElementById('txtRows').value;

  let td = "",
    tr = "";
  for (let i = 0; i < numCol; i++) {
    td = td + "<td></td>";
  }
  for (let i = 0; i < numRow; i++) {
    tr = tr + "<tr>" + td + "</tr>";
  }

  table.innerHTML = tr;
})

I know how to print the table with the number of the rows and columns that the user choose but I don’t know how to auto fill it with the number.

Thank you all!

Any way to make one JavaScript function apply to more than one HTML element? [duplicate]

I have a lot of buttons on my project. I want to add onmouseover, onmouseout and onclick events on all of them, but because of the getElementById code… I need to make a new function for every single new button I make. I’ll give you an example:

Here is my script:

  function btnOverOne(){
        document.getElementById("btn1").style.backgroundColor = "#F98B88"
        document.getElementById("btn1").style.color = "#000000"
    }
    function btnOutOne(){
        document.getElementById("btn1").style.backgroundColor = "rgb(26, 26, 26)"
        document.getElementById("btn1").style.color = "rgb(255, 240, 240)"
    }
    function btnOverTwo(){
        document.getElementById("btn2").style.backgroundColor = "#F98B88"
        document.getElementById("btn2").style.color = "#000000"
    }
    function btnOutTwo(){
        document.getElementById("btn2").style.backgroundColor = "rgb(26, 26, 26)"
        document.getElementById("btn2").style.color = "rgb(255, 240, 240)"
    }

And here is my body:

<a id="btn1" onmouseover="btnOverOne()" onmouseout="btnOutOne()" href="HTML.html">HTML</a>
<a id="btn2" onmouseover="btnOverTwo()" onmouseout="btnOutTwo()" href="CSS.html">CSS</a>

Can someone help me out please? 🙁

How to check in a css grid if the adjacent cell has a class

I’m trying to create a simple game with html, css and javascript just to practice (I’m learning). I have this grid:

Grill game

What I’m trying to achive is when you click on a cell, it turns green but only if an adjacent cell is already green. But if this cell has “death” class then it turns red.

I know I can do it coding manually every cell, like this:

b21.addEventListener("click", () => {
if ((b11.classList.contains("green") || b31.classList.contains("green") || 
b22.classList.contains("green")) && !(b21.classList.contains("death")))
    b21.classList.add("green");
else if (b21.classList.contains("death"))
    b21.classList.add("red");

})

I’m sure there is a better way to do it. Something more elegant and functional but I don’t know how. I need something in that click event that check what classes has the adjacent cell.

Thanks!!

Uncaught TypeError: Cannot read properties of undefined (reading ‘filter’) JavaScript

I have a problem concern filter in JavaScript can’t working.
I’m not sure may because API using long time for response

My code :

const getDataAll  = () =>{
    const [machines, setMachines] = useState([])
    const getMc = async () =>{
       try {
         const resMc = await axios.get("My API")
         setMachines(resMc.data)
       } catch (err) {
         console.error(err.message)
       }

    useEffect(()=>{
       getMc()
    },[])
    
    const sumData = () =>{
       const filterName = machines.data.filter((el) => item.name == "v10turbo")
    }
}

Filter have show this alert in some time.

enter image description here

And i see time show in browser for API response around 8-9 second follow image below

enter image description here

I’m not sure if I got it right.
if right please help me with to solve this problem