Cannot get data out of composable to fetch firebase data

I have a composable in vue that uploads data to firebase storage. It works, but I cannot get the data out of the composable. I think it has something to do with a return or where I’m defining terms?

The code below is built around the documentation available for firebase Storage (https://firebase.google.com/docs/storage/web/upload-files).

useStorage.js

import { ref } from "vue";
import { projectStorage } from "../firebase/config";
import {
  uploadBytesResumable,
  getDownloadURL,
  ref as storageRef,
} from "@firebase/storage";

const useStorage = () => {
  const error = ref(null);
  const url = ref(null);
  const filePath = ref(null);

  const uploadImage = async (file) => {
    filePath.value = `images/${file.name}`;

    const storageReference = storageRef(projectStorage, 
 filePath.value);

    const uploadTask = 
 uploadBytesResumable(storageReference, file);

    await uploadTask.on(
      "state_changed",
      (snapshot) => {
        const progress =
          (snapshot.bytesTransferred / snapshot.totalBytes) 
 * 100;
        console.log("Upload is " + progress + "% done");
      },
      (err) => {
        console.log(err);
        error.value = err.message;
      },
      () => {
 
        
 getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) 
 => {
          console.log("File available at", downloadURL);
          url.value = downloadURL;
          console.log(url.value); <--HAS CORRECT VALUE
          return url.value; <--DOESNT DO ANYTHING
        });
      }
    );
    console.log(url.value);
  };

   return { url, filePath, error, uploadImage }; <--URL IS 
NOT RETURNING OUT OF THIS COMPOSABLE
};

export default useStorage;

Vuetify : place title/subtitle next to icon in a card

enter image description here

I have a card component, and I’m trying to place my title, subtitle at the right of my icon.It some how kept going down to the next line. I’m new to Vuetify.

<template>
    <v-container fluid class="my-5">
        <v-row>
            <v-flex col-xs-12>
                <v-card elevation="2" class="pa-5">
                    <v-flex xs3>
                        <v-btn text color="black">
                            <v-icon left large class="mr-5">{{ icon }}</v-icon>
                        </v-btn>
                    </v-flex>
                    <v-flex xs9>
                        <v-card-title>
                            {{ title }}
                        </v-card-title>

                        <v-card-subtitle> {{ subtitle }} </v-card-subtitle>
                    </v-flex>
                </v-card>
            </v-flex>
        </v-row>
    </v-container>
</template>
<script>
export default {
    name: 'MainPanel',
    props: {
        icon: String,
        title: String,
        subtitle: String
    }
}
</script>
<style></style>

Please let me know how can I achive that.

How to pass props from one Component to another component with onClick() event in React.js

Quick Help Needed! I have Two React components Vendors and VendorsList. In Vendors.js Component i have asset.asset_name text rendered in table format. What I want is, When I click on I asset.asset_name, I wanted to pass it’s value from Vendors component to VendorsList component. How could I do this?

Here is code for Two Components

Vendors.js

import React, { useEffect, useState } from "react";
import { axios } from "axios";

const Vendors = () => {
  const [data, setData] = useState({});
  const baseURL =
    "http://127.0.0.1:8000/api/business_process/business-impact/bussiness-assets-detail";

  useEffect(() => {
    axios
      .get(baseURL)
      .then((response) => {
        setData(response.data);
      })
      .then(
        (response) => {},
        (err) => {
          alert("No Data To Show");
        }
      )
      .catch((err) => {
        return false;
      });
  }, []);
  const DisplayData = data.business_assets?.map((asset) => {
    return (
      <tr>
        <td>{asset.business_assets}</td>
        <td onClick={() => alert(asset.asset_name)}>{asset.asset_name}</td>
      </tr>
    );
  });
  return <div></div>;
};

export default Vendors;

**I tried to pass the value here but I ended up alerting the asset.asset_name text.

const DisplayData = data.business_assets?.map((asset) => {
        return (
          <tr>
            <td>{asset.business_assets}</td>
            <td onClick={() => alert(asset.asset_name)}>{asset.asset_name}</td>
          </tr>
        );
      });

Here is VendorsList.js

    import React from "react";
const VendorsList = ({ asset_name}) => {
  const foo = "test" + asset_name;
  return (
    <div>
      <h1>{foo}</h1>
    </div>
  );
};

export default VendorsList;

I need asset.asset_name value to be passed to VendorsList when I click on asset.asset_name value from Vendors component

How to do a web program with displaying continuously updating data without refreshing? [closed]

I’m trying to make a web-based program that could dynamically display some data transmitted from python. The simple structure I imagined is like this.

  1. Python // collect and process data from Twitter (maybe collect data every ten mins)
  2. Transmission // transmit data from python to Html & display by Javascript (every ten mins)
  3. Html & Javascript // display data and update information without refreshing

My question is:
I have figured out a way to achieve step1, but I don’t know how to transmit data from python to Javascript. What framework I should try? What file format should I use? What is the easiest approach?

Would anyone help point me in the right direction? Any example or keyword would be really helpful. Thank you much! Haotian

How to set max date in a kendodatepicker every time another date is chosed

i have two kendodatepickers “startDate” and “endDate”. I want every time the user set a date in startdate, establish the max date one month forward from the selected date to pick in endDate datepicker.

I am setting up the first time in this way:

 $("#datStartDate").kendoDatePicker({
        start: "month",
        depth: "year",
        format: "dd/MM/yyyy",
        dateInput: true,
        change: (e) => {                
            return moc.rangeStartDate("datStartDate", "datEndDate");
        },
        min: new Date(1900, 0, 1),
        max: new Date(),
        value: new Date()
    });

    $("#datEndDate").kendoDatePicker({
        start: "month",
        depth: "year",
        format: "dd/MM/yyyy",
        dateInput: true,
        max: new Date(),
        change: (e) => {
            return moc.rangeEndDate("datStartDate", "datEndDate");
        },
        value: new Date()
    });

I tried this to set the max value, each time the startDate picker is cheanged:

$("#datStartDate").change(() => {
        let startDate = ($("#datStartDate").val()).split("/");
        console.log("cambio de fecha", parseInt(startDate[2]), parseInt(startDate[1]), parseInt(startDate[0]))
        let datePicker = $("#datEndDate").data("kendoDatePicker");
        datePicker.max(new Date(parseInt(startDate[2]), parseInt(startDate[1]), parseInt(startDate[0])));
        datePicker.value(new Date(parseInt(startDate[2]), parseInt(startDate[1]), parseInt(startDate[0])))
    })

It doesnt works and i dont get an error. How can i do this? Thank you so much for you time.

I am using this:

  • KendoUI
  • JavaScript
  • ASP .NET MVC
  • RAZOR
  • jquery

Clickable link within a clickable div, that voids parents’s click event

Is there a way to have a clickable div with a nested <a>, that doesn’t execute the click event on the div when the <a> tag is clicked?

Looking for a vanilla JS solution

const div = document.querySelector('div');
div.addEventListener('click', e => {
  this.console.log('clicked the div');
});
div {
  width: 300px;
  border: 2px solid green;
  padding: 1em;
}
<div> 
<p>This is a button</p>
<a href="/" target="_blank">Link to somewhere else</a>
</div>

clicking a button second time, getting different result

New react developer here, i’m doing my own project, my question is related to a button(material ui), when same button is clicked second time i want that button to get disabled={true}, did not find any examply related to this on stack.

<Button
              onClick={this.startDraw.bind(this)}
              disabled={}
              startIcon={<Brush />}
            >

so at first button is clickable, when it is clicked happens something, but when this same button is clicked second time then button should get disabled (cannot be clicked anymore).
My english is not so good so there could be mistakes.

How do I make inputs generate divs?

I need to make several input fields for user input to type in height, width, color, left and top. And when user clicks “Go”-button it generates a div with same height, width, color, left-right-positioning on the screen.

Something like this: https://imgur.com/a/jNcg7Rr

I can make it work with inputs changing divs, but I cant figure out how to make the Go button generate a fresh div onclick. Thx..

Import Routes from routes.js is crashing my nodemon server

while importing Routes from routes.js nodemon crash is there any new update regarding the importation of Routes from routes.js??

Index.js code

import express from "express";

//components
import Connection from "./database/db.js";
import Routes from "./routes/Route.js";

const app = express();
app.use("/", Routes);

const PORT = 8000;

Connection();
app.listen(PORT, () =>
  console.log(`Server is running successfully on PORT ${PORT}`)
);

Routes.js code

import express from "express";

import {
  newConversation,
  getConversation,
} from "../controller/conversation-controller.js";
import { addUser, getUser } from "../controller/user-controller.js";
import { newMessage, getMessage } from "../controller/message-controller.js";

const route = express.Router();

route.post("/add", addUser);
route.get("/users", getUser);

route.post("/conversation/add", newConversation);
route.post("/conversation/get", getConversation);

route.post("/message/add", newMessage);
route.get("/message/get/:id", getMessage);

export default route;

Issue when dragging text on canvas if slightly scrolled down

When I scroll slightly down on my canvas, it does not allow me to drag my text at all. Examples (These are GIFs) –

https://gyazo.com/e60d2efd924ced758c2c6441391804db

GIF explained: So you saw the drag was working when I was on top of the page but when I scrolled slightly down. It completely stopped working. I added a few console.logs around, and what I know is the click event listener for the canvas is working but it isn’t detected the text when I slightly scroll down on the page.

I based my drag code from: http://jsfiddle.net/m1erickson/9xAGa/ | What you can see is if you change the canvas size width: 667 and height: 800, and when you scroll slightly down, you will have the same issue I am having.

HTML Code:

<div id="middle_container">
        <div class="center_container">
            <canvas id="canvas" width="667px" height="800px"></canvas>
        </div>
</div>

JavaScript Code:

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var $canvas = $("#canvas");
var BB=canvas.getBoundingClientRect();
var offsetX = BB.left;
var offsetY = BB.top;
var mx;
var my;
var texts = [];
var images = [];
var dragF = -1;
var mode = "none";

function draw() {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    for(const { text, x, y, width, height } of texts) {
        ctx.fillText(text, x, y);
    }
}

function addNewText(string_text, arrayname) {
    var y = texts.length * 20 + 20;
    var text = {
        text: string_text,
        x: 20,
        y: y,
        name: arrayname
    };
    ctx.font = "32px verdana";
    ctx.textBaseline = "top";
    text.width = ctx.measureText(text.text).width;
    text.height = 32;

    texts.push(text);
    draw();
}

function myDrag(a,e) {
    if (a == "down") {
        e.preventDefault();
        e.stopPropagation();
        mx=parseInt(e.clientX-offsetX);
        my=parseInt(e.clientY-offsetY);
        for(var i=0;i<texts.length;i++){
            if(hitDrag(mx,my,i)){
                console.log("found");
                dragF = i;
            }
        }
    }
}

addNewText("Hello World", "string1")

$("#canvas").mousedown(function(e) {
    myDrag("down", e);
});

Can’t display JSON code in php when send threw fetch() in Javascript

I have tried to echo my json into my html page with php, but it only prints in console or gives back an error.
I’m pretty new to this so please help.

this is the javascript with fetch and activated onclick to submit one to php

async function hey(){
let click = 1;

await fetch('data.php',{
    method: 'POST',
    header: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify(click),
}).then(response => response.json())
.then(data => {
  console.log(data);
})
.catch((error) => {
  console.error(error);
});}

this is the php but it will only ever print to the console

<?php
$json = file_get_contents('php://input');

echo $json;
?>

Tab events not showing on website, from Facebook API

I am embedding a Facebook events feed through their API to my website (I have a developer account and I am logged into it), however after using the Facebook plugin part https://developers.facebook.com/docs/plugins/page-plugin/# and selecting the event tab, it just shows a header of the page, and nothing else: (Result of the problem here: https://www.hairydogvenue.co.uk/gig-guide )

Is this just a bug on Facebook’s side? It was working fine for many months before, I am also an admin of the page in question.

iframe code here:

<iframe src="https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Fthehairydogderby&tabs=events&width=500&height=850&small_header=false&adapt_container_width=true&hide_cover=false&show_facepile=true&appId=505386827636891" width="500" height="850" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowfullscreen="true" allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share"></iframe>

Filter Object passed on Value Properties

I have an object like this:

let obj = {'machine1':{'err':'404', switch:false},
           'gadget1':{'err':'404', switch:true}}

Would not pass validation. => return false



let obj2 = {'machine2':{'err':'404', switch:false},
           'gadget2':{'err':null, switch:true}}

Would pass validation. => return true

I want to return true when every key in the object in which the switch is set to true does not have any errors (see obj2). (For machine2 the ‘404’ error does not matter, because the switch is set to false.)

I tried something like that, but didn’t get far.

function try() { 
  for (x in obj) {
    obj[x].filter(x=>y.switch === true)
}
}

Thanks for reading!

javascript I want to make an array of tags with different overlapping values in objectArray

Before

  const array = [
    { group: '1', tag: ['sins'] },
    { group: '1', tag: ['sun'] },
    { group: '2', tag: ['red'] },
    { group: '2', tag: ['blue'] },
    { group: '2', tag: ['black'] },
  ];

After

  const array = [
    { group: '1', tag: ['sins', 'sun'] },
    { group: '2', tag: ['red', 'blue', 'black'] },
  ];

I want to change it like the chord above. I want someone to create a cool chord.