-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathquestions.js
68 lines (62 loc) · 1.6 KB
/
questions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Importing the functions we need from Firebase SDKS
import {
ref,
onValue,
push,
get,
serverTimestamp,
} from "https://www.gstatic.com/firebasejs/10.7.1/firebase-database.js";
import { db, firestore, auth } from "./firebase.js";
import { clearQuestionList, addQuestionToList, setUserNameOnQuestion } from "./utils.js";
//
// TODO create a reference to the questions list in the database
//
// this function gets passed the question text from the form
// this is where we'll add it to the database
//
function handleQuestionSubmission(questionText) {
// TODO use the push function to add the question to the database
// the questions should have the following fields:
// - text: the question text
// - timestamp: the current server time
//
}
// grab questions from database and update the ui
//
// TODO use onValue to grab the questions from the database
// https://firebase.google.com/docs/database/web/read-and-write#read_data
// clear the question list to reset the UI and then add each question to the list
//
// ===== already implemented stuff
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
// ----- no need to edit stuff below this line but feel free to reference it
// intercept form submission and add question to database
const questionFormElement = document.getElementById("question-form");
questionFormElement.addEventListener("submit", async (e) => {
e.preventDefault();
const questionInputElement = document.getElementById("question-input");
const questionText = questionInputElement.value;
questionInputElement.value = "";
handleQuestionSubmission(questionText);
});