Skip to content

Commit

Permalink
Removed unnecessary statements and combined parallel Promises
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobellerbrock committed Sep 29, 2024
1 parent a72009e commit 0f8fbb8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 44 deletions.
70 changes: 33 additions & 37 deletions apps/web/src/actions/user-profile-mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,40 @@ export const modifyRegistrationData = authenticatedAction(
},
{ userId },
) => {
const user = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, userId),
});
const user = await getUser(userId);
if (!user) throw new Error("User not found");
await db
.update(userCommonData)
.set({
age,
gender,
race,
ethnicity,
shirtSize,
dietRestrictions: dietaryRestrictions,
accommodationNote,
phoneNumber,
countryOfResidence,
})
.where(eq(userCommonData.clerkID, user.clerkID));
await db
.update(userHackerData)
.set({
isEmailable,
university,
major,
levelOfStudy,
schoolID,
hackathonsAttended,
softwareExperience: softwareBuildingExperience,
heardFrom: heardAboutEvent,
GitHub: github,
LinkedIn: linkedin,
PersonalWebsite: personalWebsite,
})
.where(eq(userHackerData.clerkID, user.clerkID));
await Promise.all([
db
.update(userCommonData)
.set({
age,
gender,
race,
ethnicity,
shirtSize,
dietRestrictions: dietaryRestrictions,
accommodationNote,
phoneNumber,
countryOfResidence,
})
.where(eq(userCommonData.clerkID, user.clerkID)),
db
.update(userHackerData)
.set({
isEmailable,
university,
major,
levelOfStudy,
schoolID,
hackathonsAttended,
softwareExperience: softwareBuildingExperience,
heardFrom: heardAboutEvent,
GitHub: github,
LinkedIn: linkedin,
PersonalWebsite: personalWebsite,
})
.where(eq(userHackerData.clerkID, user.clerkID)),
]);
return {
success: true,
newAge: age,
Expand Down Expand Up @@ -103,10 +103,6 @@ export const modifyResume = authenticatedAction(
resume: z.string(),
}),
async ({ resume }, { userId }) => {
const user = await db.query.userHackerData.findFirst({
where: eq(userHackerData.clerkID, userId),
});
if (!user) throw new Error("User not found");
await db
.update(userHackerData)
.set({ resume })
Expand Down
20 changes: 13 additions & 7 deletions apps/web/src/components/settings/ProfileSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ export default function ProfileSettings({ profile }: ProfileSettingsProps) {
const [newBio, setNewBio] = useState(profile.bio);
const [newProfileImage, setNewProfileImage] = useState<File | null>(null);
let curSkills: Tag[] = [];
for (let i = 0; i < profile.skills.length; i++) {
let t: Tag = {
id: profile.skills[i],
text: profile.skills[i],
};
curSkills.push(t);
}
// for (let i = 0; i < profile.skills.length; i++) {
// let t: Tag = {
// id: profile.skills[i],
// text: profile.skills[i],
// };
// curSkills.push(t);
// }
profile.skills.map((skill) => {
curSkills.push({
id: skill,
text: skill,
});
});
const [newSkills, setNewSkills] = useState<Tag[]>(curSkills);
const [newDiscord, setNewDiscord] = useState(profile.discord || "");

Expand Down

0 comments on commit 0f8fbb8

Please sign in to comment.