Download survey_apps/main_study/src/components/PostSurveyForm.js from sciminds/same-words-different-judgements: direct link, hf CLI and curl.
- Browser
- Download file 3.56 kB
-
https://huggingface.co/datasets/sciminds/same-words-different-judgements/resolve/main/survey_apps/main_study/src/components/PostSurveyForm.js
- Command line
-
hf download hf://datasets/sciminds/same-words-different-judgements/survey_apps/main_study/src/components/PostSurveyForm.js
-
curl -L -o PostSurveyForm.js https://huggingface.co/datasets/sciminds/same-words-different-judgements/resolve/main/survey_apps/main_study/src/components/PostSurveyForm.js
3.56 kB
| import { useState } from "react"; | |
| import { db, auth } from "../firebase"; | |
| import { doc, setDoc } from "firebase/firestore"; | |
| const PostSurveyForm = ({ onComplete }) => { | |
| const [difficulty, setDifficulty] = useState(""); | |
| const [feedback, setFeedback] = useState(""); | |
| const [error, setError] = useState(""); | |
| const handleSubmit = async (e) => { | |
| e.preventDefault(); | |
| if (!difficulty) { | |
| setError("Please select a difficulty rating."); | |
| return; | |
| } | |
| try { | |
| await setDoc(doc(db, "participants", auth.currentUser.uid), { | |
| postSurvey: { | |
| difficulty: parseInt(difficulty, 10), | |
| feedback: feedback.trim() || null, | |
| submittedAt: new Date().toISOString() | |
| }, | |
| postSurveyCompleted: true, | |
| studyCompleted: true, | |
| studyCompletedAt: new Date().toISOString() | |
| }, { merge: true }); | |
| onComplete(); | |
| } catch (err) { | |
| console.error("Error saving post-survey feedback:", err); | |
| setError("An error occurred. Please try again."); | |
| } | |
| }; | |
| return ( | |
| <div style={{ paddingLeft: "2rem" }}> | |
| <form | |
| onSubmit={handleSubmit} | |
| style={{ | |
| display: "flex", | |
| flexDirection: "column", | |
| gap: "1.5rem", | |
| maxWidth: "600px" | |
| }} | |
| > | |
| <h2>Post-Study Questions</h2> | |
| {error && <p style={{ color: "red" }}>{error}</p>} | |
| <div> | |
| <label style={{ display: "block", marginBottom: "0.5rem", fontWeight: "bold" }}> | |
| How difficult was this task? * | |
| </label> | |
| <div style={{ display: "flex", flexDirection: "column", gap: "0.5rem" }}> | |
| {[1, 2, 3, 4, 5].map((value) => ( | |
| <label | |
| key={value} | |
| style={{ | |
| display: "flex", | |
| alignItems: "center", | |
| gap: "0.5rem", | |
| cursor: "pointer" | |
| }} | |
| > | |
| <input | |
| type="radio" | |
| name="difficulty" | |
| value={value} | |
| checked={difficulty === String(value)} | |
| onChange={(e) => setDifficulty(e.target.value)} | |
| style={{ cursor: "pointer" }} | |
| /> | |
| <span> | |
| {value === 1 && "1 - Very Easy"} | |
| {value === 2 && "2 - Easy"} | |
| {value === 3 && "3 - Moderate"} | |
| {value === 4 && "4 - Difficult"} | |
| {value === 5 && "5 - Very Difficult"} | |
| </span> | |
| </label> | |
| ))} | |
| </div> | |
| </div> | |
| <label style={{ display: "flex", flexDirection: "column", gap: "0.5rem" }}> | |
| <span style={{ fontWeight: "bold" }}> | |
| Additional comments or feedback (optional): | |
| </span> | |
| <textarea | |
| value={feedback} | |
| onChange={(e) => setFeedback(e.target.value)} | |
| rows={5} | |
| style={{ | |
| padding: "0.5rem", | |
| fontFamily: "inherit", | |
| fontSize: "inherit", | |
| resize: "vertical" | |
| }} | |
| placeholder="Please share any thoughts about your experience..." | |
| /> | |
| </label> | |
| <button | |
| type="submit" | |
| style={{ | |
| width: "fit-content", | |
| alignSelf: "flex-start", | |
| padding: "0.5rem 1rem", | |
| cursor: "pointer" | |
| }} | |
| > | |
| Submit | |
| </button> | |
| </form> | |
| </div> | |
| ); | |
| }; | |
| export default PostSurveyForm; | |