Revert "fix(user): refresh profile on sidebar open"

This reverts commit 6e811b0e09.
This commit is contained in:
2026-06-30 13:07:50 +08:00
parent a99a6e056d
commit f4d0f76466
4 changed files with 19 additions and 16 deletions
-13
View File
@@ -1,6 +1,5 @@
"use client"; "use client";
import { useEffect } from "react";
import { LogOut } from "lucide-react"; import { LogOut } from "lucide-react";
import { signOut } from "next-auth/react"; import { signOut } from "next-auth/react";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
@@ -30,18 +29,6 @@ export function SidebarScreen() {
const auth = useAuthState(); const auth = useAuthState();
const authDispatch = useAuthDispatch(); const authDispatch = useAuthDispatch();
useEffect(() => {
if (!auth.hasInitialized || auth.isLoading) return;
if (auth.loginStatus === "notLoggedIn") return;
userDispatch({ type: "UserFetch" });
}, [
auth.hasInitialized,
auth.isLoading,
auth.loginStatus,
userDispatch,
]);
const handleLogoutClick = () => { const handleLogoutClick = () => {
userDispatch({ type: "UserClearLocal" }); userDispatch({ type: "UserClearLocal" });
authDispatch({ type: "AuthLogoutSubmitted" }); authDispatch({ type: "AuthLogoutSubmitted" });
@@ -101,10 +101,11 @@ describe("userMachine", () => {
actor.stop(); actor.stop();
}); });
it("updates user profile synchronously", () => { it("updates user profile fields synchronously", () => {
const actor = createActor(createTestUserMachine()).start(); const actor = createActor(createTestUserMachine()).start();
actor.send({ type: "UserUpdate", user: makeUser({ username: "After" }) }); actor.send({ type: "UserUpdate", user: makeUser({ username: "Before" }) });
actor.send({ type: "UserUpdateUsername", username: "After" });
expect(actor.getSnapshot().context.currentUser?.username).toBe("After"); expect(actor.getSnapshot().context.currentUser?.username).toBe("After");
+4 -1
View File
@@ -7,5 +7,8 @@ export type UserEvent =
| { type: "UserInit" } | { type: "UserInit" }
| { type: "UserFetch" } | { type: "UserFetch" }
| { type: "UserUpdate"; user: UserView } | { type: "UserUpdate"; user: UserView }
| { type: "UserUpdateUsername"; username: string }
| { type: "UserClearLocal" } | { type: "UserClearLocal" }
| { type: "UserLogout" }; | { type: "UserLogout" }
| { type: "UserDeleteChatHistory" }
| { type: "UserDeleteAccount" };
+12
View File
@@ -40,6 +40,13 @@ export const userMachine = setup({
}; };
}), }),
updateUsername: assign(({ context, event }) => {
if (event.type !== "UserUpdateUsername" || !context.currentUser) return {};
return {
currentUser: { ...context.currentUser, username: event.username },
};
}),
clearUser: assign(() => ({ clearUser: assign(() => ({
currentUser: null, currentUser: null,
avatarUrl: null, avatarUrl: null,
@@ -59,10 +66,15 @@ export const userMachine = setup({
UserUpdate: { UserUpdate: {
actions: "updateUser", actions: "updateUser",
}, },
UserUpdateUsername: {
actions: "updateUsername",
},
UserClearLocal: { UserClearLocal: {
actions: "clearUser", actions: "clearUser",
}, },
UserLogout: "loggingOut", UserLogout: "loggingOut",
UserDeleteChatHistory: {},
UserDeleteAccount: {},
}, },
}, },