🔌 sync with the latest backend contract
Browse files at this commit2c19dff2e78f0c31ff658b5525d64c404fb78f51Parent: 211d704- feat
- 🔌 sync with the latest backend contract
11 changed files +96 -7
- src/api/__tests__/chatbot/chatbot.test.ts +4 -1
- src/api/__tests__/users/users.test.ts +14 -0
- src/api/chatbot/chatbotStreamUrl.ts +7 -0
- src/api/chatbot/index.ts +1 -0
- src/api/client/types.ts +23 -1
- src/api/users/index.ts +1 -0
- src/api/users/postUser.ts +6 -0
- src/components/layout/celebi-panel.tsx +2 -2
- src/components/users/profile-form.tsx +25 -2
- src/i18n/messages.ts +6 -0
- src/pages/profile-page.tsx +7 -1
src/api/__tests__/chatbot/chatbot.test.tsmodified+4 -1
| @@ -1,5 +1,5 @@ | |||
| 1 | import { afterEach, describe, expect, it, vi } from "vitest"; | 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | -import { deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread } from "../../chatbot"; | 2 | +import { chatbotStreamUrl, deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread } from "../../chatbot"; |
| 3 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; | 3 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 4 | 4 | ||
| 5 | describe("chatbot API", () => { | 5 | describe("chatbot API", () => { |
| @@ -38,4 +38,7 @@ describe("chatbot API", () => { | |||
| 38 | expect(url).toBe("/api/chatbot/threads/thread-1/messages/answer-1"); | 38 | expect(url).toBe("/api/chatbot/threads/thread-1/messages/answer-1"); |
| 39 | expect(init?.method).toBe("GET"); | 39 | expect(init?.method).toBe("GET"); |
| 40 | }); | 40 | }); |
| 41 | + it("chatbotStreamUrl builds the SSE path for an EventSource", () => { | ||
| 42 | + expect(chatbotStreamUrl("t 1", "m1")).toBe("/api/chatbot/threads/t%201/messages/m1/stream"); | ||
| 43 | + }); | ||
| 41 | }); | 44 | }); |
src/api/__tests__/users/users.test.tsmodified+14 -0
| @@ -14,6 +14,7 @@ import { postMyAvatar } from "../../users"; | |||
| 14 | import { deleteMyAvatar } from "../../users"; | 14 | import { deleteMyAvatar } from "../../users"; |
| 15 | import { deleteUserAvatar } from "../../users"; | 15 | import { deleteUserAvatar } from "../../users"; |
| 16 | import { getUserAvatarUrl } from "../../users"; | 16 | import { getUserAvatarUrl } from "../../users"; |
| 17 | +import { postUser } from "../../users"; | ||
| 17 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; | 18 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 18 | 19 | ||
| 19 | describe("users API", () => { | 20 | describe("users API", () => { |
| @@ -214,4 +215,17 @@ describe("users API", () => { | |||
| 214 | expect(getUserAvatarUrl("u1", 3)).toBe("/api/users/u1/avatar?v=3"); | 215 | expect(getUserAvatarUrl("u1", 3)).toBe("/api/users/u1/avatar?v=3"); |
| 215 | expect(getUserAvatarUrl("u/1")).toBe("/api/users/u%2F1/avatar"); | 216 | expect(getUserAvatarUrl("u/1")).toBe("/api/users/u%2F1/avatar"); |
| 216 | }); | 217 | }); |
| 218 | + it("postUser posts the new account to /users", async () => { | ||
| 219 | + const mockUser = { id: "u9", username: "ayse", role: "teacher" }; | ||
| 220 | + mockFetchSuccess(mockUser); | ||
| 221 | + | ||
| 222 | + const body = { username: "ayse", password: "secret123", role: "teacher" as const }; | ||
| 223 | + const result = await postUser(body); | ||
| 224 | + expect(result).toEqual(mockUser); | ||
| 225 | + | ||
| 226 | + const [url, init] = lastFetchCall(); | ||
| 227 | + expect(url).toBe("/api/users"); | ||
| 228 | + expect(init?.method).toBe("POST"); | ||
| 229 | + expect(JSON.parse(init?.body as string)).toEqual(body); | ||
| 230 | + }); | ||
| 217 | }); | 231 | }); |
src/api/chatbot/chatbotStreamUrl.tsadded+7 -0
| @@ -0,0 +1,7 @@ | |||
| 1 | +/** | ||
| 2 | + * The SSE URL for one pending turn: `delta` chunks, then one `done` or | ||
| 3 | + * `error`. Not a request — hand it to an `EventSource` (`withCredentials: true`). | ||
| 4 | + */ | ||
| 5 | +export function chatbotStreamUrl(threadId: string, messageId: string): string { | ||
| 6 | + return `/api/chatbot/threads/${encodeURIComponent(threadId)}/messages/${encodeURIComponent(messageId)}/stream`; | ||
| 7 | +} | ||
src/api/chatbot/index.tsmodified+1 -0
| @@ -5,4 +5,5 @@ export * from "./patchChatbotThreadById"; | |||
| 5 | export * from "./deleteChatbotThreadById"; | 5 | export * from "./deleteChatbotThreadById"; |
| 6 | export * from "./postChatbotMessage"; | 6 | export * from "./postChatbotMessage"; |
| 7 | export * from "./postChatbotThread"; | 7 | export * from "./postChatbotThread"; |
| 8 | +export * from "./chatbotStreamUrl"; | ||
| 8 | export * from "./types"; | 9 | export * from "./types"; |
src/api/client/types.tsmodified+23 -1
| @@ -38,6 +38,17 @@ export type ProfileUpdate = { | |||
| 38 | birth_date?: string | null; | 38 | birth_date?: string | null; |
| 39 | display_name?: string | null; | 39 | display_name?: string | null; |
| 40 | bio?: string | null; | 40 | bio?: string | null; |
| 41 | + // The teacher's branş, by name from settings.branches. | ||
| 42 | + branch?: string | null; | ||
| 43 | +}; | ||
| 44 | + | ||
| 45 | +// POST /users (admin): the school office opens an account directly. `role` | ||
| 46 | +// defaults to student on the server; an existing person joins this school only | ||
| 47 | +// when the password matches their credential (409 otherwise). | ||
| 48 | +export type CreateUserInput = { | ||
| 49 | + username: string; | ||
| 50 | + password: string; | ||
| 51 | + role?: Role; | ||
| 41 | }; | 52 | }; |
| 42 | 53 | ||
| 43 | export type PersonRef = { | 54 | export type PersonRef = { |
| @@ -105,6 +116,8 @@ export type Profile = { | |||
| 105 | display_name: string | null; | 116 | display_name: string | null; |
| 106 | role: Role; | 117 | role: Role; |
| 107 | bio: string | null; | 118 | bio: string | null; |
| 119 | + // The teacher's branş, one of settings.branches; null when unset. | ||
| 120 | + branch: string | null; | ||
| 108 | avatar: AvatarMeta | null; | 121 | avatar: AvatarMeta | null; |
| 109 | // Capped at limits.user.max_profile_classes; stats.classes holds the true total. | 122 | // Capped at limits.user.max_profile_classes; stats.classes holds the true total. |
| 110 | classes: ProfileClassRef[]; | 123 | classes: ProfileClassRef[]; |
| @@ -395,6 +408,12 @@ export type ClassMember = { | |||
| 395 | class: string; | 408 | class: string; |
| 396 | user: PersonRef; | 409 | user: PersonRef; |
| 397 | added_by: PersonRef; | 410 | added_by: PersonRef; |
| 411 | + // One stint: a leave-and-rejoin is a fresh row with a fresh id. | ||
| 412 | + joined_at: number; | ||
| 413 | + // Null while the stint is live; the roster routes only list live rows. | ||
| 414 | + left_at: number | null; | ||
| 415 | + // The şube a year rollover copied this member out of; null when placed by hand. | ||
| 416 | + source_class_group: string | null; | ||
| 398 | }; | 417 | }; |
| 399 | 418 | ||
| 400 | // The instance as the class routes return it: an Instance plus who attached | 419 | // The instance as the class routes return it: an Instance plus who attached |
| @@ -833,6 +852,9 @@ export type Limits = { | |||
| 833 | max_class_grade_len: number; | 852 | max_class_grade_len: number; |
| 834 | max_class_members: number; | 853 | max_class_members: number; |
| 835 | max_class_courses: number; | 854 | max_class_courses: number; |
| 855 | + max_academic_year_name_len: number; | ||
| 856 | + min_ders_saati: number; | ||
| 857 | + max_ders_saati: number; | ||
| 836 | }; | 858 | }; |
| 837 | exam: { | 859 | exam: { |
| 838 | max_title_len: number; | 860 | max_title_len: number; |
| @@ -934,7 +956,7 @@ export type Limits = { | |||
| 934 | required_attendance_statuses: string[]; | 956 | required_attendance_statuses: string[]; |
| 935 | }; | 957 | }; |
| 936 | request: { max_page_limit: number; max_request_id_len: number; schedule_past_grace_ms: number; request_timeout_secs: number }; | 958 | request: { max_page_limit: number; max_request_id_len: number; schedule_past_grace_ms: number; request_timeout_secs: number }; |
| 937 | - rate: { window_secs: number; auth_per_minute: number; api_per_minute: number; chatbot_per_minute: number }; | 959 | + rate: { window_secs: number; auth_per_minute: number; api_per_minute: number; chatbot_per_minute: number; rag_per_minute: number }; |
| 938 | // The RAG nest. Message length, thread titles, history depth and the thread | 960 | // The RAG nest. Message length, thread titles, history depth and the thread |
| 939 | // cap are the chatbot's own knobs, republished so a RAG client need not read | 961 | // cap are the chatbot's own knobs, republished so a RAG client need not read |
| 940 | // the chatbot group to bound its input. | 962 | // the chatbot group to bound its input. |
src/api/users/index.tsmodified+1 -0
| @@ -13,3 +13,4 @@ export * from "./postMyAvatar"; | |||
| 13 | export * from "./deleteMyAvatar"; | 13 | export * from "./deleteMyAvatar"; |
| 14 | export * from "./deleteUserAvatar"; | 14 | export * from "./deleteUserAvatar"; |
| 15 | export * from "./getUserAvatarUrl"; | 15 | export * from "./getUserAvatarUrl"; |
| 16 | +export * from "./postUser"; | ||
src/api/users/postUser.tsadded+6 -0
| @@ -0,0 +1,6 @@ | |||
| 1 | +import { client } from "../client"; | ||
| 2 | +import type { CreateUserInput, User } from "../client"; | ||
| 3 | + | ||
| 4 | +export function postUser(body: CreateUserInput): Promise<User> { | ||
| 5 | + return client<User>("/users", { method: "POST", body }); | ||
| 6 | +} | ||
src/components/layout/celebi-panel.tsxmodified+2 -2
| @@ -1,6 +1,6 @@ | |||
| 1 | import { For, Match, Show, Switch, createEffect, createSignal, on, onCleanup, untrack } from "solid-js"; | 1 | import { For, Match, Show, Switch, createEffect, createSignal, on, onCleanup, untrack } from "solid-js"; |
| 2 | import { useNavigate } from "@tanstack/solid-router"; | 2 | import { useNavigate } from "@tanstack/solid-router"; |
| 3 | -import { deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread, type ChatbotMessage, type ChatbotThread } from "@/api/chatbot"; | 3 | +import { chatbotStreamUrl, deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread, type ChatbotMessage, type ChatbotThread } from "@/api/chatbot"; |
| 4 | import { formatApiError } from "@/api/client"; | 4 | import { formatApiError } from "@/api/client"; |
| 5 | import { CelebiComposer } from "@/components/layout/celebi-composer"; | 5 | import { CelebiComposer } from "@/components/layout/celebi-composer"; |
| 6 | import { CelebiMarkdown } from "@/components/layout/celebi-markdown"; | 6 | import { CelebiMarkdown } from "@/components/layout/celebi-markdown"; |
| @@ -217,7 +217,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean | |||
| 217 | 217 | ||
| 218 | const streamAnswer = (activeThreadId: string, messageId: string) => { | 218 | const streamAnswer = (activeThreadId: string, messageId: string) => { |
| 219 | stopStream(); | 219 | stopStream(); |
| 220 | - const source = new EventSource(`/api/chatbot/threads/${encodeURIComponent(activeThreadId)}/messages/${encodeURIComponent(messageId)}/stream`, { withCredentials: true }); | 220 | + const source = new EventSource(chatbotStreamUrl(activeThreadId, messageId), { withCredentials: true }); |
| 221 | stream = source; | 221 | stream = source; |
| 222 | source.addEventListener("delta", (event) => { try { const data = JSON.parse((event as MessageEvent).data) as { text?: unknown }; if (typeof data.text === "string") setMessages((items) => items.map((item) => item.id === messageId ? { ...item, content: item.content + data.text } : item)); } catch { /* ignore malformed chunk */ } }); | 222 | source.addEventListener("delta", (event) => { try { const data = JSON.parse((event as MessageEvent).data) as { text?: unknown }; if (typeof data.text === "string") setMessages((items) => items.map((item) => item.id === messageId ? { ...item, content: item.content + data.text } : item)); } catch { /* ignore malformed chunk */ } }); |
| 223 | source.addEventListener("done", (event) => { try { updateAssistant((JSON.parse((event as MessageEvent).data) as { message: ChatbotMessage }).message); } catch { poll(activeThreadId, messageId); } finally { stopStream(); void loadThreads(); } }); | 223 | source.addEventListener("done", (event) => { try { updateAssistant((JSON.parse((event as MessageEvent).data) as { message: ChatbotMessage }).message); } catch { poll(activeThreadId, messageId); } finally { stopStream(); void loadThreads(); } }); |
src/components/users/profile-form.tsxmodified+25 -2
| @@ -1,4 +1,4 @@ | |||
| 1 | -import { Show, createSignal } from "solid-js"; | 1 | +import { For, Show, createSignal } from "solid-js"; |
| 2 | import { patchMe } from "@/api/users"; | 2 | import { patchMe } from "@/api/users"; |
| 3 | import type { ProfileUpdate, User } from "@/api/client"; | 3 | import type { ProfileUpdate, User } from "@/api/client"; |
| 4 | import { formatApiError } from "@/api/client"; | 4 | import { formatApiError } from "@/api/client"; |
| @@ -7,8 +7,10 @@ import { Button } from "@/components/ui/button"; | |||
| 7 | import { DatePicker } from "@/components/ui/date-picker"; | 7 | import { DatePicker } from "@/components/ui/date-picker"; |
| 8 | import { Input } from "@/components/ui/input"; | 8 | import { Input } from "@/components/ui/input"; |
| 9 | import { Label } from "@/components/ui/label"; | 9 | import { Label } from "@/components/ui/label"; |
| 10 | +import { Select } from "@/components/ui/select"; | ||
| 10 | import { Textarea } from "@/components/ui/textarea"; | 11 | import { Textarea } from "@/components/ui/textarea"; |
| 11 | import { createFlash } from "@/lib/flash"; | 12 | import { createFlash } from "@/lib/flash"; |
| 13 | +import { hasMinRole } from "@/lib/roles"; | ||
| 12 | import { useT } from "@/stores/preferences-context"; | 14 | import { useT } from "@/stores/preferences-context"; |
| 13 | 15 | ||
| 14 | const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | 16 | const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; |
| @@ -47,7 +49,9 @@ export function ProfileForm(props: { | |||
| 47 | * them where a profile is in hand; omit them and the fields stay hidden | 49 | * them where a profile is in hand; omit them and the fields stay hidden |
| 48 | * rather than silently offering to clear values they cannot see. | 50 | * rather than silently offering to clear values they cannot see. |
| 49 | */ | 51 | */ |
| 50 | - profile?: { display_name: string | null; bio: string | null }; | 52 | + profile?: { display_name: string | null; bio: string | null; branch?: string | null }; |
| 53 | + /** The school's branş vocabulary (settings.branches); the picker hides when empty. */ | ||
| 54 | + branches?: string[]; | ||
| 51 | maxDisplayNameLen?: number; | 55 | maxDisplayNameLen?: number; |
| 52 | maxBioLen?: number; | 56 | maxBioLen?: number; |
| 53 | onSaved: () => void; | 57 | onSaved: () => void; |
| @@ -61,6 +65,15 @@ export function ProfileForm(props: { | |||
| 61 | const [birthDate, setBirthDate] = createSignal(dateInputFromIso(props.user.birth_date)); | 65 | const [birthDate, setBirthDate] = createSignal(dateInputFromIso(props.user.birth_date)); |
| 62 | const [displayName, setDisplayName] = createSignal(props.profile?.display_name ?? ""); | 66 | const [displayName, setDisplayName] = createSignal(props.profile?.display_name ?? ""); |
| 63 | const [bio, setBio] = createSignal(props.profile?.bio ?? ""); | 67 | const [bio, setBio] = createSignal(props.profile?.bio ?? ""); |
| 68 | + const [branch, setBranch] = createSignal(props.profile?.branch ?? ""); | ||
| 69 | + // Branş is a teacher's field; a stored value outside the list still shows so | ||
| 70 | + // saving the form never silently drops it. | ||
| 71 | + const branchOptions = () => { | ||
| 72 | + const list = props.branches ?? []; | ||
| 73 | + const stored = props.profile?.branch; | ||
| 74 | + return stored && !list.includes(stored) ? [stored, ...list] : list; | ||
| 75 | + }; | ||
| 76 | + const showBranch = () => !!props.profile && hasMinRole(props.user.role, "teacher") && branchOptions().length > 0; | ||
| 64 | const [error, setError] = createSignal(""); | 77 | const [error, setError] = createSignal(""); |
| 65 | const [flash, setFlash] = createFlash(); | 78 | const [flash, setFlash] = createFlash(); |
| 66 | const [pending, setPending] = createSignal(false); | 79 | const [pending, setPending] = createSignal(false); |
| @@ -93,6 +106,7 @@ export function ProfileForm(props: { | |||
| 93 | const bi = bio().trim(); | 106 | const bi = bio().trim(); |
| 94 | if (dn !== (props.profile.display_name ?? "")) b.display_name = dn; | 107 | if (dn !== (props.profile.display_name ?? "")) b.display_name = dn; |
| 95 | if (bi !== (props.profile.bio ?? "")) b.bio = bi; | 108 | if (bi !== (props.profile.bio ?? "")) b.bio = bi; |
| 109 | + if (showBranch() && branch() !== (props.profile.branch ?? "")) b.branch = branch(); | ||
| 96 | } | 110 | } |
| 97 | return b; | 111 | return b; |
| 98 | }; | 112 | }; |
| @@ -160,6 +174,15 @@ export function ProfileForm(props: { | |||
| 160 | </p> | 174 | </p> |
| 161 | </div> | 175 | </div> |
| 162 | </Show> | 176 | </Show> |
| 177 | + <Show when={showBranch()}> | ||
| 178 | + <div class="space-y-1.5"> | ||
| 179 | + <Label for="pf-branch">{t("profile.branch")}</Label> | ||
| 180 | + <Select id="pf-branch" class="h-10" value={branch()} onChange={(e) => setBranch(e.currentTarget.value)}> | ||
| 181 | + <option value="">{t("profile.branchNone")}</option> | ||
| 182 | + <For each={branchOptions()}>{(name) => <option value={name}>{name}</option>}</For> | ||
| 183 | + </Select> | ||
| 184 | + </div> | ||
| 185 | + </Show> | ||
| 163 | <div class="space-y-1.5"> | 186 | <div class="space-y-1.5"> |
| 164 | <Label for="pf-email">{t("profile.email")}</Label> | 187 | <Label for="pf-email">{t("profile.email")}</Label> |
| 165 | <Input id="pf-email" class="h-10" type="email" value={email()} onInput={(e) => setEmail(e.currentTarget.value)} /> | 188 | <Input id="pf-email" class="h-10" type="email" value={email()} onInput={(e) => setEmail(e.currentTarget.value)} /> |
src/i18n/messages.tsmodified+6 -0
| @@ -126,6 +126,8 @@ export type MessageKey = | |||
| 126 | | "profile.displayNameHint" | 126 | | "profile.displayNameHint" |
| 127 | | "profile.bio" | 127 | | "profile.bio" |
| 128 | | "profile.bioHint" | 128 | | "profile.bioHint" |
| 129 | + | "profile.branch" | ||
| 130 | + | "profile.branchNone" | ||
| 129 | | "profile.bioEmpty" | 131 | | "profile.bioEmpty" |
| 130 | | "profile.classes" | 132 | | "profile.classes" |
| 131 | | "profile.noClasses" | 133 | | "profile.noClasses" |
| @@ -2121,6 +2123,8 @@ const en: Dict = { | |||
| 2121 | "profile.displayNameHint": "Shown to other people instead of your username.", | 2123 | "profile.displayNameHint": "Shown to other people instead of your username.", |
| 2122 | "profile.bio": "About", | 2124 | "profile.bio": "About", |
| 2123 | "profile.bioHint": "A short line about yourself.", | 2125 | "profile.bioHint": "A short line about yourself.", |
| 2126 | + "profile.branch": "Teaching subject (branş)", | ||
| 2127 | + "profile.branchNone": "Not set", | ||
| 2124 | "profile.bioEmpty": "No bio yet.", | 2128 | "profile.bioEmpty": "No bio yet.", |
| 2125 | "profile.classes": "Classes", | 2129 | "profile.classes": "Classes", |
| 2126 | "profile.noClasses": "Not in any class.", | 2130 | "profile.noClasses": "Not in any class.", |
| @@ -4124,6 +4128,8 @@ const tr: Dict = { | |||
| 4124 | "profile.displayNameHint": "Diğer kişilere kullanıcı adın yerine bu gösterilir.", | 4128 | "profile.displayNameHint": "Diğer kişilere kullanıcı adın yerine bu gösterilir.", |
| 4125 | "profile.bio": "Hakkında", | 4129 | "profile.bio": "Hakkında", |
| 4126 | "profile.bioHint": "Kendinle ilgili kısa bir not.", | 4130 | "profile.bioHint": "Kendinle ilgili kısa bir not.", |
| 4131 | + "profile.branch": "Branş", | ||
| 4132 | + "profile.branchNone": "Belirtilmedi", | ||
| 4127 | "profile.bioEmpty": "Henüz bir not yok.", | 4133 | "profile.bioEmpty": "Henüz bir not yok.", |
| 4128 | "profile.classes": "Şubeler", | 4134 | "profile.classes": "Şubeler", |
| 4129 | "profile.noClasses": "Hiçbir şubede değil.", | 4135 | "profile.noClasses": "Hiçbir şubede değil.", |
src/pages/profile-page.tsxmodified+7 -1
| @@ -3,6 +3,7 @@ import { createResource } from "@/lib/create-resource"; | |||
| 3 | import { useLocation, useParams } from "@tanstack/solid-router"; | 3 | import { useLocation, useParams } from "@tanstack/solid-router"; |
| 4 | import { getClassesByUserId, getMyClasses } from "@/api/classes"; | 4 | import { getClassesByUserId, getMyClasses } from "@/api/classes"; |
| 5 | import { getLimits } from "@/api/limits"; | 5 | import { getLimits } from "@/api/limits"; |
| 6 | +import { getSettings } from "@/api/settings"; | ||
| 6 | import { getMyProfile, getUserProfile } from "@/api/users"; | 7 | import { getMyProfile, getUserProfile } from "@/api/users"; |
| 7 | import { ApiError, formatApiError, type Profile } from "@/api/client"; | 8 | import { ApiError, formatApiError, type Profile } from "@/api/client"; |
| 8 | import { RouteGuard } from "@/components/layout/route-guard"; | 9 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -50,6 +51,7 @@ function ProfileContent() { | |||
| 50 | id === "me" ? getMyProfile() : getUserProfile(id), | 51 | id === "me" ? getMyProfile() : getUserProfile(id), |
| 51 | ); | 52 | ); |
| 52 | const [limits] = createResource(() => getLimits()); | 53 | const [limits] = createResource(() => getLimits()); |
| 54 | + const [settings] = createResource(() => getSettings().catch(() => null)); | ||
| 53 | const [editing, setEditing] = createSignal(false); | 55 | const [editing, setEditing] = createSignal(false); |
| 54 | 56 | ||
| 55 | // The five counters that fit the profile owner's role: a student's own | 57 | // The five counters that fit the profile owner's role: a student's own |
| @@ -160,6 +162,9 @@ function ProfileContent() { | |||
| 160 | <div class="flex flex-wrap items-center gap-2"> | 162 | <div class="flex flex-wrap items-center gap-2"> |
| 161 | <span class="text-sm text-muted-foreground">@{p().username}</span> | 163 | <span class="text-sm text-muted-foreground">@{p().username}</span> |
| 162 | <RoleBadge role={p().role} /> | 164 | <RoleBadge role={p().role} /> |
| 165 | + <Show when={p().branch}> | ||
| 166 | + {(b) => <Badge variant="secondary" class="rounded-md">{b()}</Badge>} | ||
| 167 | + </Show> | ||
| 163 | </div> | 168 | </div> |
| 164 | <p class="max-w-prose whitespace-pre-wrap text-sm text-muted-foreground"> | 169 | <p class="max-w-prose whitespace-pre-wrap text-sm text-muted-foreground"> |
| 165 | {p().bio || t("profile.bioEmpty")} | 170 | {p().bio || t("profile.bioEmpty")} |
| @@ -220,7 +225,8 @@ function ProfileContent() { | |||
| 220 | {(u) => ( | 225 | {(u) => ( |
| 221 | <ProfileForm | 226 | <ProfileForm |
| 222 | user={u()} | 227 | user={u()} |
| 223 | - profile={{ display_name: p().display_name, bio: p().bio }} | 228 | + profile={{ display_name: p().display_name, bio: p().bio, branch: p().branch }} |
| 229 | + branches={settings.latest?.branches} | ||
| 224 | maxDisplayNameLen={limits.latest?.user.max_display_name_len} | 230 | maxDisplayNameLen={limits.latest?.user.max_display_name_len} |
| 225 | maxBioLen={limits.latest?.user.max_bio_len} | 231 | maxBioLen={limits.latest?.user.max_bio_len} |
| 226 | onSaved={() => { | 232 | onSaved={() => { |