Skip to content

Commit

Permalink
Username display error Resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
subratamondal1 committed Mar 24, 2024
1 parent a6794f1 commit 8f77b7e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
23 changes: 22 additions & 1 deletion frontend/react-app/src/auth/RegisterPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ const RegisterPage = () => {
const [isNLP, setIsNLP] = useState(false)
const [isLLM, setIsLLM] = useState(false)

const handlePreference = () => {
// Initialize an empty string to store preferences
let preferences = ""

// Check each state and add the corresponding term to the preference string
if (isML) preferences += " ML"
if (isCV) preferences += " CV"
if (isNLP) preferences += " NLP"
if (isLLM) preferences += " LLM"

// Remove leading space (if any)
preferences = preferences.trim()

// You can use this preference string for further processing
console.log(preferences) // Output: "ML CV LLM"
}

useEffect(() => {
userRef.current.focus()
}, [])
Expand Down Expand Up @@ -63,7 +80,7 @@ const RegisterPage = () => {
return
}
try {
const response = await axios.post(REGISTER_URL, JSON.stringify({ username: user, password: pwd, password2: matchPwd, email: user }), {
const response = await axios.post(REGISTER_URL, JSON.stringify({ username: user, password: pwd, password2: matchPwd, email: user, preferences }), {
headers: { "Content-Type": "application/json" },
withCredentials: true,
})
Expand Down Expand Up @@ -231,18 +248,22 @@ const RegisterPage = () => {
<Choice
isChecked={isML}
setChoiceState={setIsML}
onPreferenceChange={handlePreference}
name="ML"></Choice>
<Choice
isChecked={isCV}
setChoiceState={setIsCV}
onPreferenceChange={handlePreference}
name="CV"></Choice>
<Choice
isChecked={isNLP}
setChoiceState={setIsNLP}
onPreferenceChange={handlePreference}
name="NLP"></Choice>
<Choice
isChecked={isLLM}
setChoiceState={setIsLLM}
onPreferenceChange={handlePreference}
name="LLM"></Choice>
</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions frontend/react-app/src/components/Choice.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
function Choice(props) {
const { name, isChecked, setChoiceState } = props;
const { name, isChecked, setChoiceState, onPreferenceChange } = props
const handleChange = () => {
setChoiceState(!isChecked) // Toggle checkbox state
onPreferenceChange() // Call the handlePreference function passed as a prop
}
return (
<div>
<input
id={name}
checked={isChecked}
type="checkbox"
className="default:ring-2 mr-2"
onChange={() => setChoiceState(!isChecked)}
onChange={handleChange}
/>
<label htmlFor="ml">{name}</label>
</div>
);
)
}

export default Choice;

0 comments on commit 8f77b7e

Please sign in to comment.