React Filter array of objects by date within a certain range using specific date range buttons, moment js

So i have an array objects with dates and scores. I would like to create an onclick handler that updates data everytime i click one of the 4 buttons. My 4 buttons represent 3 months, 6 months, 12 months and reset. I would like to filter this data from todays date to “blank” months ago. I am thinking of using moment and here is what i have so far. Just not sure if im going the right direction or how to solve this issue.

const threeMonths = moment().startOf('day').subtract(3, 'month').format('YYYY-MM-DD');
const sixMonths = moment().startOf('day').subtract(6, 'month').format('YYYY-MM-DD');
const twelveMonths = moment().startOf('day').subtract(12, 'month').format('YYYY-MM-DD');

Example: Clicking the 3 months button
I would like to filter this data from todays date to 3 months ago

Starting:

 Data = [ 
    {date: '2023-01-22', score: 57.675},
    {date: '2022-11-05', score: 60.675},
    {date: '2022-12-11', score: 78.675},
    {date: '2022-08-26', score: 81.675}
    ]

<Button onclick= {} > 3 months </Button>

After 3 month button click: Only dates within 3 months remain

Data = [ 
    {date: '2023-01-22', score: 57.675},
    {date: '2022-11-05', score: 60.675},
    {date: '2022-12-11', score: 78.675},
    ]

Merge Two Arrays and Values [duplicate]

I would like to merge two arrays and in the midst of merging the values together.

Current Array:

let arr1 = ['apple','pear'];
let arr2 = ['2022','2021','2020'];

This is what I tried.

let filterArray = arr2.map(function(num,idx) {
   for (let i = 0; i < arr2.length; i++) {
      for (let j = 0; j < arr1.length; j++) {
         return arr1[j] + arr2[idx];
      }
   }
}

Current outcome:

['apple2022','apple2021','apple2020']

Expecting to be:

['apple','apple2022','apple2021','apple2020','pear','pear2020','pear2021','pear2020'];

Facebook login sdk is blocked by Microsoft Edge tracking prevention

I’m using facebook login javascript sdk for social login functionality and it is blocked on Microsoft Edge browser, is there any way to make it work?

I tried to load the script using proxy but it’s still blocked.
I also noticed some browsers like firefox and chrome also blocked facebook sdk before, but still, I’m wondering if there is any way to bypass this rather than waiting for an update from Microsoft to fix this or manually add the sdk as an exception to the Tracking prevention.

Any help is very appreciated.

Cheers!

Is there a way to change color of div based on what what text is entered?

I will try my best to ask this question so it can be understood. And hopefully what I am trying to achieve is possible, without trying to reinvent the wheel.

I have a form with a ‘select’ input field, so that an admin may select a ‘status’ option for individual users.

The status options would be ‘Unverified’, ‘Verified’ or ‘Banned’.

When the user’s profile page displays the respective ‘status’ of that user (called from the database), I would like the background color of the ‘status div’ to also change accordingly.

For example…

The background color for the status div of an unverified user should be orange.

Whereas… The background color for the status div of an verified user should be green.

And finally… The background color for the status div of a banned user should be red.

Dropdown menu not aligning

I’m having a problem where my list for my dropdown menu appears in another location then expected to be at.

Image

This is part of my code. I’ve tried multiple references, like YouTube, w3school, and etc.

(HTML / JS)

    <header>
            <ul>
                <li id="regular"><a href="#">EARN</a></li>
                <li id="regular"><a href="#">PROMOCODES</a></li>
                <li id="regular"><a href="#">WITHDRAW</a></li>
                
                <li class="dropdown">
                    <button class="dropdownButton" href="#">MORE ▼</button>
                    <ul class="list">
                        <a href="#"><button class="links">REFFERALS</button></a>
                        <a href="#"><button class="links">DAILY</button></a>
                    </ul>
                </li>

                <li id="login"><a href="#">SIGN UP</a></li>
            </ul>

            <script>
                //Dropdown
                let click = document.querySelector('.dropdownButton');
                let list = document.querySelector('.list');
    
                click.addEventListener("click",()=>{
                    list.classList.toggle('newlist');
                });
                //Dropdown End
            </script>
   </header>

(CSS)

.dropdownButton {
    color: #fe4b4b;
    text-decoration: none;
    font-family: 'Titillium Web', sans-serif;
    font-size: 165%;
    background-color: transparent;
    background-repeat: no-repeat;
    border: none;
    cursor: pointer;
    overflow: hidden;
    outline: none;
}

.dropdown {
    align-items: center;
}

.list {
    position: absolute;
    align-items: center;
    text-align: center;
    transform: scaleY(0);
    transform-origin: top;
    transition: 0.3s;
    height: auto;
    width: 150px;
    border-radius: 5px;
    background-color: #3a4172;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 2px 0px 10px 5px rgba(0, 0, 0, 0.7);
    list-style: none;
}

.newlist {
    transform: scaleY(1);
}

.links {
    color: #ffffff;
    text-decoration: none;
    font-family: 'Titillium Web', sans-serif;
    font-size: 130%;
    background-repeat: no-repeat;
    background-color: transparent;
    border: none;
    border-radius: 5px;
    width: 100%;
}

.links:hover {
    color: #fefb4b;
    border-left: 5px solid #fefb4b;
    cursor: pointer;
    transform: scale(1.025);
}

I don’t know how to fix it cause I’m a beginner, any help on fixing it / guidance would be nice! Thanks.

how to get a particular user data from MongoDB in node.js

Im doing a project on e commerce website. here im with a problem.

  1. i have used get method to retrive user data from MongoDB
  2. i have passed correct parameters and the statment UserId:req.params.userId have been satisfied where we can see in the nodejs terminal.
  3. Im looking to get only particular user data which has UserId === UserId. But in my result all the users data is been poping up.
  4. Can i please get the solution for this ASAP

Im Trying this but the solution im getting is all the users data

i have tried using findOne() but the result is this 635ea7e5e931e12c9f851dd3 user details. where the parameter is 63a8a0f77addf42592eed1e5. where im expecting to get the only user which im passing in parameter.

router.get("/find/:userId", verifyTokenAndAuthorization, async (req, res) => {
  try {
    const cart = await Cart.find( 
    {userId : req.params.userId});
    console.log("parameter: "+req.params.userId)
     return res.status(200).json(cart);
  } catch (err) {
    res.status(500).json(err);
  }

The req.params userId is ’63a8a0f77addf42592eed1e5′ ineed only this. but it is poping up all the users Data.

This is this node.js terminal ScreenShot which is showing the parameter is same with userId
This is Post Man ScreenShot which is showing the response of all users present in the DB but i need only the user details which i had passed in the parameter

Getting empty properties array when using Google Analytics API v3 to list web properties

I’m able to successfully connect to Google Analytics(GA4) but I’m receiving an empty array for properties even though my Google Analytics account is an administrator for two properties in conjunction with the service account I am using for authentication. The response I am getting is “Google analytics connection is working and your account is: markusets Available properties: []”. I am using the v3 version of the API, I’m looking for a solution to be able to retrieve the available properties.

When I run this NodeJs script:

const { google } = require("googleapis");
const analytics = google.analytics("v3");
const credentials = require("./service-account-credentials.json");

const client = new google.auth.JWT(
  credentials.client_email,
  null,
  credentials.private_key,
  ["https://www.googleapis.com/auth/analytics.readonly"]
);

client.authorize((err) => {
  if (err) {
    console.log(err);
    return;
  }
  //call to get account name
  analytics.management.accounts.list({ auth: client }, (err, result) => {
    if (err) {
      console.log(err);
    } else {
      console.log(
        `Google analytics connection is working and your account is: ${result.data.items[0].name}`
      );
      //call to get properties
      analytics.management.webproperties.list(
        {
          auth: client,
          accountId: "12345678",
        },
        (err, result) => {
          if (err) {
            console.log(err);
          } else {
            console.log(
              `Available properties: ${JSON.stringify(result.data.items)}`
            );
          }
        }
      );
    }
  });
});

I get:

Google analytics connection is working and your account is: markusets
Available properties: []

So what I’ve tried so far is to retrieve the available properties of my Google Analytics account using a service account and the Google Analytics API (v3). I have verified that my account and the service account have administrator privileges for the properties and that the credentials are correct because I am receiving the message “Google analytics connection is working and your account is: markusets” which suggests that I have been successfully authenticated. However, when I try to retrieve the properties, the resulting array is empty. I have tried different methods to retrieve the properties but none of them have worked so far. I am looking for a solution or a reason why the properties array is empty despite the correct authentication.

How can I position an element on n cells of an html table? Angular

How can I position an element correctly on a table? The problem is that the table is dynamic, there can be n columns and n rows, then both width and height can change.

Result

My intention here is that according to a start and end time are the height of the element and the place of the column where it is located.

I leave an example of my code and attempts.
Stackblitz live code

Typescript.

  hours = [
    '8:00 AM',
    '9:00 AM',
    '10:00 AM',
    '11:00 AM',
    '12:00 PM',
    '1:00 PM',
    '2:00 PM',
    '3:00 PM',
    '4:00 PM',
    '5:00 PM',
  ];
  places = ['P1', 'P2', 'P3', 'P4', 'P5'];
  events: any = [];

  cellWidth = 0;
  cellWidthHour = 0;
  cellHeight = 0;

  constructor() {}

  ngAfterViewInit() {
    this.getCellSize();
    this.createEvent('10:00 AM', '12:00 PM', 'P3');
  }

  getCellSize() {
    const cell = document.getElementsByClassName('cell')[0];
    const cellWidthHour = document.getElementsByClassName('cell-hour')[0];
    const cellRect = cell.getBoundingClientRect();
    const cellRectHour = cellWidthHour.getBoundingClientRect();
    this.cellWidth = cellRect.width;
    this.cellHeight = cellRect.height;
    this.cellWidthHour = cellRectHour.width;
    console.log(this.cellWidth, this.cellHeight);
  }

  createEvent(startTime: string, endTime: string, location: string) {
    const event: any = { startTime, endTime, location };
    event.position = this.calculateEventPosition(startTime, endTime, location);
    this.events.push(event);
  }

  calculateEventPosition(startTime: string, endTime: string, location: string) {
    const start = this.hours.indexOf(startTime) + 1;
    const end = this.hours.indexOf(endTime);

    const place = this.places.indexOf(location);

    const height = (end - start + 1) * this.cellHeight + 3;
    const top = start * this.cellHeight - 6;
    const left = place * this.cellWidth + this.cellWidthHour;

    console.log(start, end, place);
    console.log(height, top, left);

    return {
      height: height + 'px',
      top: top + 'px',
      left: left + 'px',
      width: this.cellWidth + 'px',
    };
  }

HTML

<div class="calendar-container">
  <table>
    <tr>
      <th></th>
      <th *ngFor="let place of places">{{ place }}</th>
    </tr>
    <tr *ngFor="let hour of hours">
      <td class="cell-hour">{{ hour }}</td>
      <td class="cell" *ngFor="let place of places"></td>
    </tr>
  </table>
  <div *ngFor="let event of events">
    <div class="event" [ngStyle]="event.position">
      <p>{{ event.location }}</p>
    </div>
  </div>
</div>

CSS

.calendar-container {
  position: relative;
}

table {
  border-collapse: collapse;
  width: 100%;
}

td,
th {
  border: 1px solid #dddddd;
  text-align: center;
}

table td {
  height: 25px;
}

.event {
  position: absolute;
  background-color: #f2f2f2;
  padding: 12px;
  border-radius: 4px;
}

I tried to generate these elements that are like cards in a dynamic way but I could not find the correct formula, sometimes it overflows or when I place it well just by readjusting the screen I lose the effect.

transition-group with v-show not working in vue2

I want to add some transition-delay effects to each element in transition-group,but something really weird happens.
The first time come and leave works fine,but the second time come and leave both not working.
I thought of many reasons such as key problem,transition style problem,element style problem,but all failed. Maybe settimeout function in js callback can solve it, but is there another way?
I made a simple transition element as comparison,it works fine.
I’ll be appreciate if someone can spend time working out this issue.
here are code below

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>v-show标签过渡实现特效单项目探究</title>
    <script src="vue.js"></script>
</head>
<body>
<div id="root">
    <button @click="isShow2=!isShow2">显示/隐藏</button>
    <transition
            name="hello"
           appear
    >
        <div class="divwidth" v-show="isShow2" :style="[{transition :'500ms'},{transitionDelay:100+'ms'}]">
            <span class="content">英语第1次考试</span>

        </div>


    </transition>
    <button @click="isShow=!isShow">显示/隐藏</button>
    <Transition-group

            name="hello"
            appear
    >
        <div class="divwidth" v-show="isShow"  key="11" :style="[{transition :'500ms'},{transitionDelay:100+'ms'}]">
            <span class="content">英语第1次考试</span>
        </div>
        <div class="divwidth" v-show="isShow"  key="12" :style="[{transition :'300ms'},{transitionDelay:100+'ms'}]">
            <span class="content">英语第2次考试</span>
        </div>
    </Transition-group>


</div>
</body>
<script>
    new Vue({
        el: "#root",
        data() {
            return {
                isShow: true,
                isShow2: true
            }
        },
    })
</script>
<style>
    .divwidth {
        width: 60%;
        margin-top: 15px;
    }

    .content {
        /*background-image: linear-gradient(red, yellow, blue);用于创建一个线性渐变的" 图像 "*/
        background-color: orange;
        width: auto;
        /*margin: 20px;*/
        /*margin-top: 0px;*/
        /*padding-top: 10px;*/
        padding: 6px;
        font-size: 20px;
        border: 10px;
        border-radius: 8px;
        /*line-height: 30px;*/

    }

    /*.hello-enter-active, .hello-leave-active  {*/
    /*    transition: 300ms linear;*/
    /*    !*transition-delay:200ms*!*/
    /*}*/

    .hello-enter, .hello-leave-to {
        opacity: 0;
        transform: translateX(50%);
    }


 /*.hello-move { transition: all 0.6s ease; }*/
/*.hello-leave-active{*/
/*    position: absolute; */
/*}*/

</style>
</html>

I tried v-if,it works fine,but I don’t want to get rid of elements from DOM .
as to v-show I thought of many reasons such as key problem,transition style problem,element style problem,but all failed.
I expect to see transition effects happens every time i click the button,but in my example ,effects failed at second time come and leave.

How to display data in multiple HTML tags with a button on click function on JavaScript?

function myFunction() {
  var length = document.getElementById("rooml").value;
  var lroom;
  lroom = length;
  var width = document.getElementById("roomw").value;
  var wroom;
  wroom = width;
  var height = document.getElementById("roomh").value;
  var hroom;
  hroom = height;

  $(document).ready(function() {
        var myVolume = $("#volume");
        myVolume.text(" " + (length * width * height) + " cubic feet");

        $(document).ready(function() {
          var mySurface = $("#area");
          mySurface.text(" " + (((length * height) * 2) + ((width * height) * 2) + ((width * length) * 2)) + " square feet");

        });

      }

I am trying to get 3 values from some html input tags and display the result in 3 different paragraphs with different html id’s

I’ve tried using getElementById: I only can display data in one HTML tag. Also I’ve tried jQuery selector and same ending. the math part/formulas are ok: I just can’t get displaying the results

What’s so special about adding when it comes to strings and numbers?

All except + do the math. How do I do an actual addition mathematically? Don’t ask why I need it. I’m curious.

let first = "2" + 2  
let second = 4 + 4  
let third = first + second  
console.log(third)  

logged 228

let first = "2" + 2  
let second = 4 + 4  
let third = first - second  
console.log(third)  

logged 14

let first = "2" + 2  
let second = 4 + 4  
let third = first * second  
console.log(third)  

logged 176

let first = "2" + 2  
let second = 4 + 4  
let third = first / second  
console.log(third)  

logged 2.75

useEffect and event listeners

I need to update a database after an event is emitted from contract. I’m concerned about instances where the contract emits another SomeEvent before the DB operations finish, causing the useEffect to retrigger before the first update is complete. Is this a genuine concern and how is it usually handled?

    useEffect(() => {
        contract.on("SomeEvent", (_a, _b) => {
            ...perform DB operations here!
        })

        /* Handle unmounts */
        return () => {
            contract.removeAllListeners("SomeEvent");
        }
    }, [])

My javascript works on firebox but not on chrome?

I have the following code

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Followers and Following List Comparison</title>
    <!-- <link rel="stylesheet" type="text/css" href="../styles.css" />  -->

</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js"></script>



<div class="follows">
    <div class="followers">
        <h2>Upload Followers List</h2>
        <input id="followers" type="file" accept="application/json" />
        <textarea id="followers_result" rows=25 cols=50></textarea>
    </div>

    <div class="following">
        <h2>Upload Following List</h2>
        <input id="following" type="file" accept="application/json" />
        <textarea id="following_result" rows=25 cols=50></textarea>
    </div>

    <div class="result">
        <h2>People who are not following you</h2>
        <textarea id="result" rows=25 cols=50></textarea>
    </div>
</div>


<script type="text/javascript">



//followers list
 document.getElementById('followers').onchange = function(evt) {
        try {
            let files = evt.target.files;
            if (!files.length) {
                alert('No file selected!');
                return;
            }
            let file = files[0];
            let reader = new FileReader();
            const self = this;
            reader.onload = (event) => {
                // console.log(event.target.result);
                obj = JSON.parse(event.target.result);
                // console.log(obj)
                followers_data = Object.keys(obj).map(key => {
                    return obj[key];
                });
                  followers = followers_data.flat(1);

                  follower_array = [];
                  for(i=0; i < followers.length; i++){
                    follower_array.push(followers[i].string_list_data[0].href);
                }
                // console.log(follower_array);
                // console.log('somethign');
                document.getElementById('followers_result').value = follower_array.join("n");
                followers = document.getElementById('followers_result').value;
                // console.log(followers);
                // followersj = JSON.stringify(followers);
                // spfollowers = JSON.parse(followersj);
                // finalfollowers = spfollowers.split('n');

            };
            reader.readAsText(file);
        } catch (err) {
            console.error(err);
        }
    }



//following list
document.getElementById('following').onchange = function(evt) {
        try {
            let files = evt.target.files;
            if (!files.length) {
                alert('No file selected!');
                return;
            }
            let file = files[0];
            let reader = new FileReader();
            const self = this;
            reader.onload = (event) => {
                // console.log(event.target.result);
                obj = JSON.parse(event.target.result);
                // console.log(obj)
                followers_data = Object.keys(obj).map(key => {
                    return obj[key];
                });
                  followers = followers_data.flat(1);

                  follower_array = [];
                  for(i=0; i < followers.length; i++){
                    follower_array.push(followers[i].string_list_data[0].href);
                }
                // console.log(follower_array);
                document.getElementById('following_result').value = follower_array.join("n");
                // console.log(document.getElementById('followers_result').value);
                following = document.getElementById('followers_result').value;
                // console.log(following);
                // followingj = JSON.stringify(following);
                // spfollowing = JSON.parse(followingj);
                // finalfollowing = spfollowing.split('n');

            };
            reader.readAsText(file);
        } catch (err) {
            console.error(err);
        }
    }

// var el = document.getElementById('followers');
// el.onchange = function(){
//       following = document.getElementById('following_result').value;
//     console.log(following);
//     followingj = JSON.stringify(following);
//     spfollowing = JSON.parse(followingj);
//     finalfollowing = spfollowing.split('n');
//     console.log(finalfollowing);
// };
following = document.getElementById('following_result').value;
console.log(following);
followingj = JSON.stringify(following);
spfollowing = JSON.parse(followingj);
finalfollowing = spfollowing.split('n');
console.log(finalfollowing);

followers = document.getElementById('followers_result').value;
console.log(followers);
followersj = JSON.stringify(followers);
spfollowers = JSON.parse(followersj);
finalfollowers = spfollowers.split('n');
console.log(finalfollowers);

finalfollowing = finalfollowing.filter(val => !finalfollowers.includes(val));
users = [];
finalfollowing.forEach(function(item){
    user = item.split('https://www.instagram.com/');
    users.push(user[1]);
})

console.log(users);
t = JSON.stringify(users);
f = t.replaceAll('"', '');
k = f.replaceAll('[', '');
b = k.replaceAll(']', '');
s = b.replaceAll(',', 'n')
console.log(s);
document.getElementById('result').value = s



console.log(users);





</script>



</body>
</html>

I am uploading json files and comparing the files for those that dont follow me. When I use it on firefox, refreshing the page populates the result in the textarea but when i do it on chrome it doesnt work. I also tried to create a function (onchange) where when the file was uploaded, it would do something because i thought it was an issue with the text not displaying bc it wasnt uploaded first but that didnt work. any help would be appreciated pls.

Background style not working on swiper js images

I’m trying to add background style to my slider image but it doesn’t seem to work
“background: linear-gradient(180deg,transparent 0,#000 100%);”

<div class="swiper mySwiper">
      <div class="swiper-wrapper">
        <div class="swiper-slide">
     <img src="img" alt=""></div>
    <div class="swiper-slide"><img  src="img" alt=""></div>
    <div class="swiper-slide"><img src="img" alt=""></div>
  </div>
  <div class="swiper-pagination"></div>
</div>

.swiper {
    width: auto;
    height: 100%;
  }


  .swiper-slide {
    text-align: center;
    font-size: 18px;
    background: #fff;
    padding: 60px 0 20px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
    align-items: center;
    margin: 0 auto;
     }


.swiper-slide img {
    position: relative;
    display: block;
    width: 75%;
    height: 100%;
    object-fit: cover; 
    background: blue linear-gradient(180deg,transparent 0,#000 100%);
/*   Does not work */
  }

var swiper = new Swiper(".mySwiper", {
  slidesPerView: 3,
  spaceBetween: 30,
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },
});

Please check here for image preview :
https://codepen.io/Knightcore16/pen/oNMqvaV

Please help me

How to create a sidebar in my Google Sheets app by using the appsscript.json file?

I’m trying to create a sidebar in my Google Sheets app by using the appsscript.json file.

I get the following error:

“appsscript.json” has errors: Invalid manifest: unknown fields: [sidebar].

What am I doing wrong and how do I fix it?

Does Google Apps Script runtime even support the creation of sidebars in Google Sheets using the appsscript.json file?

appsscript.json
{
  "timeZone": "America/New_York",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
    "https://www.googleapis.com/auth/script.container.ui",
    "https://www.googleapis.com/auth/spreadsheets"
  ],
  "sidebar": {
    "name": "My Sidebar Add-on",
    "iconUrl": "https://path/to/icon.png",
    "url": "https://path/to/sidebar.html"
  }
}