Revert "fix(user): refresh profile on sidebar open"
This reverts commit 6e811b0e09.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { LogOut } from "lucide-react";
|
||||
import { signOut } from "next-auth/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
@@ -30,18 +29,6 @@ export function SidebarScreen() {
|
||||
const auth = useAuthState();
|
||||
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 = () => {
|
||||
userDispatch({ type: "UserClearLocal" });
|
||||
authDispatch({ type: "AuthLogoutSubmitted" });
|
||||
|
||||
@@ -101,10 +101,11 @@ describe("userMachine", () => {
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
it("updates user profile synchronously", () => {
|
||||
it("updates user profile fields synchronously", () => {
|
||||
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");
|
||||
|
||||
|
||||
@@ -7,5 +7,8 @@ export type UserEvent =
|
||||
| { type: "UserInit" }
|
||||
| { type: "UserFetch" }
|
||||
| { type: "UserUpdate"; user: UserView }
|
||||
| { type: "UserUpdateUsername"; username: string }
|
||||
| { type: "UserClearLocal" }
|
||||
| { type: "UserLogout" };
|
||||
| { type: "UserLogout" }
|
||||
| { type: "UserDeleteChatHistory" }
|
||||
| { type: "UserDeleteAccount" };
|
||||
|
||||
@@ -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(() => ({
|
||||
currentUser: null,
|
||||
avatarUrl: null,
|
||||
@@ -59,10 +66,15 @@ export const userMachine = setup({
|
||||
UserUpdate: {
|
||||
actions: "updateUser",
|
||||
},
|
||||
UserUpdateUsername: {
|
||||
actions: "updateUsername",
|
||||
},
|
||||
UserClearLocal: {
|
||||
actions: "clearUser",
|
||||
},
|
||||
UserLogout: "loggingOut",
|
||||
UserDeleteChatHistory: {},
|
||||
UserDeleteAccount: {},
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user