Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(profile): optimistic interests update + clickable auth logo (#14984)

YuTengjing29623c4ab62e
diff --git a/src/app/[variants]/(auth)/_layout/index.tsx b/src/app/[variants]/(auth)/_layout/index.tsx
index 248d5f40a02..29411ec464b 100644
--- a/src/app/[variants]/(auth)/_layout/index.tsx
+++ b/src/app/[variants]/(auth)/_layout/index.tsx
@@ -4,6 +4,7 @@ import { COPYRIGHT_FULL } from '@lobechat/business-const';
import { Center, Flexbox, Text } from '@lobehub/ui';
import { Divider } from 'antd';
import { cx } from 'antd-style';
+import Link from 'next/link';
import { type FC, type PropsWithChildren } from 'react';
import { ProductLogo } from '@/components/Branding';
@@ -30,7 +31,9 @@ const AuthContainer: FC<PropsWithChildren> = ({ children }) => {
padding={16}
width={'100%'}
>
- <ProductLogo size={40} />
+ <Link aria-label={'LobeHub'} href={'/'} style={{ display: 'inline-flex' }}>
+ <ProductLogo size={40} />
+ </Link>
<Flexbox horizontal align={'center'}>
<AuthLangButton size={18} />
<Divider className={styles.divider} orientation={'vertical'} />
diff --git a/src/routes/(main)/settings/profile/features/InterestsRow.tsx b/src/routes/(main)/settings/profile/features/InterestsRow.tsx
index b65094f2032..1c540f37199 100644
--- a/src/routes/(main)/settings/profile/features/InterestsRow.tsx
+++ b/src/routes/(main)/settings/profile/features/InterestsRow.tsx
@@ -22,13 +22,11 @@ const InterestsRow = () => {
const updateInterests = useUserStore((s) => s.updateInterests);
const [customInput, setCustomInput] = useState('');
const [showCustomInput, setShowCustomInput] = useState(false);
- const [saving, setSaving] = useState(false);
const normalizedInterests = useMemo(() => normalizeInterestsForStorage(interests), [interests]);
const saveInterests = useCallback(
async (updated: string[]) => {
try {
- setSaving(true);
await updateInterests(updated);
} catch (error) {
console.error('Failed to update interests:', error);
@@ -36,8 +34,6 @@ const InterestsRow = () => {
errorMessage: error instanceof Error ? error.message : String(error),
status: 500,
});
- } finally {
- setSaving(false);
}
},
[updateInterests],
@@ -101,11 +97,10 @@ const InterestsRow = () => {
? {
background: cssVar.colorFillSecondary,
borderColor: cssVar.colorFillSecondary,
- opacity: saving ? 0.6 : 1,
}
- : { opacity: saving ? 0.6 : 1 }
+ : undefined
}
- onClick={() => !saving && toggleInterest(item.key)}
+ onClick={() => toggleInterest(item.key)}
>
<Icon color={cssVar.colorTextSecondary} icon={item.icon} size={14} />
<Text fontSize={13} weight={500}>
@@ -125,9 +120,8 @@ const InterestsRow = () => {
style={{
background: cssVar.colorFillSecondary,
borderColor: cssVar.colorFillSecondary,
- opacity: saving ? 0.6 : 1,
}}
- onClick={() => !saving && removeCustomInterest(interest)}
+ onClick={() => removeCustomInterest(interest)}
>
<Text fontSize={13} weight={500}>
{interest}
diff --git a/src/store/user/slices/common/action.test.ts b/src/store/user/slices/common/action.test.ts
index 81909b821fa..d02572d07b4 100644
--- a/src/store/user/slices/common/action.test.ts
+++ b/src/store/user/slices/common/action.test.ts
@@ -41,6 +41,36 @@ describe('createCommonSlice', () => {
});
});
+ describe('updateInterests', () => {
+ it('optimistically updates user.interests before the service call resolves', async () => {
+ act(() => {
+ useUserStore.setState({ user: { id: 'u1', interests: ['old'] } as any });
+ });
+
+ let resolveService: () => void = () => {};
+ const updateSpy = vi.spyOn(userService, 'updateInterests').mockImplementation(
+ () =>
+ new Promise<void>((r) => {
+ resolveService = r;
+ }) as any,
+ );
+
+ let pending: Promise<void> | undefined;
+ act(() => {
+ pending = useUserStore.getState().updateInterests(['new']);
+ });
+
+ expect(useUserStore.getState().user?.interests).toEqual(['new']);
+
+ await act(async () => {
+ resolveService();
+ await pending;
+ });
+
+ expect(updateSpy).toHaveBeenCalledWith(['new']);
+ });
+ });
+
describe('useInitUserState', () => {
const mockServerConfig = {
defaultAgent: 'agent1',
diff --git a/src/store/user/slices/common/action.ts b/src/store/user/slices/common/action.ts
index 320dd526e97..936865aa0b5 100644
--- a/src/store/user/slices/common/action.ts
+++ b/src/store/user/slices/common/action.ts
@@ -54,6 +54,10 @@ export class CommonActionImpl {
};
updateInterests = async (interests: string[]): Promise<void> => {
+ const previousUser = this.#get().user;
+ if (previousUser) {
+ this.#set({ user: { ...previousUser, interests } }, false, n('updateInterests/optimistic'));
+ }
await userService.updateInterests(interests);
await this.#get().refreshUserState();
};