fix(user): refresh profile on sidebar open

This commit is contained in:
2026-06-30 11:36:52 +08:00
parent 345c5f7f25
commit 6e811b0e09
4 changed files with 16 additions and 19 deletions
@@ -101,11 +101,10 @@ describe("userMachine", () => {
actor.stop();
});
it("updates user profile fields synchronously", () => {
it("updates user profile synchronously", () => {
const actor = createActor(createTestUserMachine()).start();
actor.send({ type: "UserUpdate", user: makeUser({ username: "Before" }) });
actor.send({ type: "UserUpdateUsername", username: "After" });
actor.send({ type: "UserUpdate", user: makeUser({ username: "After" }) });
expect(actor.getSnapshot().context.currentUser?.username).toBe("After");
+1 -4
View File
@@ -7,8 +7,5 @@ export type UserEvent =
| { type: "UserInit" }
| { type: "UserFetch" }
| { type: "UserUpdate"; user: UserView }
| { type: "UserUpdateUsername"; username: string }
| { type: "UserClearLocal" }
| { type: "UserLogout" }
| { type: "UserDeleteChatHistory" }
| { type: "UserDeleteAccount" };
| { type: "UserLogout" };
-12
View File
@@ -40,13 +40,6 @@ export const userMachine = setup({
};
}),
updateUsername: assign(({ context, event }) => {
if (event.type !== "UserUpdateUsername" || !context.currentUser) return {};
return {
currentUser: { ...context.currentUser, username: event.username },
};
}),
clearUser: assign(() => ({
currentUser: null,
avatarUrl: null,
@@ -66,15 +59,10 @@ export const userMachine = setup({
UserUpdate: {
actions: "updateUser",
},
UserUpdateUsername: {
actions: "updateUsername",
},
UserClearLocal: {
actions: "clearUser",
},
UserLogout: "loggingOut",
UserDeleteChatHistory: {},
UserDeleteAccount: {},
},
},