xxxxxxxxxx
85
// var database;
var nameInput;
var submitButton;
var database;
function setup() {
createCanvas(400, 400);
const firebaseConfig = {
apiKey: "AIzaSyBoE_l0nQB187ySUApOpRT9lIVab1bhR8g",
authDomain: "comcom-example-2024.firebaseapp.com",
projectId: "comcom-example-2024",
storageBucket: "comcom-example-2024.appspot.com",
messagingSenderId: "328185628717",
appId: "1:328185628717:web:687ed4f4645086df5d50a4",
measurementId: "G-60Q7VM7QT9"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize Realtime Database and get a reference to the service
database = getDatabase(app,'https://comcom-example-2024-default-rtdb.firebaseio.com/');
console.log(database)
nameInput = createInput ('name');
submitButton = createButton('submit');
submitButton.mousePressed(submitName);
}
function draw() {
background(204,14,14);
textSize(30);
text("hey, this is a test",75,50);
}
function submitName(){
var data = {
name: nameInput.value()
}
//console.log(data);
var ref = database.ref('name');
ref.push(data);
}
function gotData(data){
var namelisting = selectAll('.namelisting');
for (var j=0; j<namelisting.length; j++){
namelisting[j].remove();
}
//code for list of names
//console.log(data.val());
var name = data.val();
var keys
if (keys != null) {
keys = Object.keys(name);
// console.log(keys);
for (var i = 0; i<keys.length; i++){
var k = keys[i];
var nameYass = name[k].name;
// console.log(nameYass);
var li = createElement('li', nameYass)
li.class('namelisting');
li.parent('namelist');
}
}
}
function errorData(err){
console.log('Error!');
console.log(err);
}