Spaces:
Sleeping
Sleeping
Update web/src/components/ProfileEditor.tsx
Browse files
web/src/components/ProfileEditor.tsx
CHANGED
|
@@ -23,6 +23,7 @@ export function ProfileEditor({ user, onSave, onClose }: ProfileEditorProps) {
|
|
| 23 |
const [yearLevel, setYearLevel] = useState(user.yearLevel ?? "");
|
| 24 |
const [major, setMajor] = useState(user.major ?? "");
|
| 25 |
|
|
|
|
| 26 |
const [bio, setBio] = useState(user.bio ?? "");
|
| 27 |
|
| 28 |
const [learningStyle, setLearningStyle] = useState(user.learningStyle ?? "visual");
|
|
@@ -31,17 +32,21 @@ export function ProfileEditor({ user, onSave, onClose }: ProfileEditorProps) {
|
|
| 31 |
const [photoPreview, setPhotoPreview] = useState<string | null>(user.avatarUrl ?? null);
|
| 32 |
const fileInputRef = useRef<HTMLInputElement>(null);
|
| 33 |
|
| 34 |
-
//
|
| 35 |
useEffect(() => {
|
| 36 |
setName(user.name ?? "");
|
| 37 |
setEmail(user.email ?? "");
|
|
|
|
| 38 |
setStudentId(user.studentId ?? "");
|
| 39 |
setDepartment(user.department ?? "");
|
| 40 |
setYearLevel(user.yearLevel ?? "");
|
| 41 |
setMajor(user.major ?? "");
|
|
|
|
| 42 |
setBio(user.bio ?? "");
|
|
|
|
| 43 |
setLearningStyle(user.learningStyle ?? "visual");
|
| 44 |
setLearningPace(user.learningPace ?? "moderate");
|
|
|
|
| 45 |
setPhotoPreview(user.avatarUrl ?? null);
|
| 46 |
}, [
|
| 47 |
user.name,
|
|
@@ -66,13 +71,18 @@ export function ProfileEditor({ user, onSave, onClose }: ProfileEditorProps) {
|
|
| 66 |
...user,
|
| 67 |
name: name.trim(),
|
| 68 |
email: email.trim(),
|
|
|
|
| 69 |
studentId: studentId.trim() || undefined,
|
| 70 |
department: department.trim() || undefined,
|
| 71 |
yearLevel: yearLevel || undefined,
|
| 72 |
major: major.trim() || undefined,
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
| 74 |
learningStyle: learningStyle || undefined,
|
| 75 |
learningPace: learningPace || undefined,
|
|
|
|
| 76 |
avatarUrl: photoPreview || undefined,
|
| 77 |
};
|
| 78 |
|
|
@@ -224,7 +234,7 @@ export function ProfileEditor({ user, onSave, onClose }: ProfileEditorProps) {
|
|
| 224 |
</div>
|
| 225 |
</div>
|
| 226 |
|
| 227 |
-
{/* Bio */}
|
| 228 |
<div className="space-y-2">
|
| 229 |
<Label htmlFor="edit-bio">Bio</Label>
|
| 230 |
<Textarea
|
|
@@ -235,7 +245,7 @@ export function ProfileEditor({ user, onSave, onClose }: ProfileEditorProps) {
|
|
| 235 |
className="min-h-[100px] resize-none"
|
| 236 |
maxLength={200}
|
| 237 |
/>
|
| 238 |
-
<p className="text-xs text-muted-foreground">
|
| 239 |
</div>
|
| 240 |
|
| 241 |
{/* Learning Preferences */}
|
|
@@ -286,4 +296,3 @@ export function ProfileEditor({ user, onSave, onClose }: ProfileEditorProps) {
|
|
| 286 |
</Dialog>
|
| 287 |
);
|
| 288 |
}
|
| 289 |
-
|
|
|
|
| 23 |
const [yearLevel, setYearLevel] = useState(user.yearLevel ?? "");
|
| 24 |
const [major, setMajor] = useState(user.major ?? "");
|
| 25 |
|
| 26 |
+
// ✅ bio is editable here (user can override Clare-generated bio)
|
| 27 |
const [bio, setBio] = useState(user.bio ?? "");
|
| 28 |
|
| 29 |
const [learningStyle, setLearningStyle] = useState(user.learningStyle ?? "visual");
|
|
|
|
| 32 |
const [photoPreview, setPhotoPreview] = useState<string | null>(user.avatarUrl ?? null);
|
| 33 |
const fileInputRef = useRef<HTMLInputElement>(null);
|
| 34 |
|
| 35 |
+
// ✅ Keep fields in sync if user changes while dialog is open
|
| 36 |
useEffect(() => {
|
| 37 |
setName(user.name ?? "");
|
| 38 |
setEmail(user.email ?? "");
|
| 39 |
+
|
| 40 |
setStudentId(user.studentId ?? "");
|
| 41 |
setDepartment(user.department ?? "");
|
| 42 |
setYearLevel(user.yearLevel ?? "");
|
| 43 |
setMajor(user.major ?? "");
|
| 44 |
+
|
| 45 |
setBio(user.bio ?? "");
|
| 46 |
+
|
| 47 |
setLearningStyle(user.learningStyle ?? "visual");
|
| 48 |
setLearningPace(user.learningPace ?? "moderate");
|
| 49 |
+
|
| 50 |
setPhotoPreview(user.avatarUrl ?? null);
|
| 51 |
}, [
|
| 52 |
user.name,
|
|
|
|
| 71 |
...user,
|
| 72 |
name: name.trim(),
|
| 73 |
email: email.trim(),
|
| 74 |
+
|
| 75 |
studentId: studentId.trim() || undefined,
|
| 76 |
department: department.trim() || undefined,
|
| 77 |
yearLevel: yearLevel || undefined,
|
| 78 |
major: major.trim() || undefined,
|
| 79 |
+
|
| 80 |
+
// ✅ allow user edit
|
| 81 |
+
bio: (bio ?? "").slice(0, 200),
|
| 82 |
+
|
| 83 |
learningStyle: learningStyle || undefined,
|
| 84 |
learningPace: learningPace || undefined,
|
| 85 |
+
|
| 86 |
avatarUrl: photoPreview || undefined,
|
| 87 |
};
|
| 88 |
|
|
|
|
| 234 |
</div>
|
| 235 |
</div>
|
| 236 |
|
| 237 |
+
{/* Bio (Editable) */}
|
| 238 |
<div className="space-y-2">
|
| 239 |
<Label htmlFor="edit-bio">Bio</Label>
|
| 240 |
<Textarea
|
|
|
|
| 245 |
className="min-h-[100px] resize-none"
|
| 246 |
maxLength={200}
|
| 247 |
/>
|
| 248 |
+
<p className="text-xs text-muted-foreground">Max 200 characters. You can edit this anytime.</p>
|
| 249 |
</div>
|
| 250 |
|
| 251 |
{/* Learning Preferences */}
|
|
|
|
| 296 |
</Dialog>
|
| 297 |
);
|
| 298 |
}
|
|
|