Skip to content

Commit 82d62b3

Browse files
committed
Revert "use null"
This reverts commit 379168a.
1 parent a882dac commit 82d62b3

3 files changed

Lines changed: 17 additions & 23 deletions

File tree

frontend/src/ts/components/modals/EditProfileModal.tsx

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { getSnapshot } from "../../states/snapshot";
1919
import { cn } from "../../utils/cn";
2020
import { AnimatedModal } from "../common/AnimatedModal";
2121
import { Button } from "../common/Button";
22-
import { Fa } from "../common/Fa";
2322
import { UserBadge } from "../common/UserBadge";
2423
import { Checkbox } from "../ui/form/Checkbox";
2524
import { InputField } from "../ui/form/InputField";
@@ -42,7 +41,7 @@ export function EditProfile() {
4241
website: snapshot.details?.socialProfiles?.website ?? "",
4342
showActivityOnPublicProfile:
4443
snapshot.details?.showActivityOnPublicProfile ?? true,
45-
badgeId: badges.find((b) => b.selected)?.id ?? null,
44+
badgeId: badges.find((b) => b.selected)?.id ?? -1,
4645
},
4746
onSubmit: async ({ value }) => {
4847
const updates = {
@@ -59,7 +58,7 @@ export function EditProfile() {
5958
const response = await Ape.users.updateProfile({
6059
body: {
6160
...updates,
62-
selectedBadgeId: value.badgeId ?? undefined,
61+
selectedBadgeId: value.badgeId,
6362
},
6463
});
6564

@@ -226,25 +225,7 @@ export function EditProfile() {
226225
<form.Field name="badgeId">
227226
{(field) => (
228227
<div class="flex flex-wrap gap-2">
229-
<Button
230-
class={cn("p-0 opacity-25 hover:opacity-100", {
231-
"opacity-100": field().state.value === null,
232-
})}
233-
active={field().state.value === null}
234-
onClick={() => field().handleChange(null)}
235-
>
236-
<div
237-
class="rounded-[0.5em] p-1.5 text-em-sm"
238-
style={{
239-
background: "var(--sub-color)",
240-
color: "var(--text-color)",
241-
}}
242-
>
243-
<Fa icon="fa-frown-open" />
244-
<span class="pl-[0.75em]">none</span>
245-
</div>
246-
</Button>
247-
<For each={badges}>
228+
<For each={[{ id: -1 }, ...badges]}>
248229
{(badge) => (
249230
<Button
250231
class={cn("p-0 opacity-25 hover:opacity-100", {

frontend/src/ts/controllers/badge-controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ export type UserBadge = {
1212
};
1313

1414
export const badges: Record<number, UserBadge> = {
15+
"-1": {
16+
id: -1,
17+
name: "none",
18+
description: "",
19+
icon: "fa-frown-open",
20+
color: "var(--text-color)",
21+
background: "var(--sub-color)",
22+
},
1523
1: {
1624
id: 1,
1725
name: "Developer",

packages/contracts/src/users.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,12 @@ export const GetProfileResponseSchema = responseWithData(UserProfileSchema);
256256
export type GetProfileResponse = z.infer<typeof GetProfileResponseSchema>;
257257

258258
export const UpdateUserProfileRequestSchema = UserProfileDetailsSchema.extend({
259-
selectedBadgeId: z.number().int().nonnegative().optional(),
259+
selectedBadgeId: z
260+
.number()
261+
.int()
262+
.nonnegative()
263+
.optional()
264+
.or(z.literal(-1).describe("no badge selected")), //TODO remove the -1, use optional?
260265
});
261266
export type UpdateUserProfileRequest = z.infer<
262267
typeof UpdateUserProfileRequestSchema

0 commit comments

Comments
 (0)