Download survey_apps/main_study/src/components/ProlificIdForm.js from sciminds/same-words-different-judgements: direct link, hf CLI and curl.
- Browser
- Download file 3.91 kB
-
https://huggingface.co/datasets/sciminds/same-words-different-judgements/resolve/main/survey_apps/main_study/src/components/ProlificIdForm.js
- Command line
-
hf download hf://datasets/sciminds/same-words-different-judgements/survey_apps/main_study/src/components/ProlificIdForm.js
-
curl -L -o ProlificIdForm.js https://huggingface.co/datasets/sciminds/same-words-different-judgements/resolve/main/survey_apps/main_study/src/components/ProlificIdForm.js
3.91 kB
| import { useState, useEffect } from "react"; | |
| import { db, auth } from "../firebase"; | |
| import { doc, setDoc } from "firebase/firestore"; | |
| function ProlificIdForm({ onComplete }) { | |
| const [prolificId, setProlificId] = useState(""); | |
| const [error, setError] = useState(""); | |
| const [loading, setLoading] = useState(true); | |
| useEffect(() => { | |
| const captureUrlParams = async () => { | |
| // Get URL parameters | |
| const urlParams = new URLSearchParams(window.location.search); | |
| const prolificPid = urlParams.get('PROLIFIC_PID'); | |
| const studyId = urlParams.get('STUDY_ID'); | |
| const sessionId = urlParams.get('SESSION_ID'); | |
| // If Prolific parameters exist, automatically save and proceed | |
| if (prolificPid) { | |
| try { | |
| await setDoc(doc(db, "participants", auth.currentUser.uid), { | |
| prolificPid: prolificPid, | |
| prolificStudyId: studyId || null, | |
| prolificSessionId: sessionId || null, | |
| prolificDataCapturedAt: new Date().toISOString() | |
| }, { merge: true }); | |
| onComplete(); | |
| } catch (err) { | |
| console.error("Error saving Prolific data:", err); | |
| setError("An error occurred saving your information. Please try again."); | |
| setLoading(false); | |
| } | |
| } else { | |
| // No URL parameters, show manual entry form | |
| setLoading(false); | |
| } | |
| }; | |
| captureUrlParams(); | |
| }, [onComplete]); | |
| const handleSubmit = async (e) => { | |
| e.preventDefault(); | |
| if (!prolificId.trim()) { | |
| setError("Please enter your Prolific ID."); | |
| return; | |
| } | |
| try { | |
| await setDoc(doc(db, "participants", auth.currentUser.uid), { | |
| prolificPid: prolificId.trim(), | |
| prolificStudyId: null, | |
| prolificSessionId: null, | |
| prolificDataCapturedAt: new Date().toISOString(), | |
| manualEntry: true | |
| }, { merge: true }); | |
| onComplete(); | |
| } catch (err) { | |
| console.error("Error saving Prolific ID:", err); | |
| setError("An error occurred. Please try again."); | |
| } | |
| }; | |
| if (loading) { | |
| return ( | |
| <div style={{ | |
| minHeight: '100vh', | |
| display: 'flex', | |
| alignItems: 'center', | |
| justifyContent: 'center', | |
| padding: '2rem' | |
| }}> | |
| <p>Loading...</p> | |
| </div> | |
| ); | |
| } | |
| return ( | |
| <div style={{ | |
| minHeight: '100vh', | |
| display: 'flex', | |
| alignItems: 'center', | |
| justifyContent: 'center', | |
| padding: '2rem' | |
| }}> | |
| <form | |
| onSubmit={handleSubmit} | |
| style={{ | |
| display: 'flex', | |
| flexDirection: 'column', | |
| gap: '1.5rem', | |
| maxWidth: '400px', | |
| width: '100%' | |
| }} | |
| > | |
| <h2 style={{ margin: 0 }}>Welcome</h2> | |
| <p style={{ margin: 0 }}>Please enter your Prolific ID to begin the study.</p> | |
| {error && <p style={{ color: "red", margin: 0 }}>{error}</p>} | |
| <label style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}> | |
| <strong>Prolific ID:</strong> | |
| <input | |
| type="text" | |
| value={prolificId} | |
| onChange={(e) => setProlificId(e.target.value)} | |
| placeholder="Enter your Prolific ID" | |
| required | |
| style={{ | |
| padding: '0.5rem', | |
| fontSize: '16px', | |
| border: '1px solid #ccc', | |
| borderRadius: '4px' | |
| }} | |
| /> | |
| </label> | |
| <button | |
| type="submit" | |
| style={{ | |
| width: 'fit-content', | |
| alignSelf: 'flex-start', | |
| padding: '0.5rem 1rem', | |
| fontSize: '16px', | |
| backgroundColor: '#007bff', | |
| color: 'white', | |
| border: 'none', | |
| borderRadius: '5px', | |
| cursor: 'pointer' | |
| }} | |
| > | |
| Continue | |
| </button> | |
| </form> | |
| </div> | |
| ); | |
| } | |
| export default ProlificIdForm; | |