🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style(project): restore the card layout of project General settings (#22441)
Arvin Xu3d86051d3d1f
diff --git a/locales/en-US/project.json b/locales/en-US/project.jsonindex 31a6afdc99d..73a31202e61 100644--- a/locales/en-US/project.json+++ b/locales/en-US/project.json@@ -325,23 +325,24 @@"settings.identifier": "Project identifier","settings.identifierDescription": "Prefix for this project’s task numbers, set when the project is created. Projects without one use the default prefix.","settings.knowledgeBases": "Libraries",- "settings.logoAndName": "Logo and name",- "settings.logoHint": "Click the logo to upload an image or pick an emoji.",+ "settings.logo": "Logo",+ "settings.logoDescription": "Shown in the project header, sidebar and switcher.",+ "settings.logoHint": "Click the logo to upload an image or pick an emoji. Changes are saved right away.","settings.logoSizeExceeded": "The logo must be smaller than 2 MB.",+ "settings.logoUpdated": "Logo updated","settings.logoUploadFailed": "Could not upload the logo","settings.members": "Members",+ "settings.nameHint": "Use 255 characters at most.","settings.noDirectories": "No folders in this environment yet. Add an existing folder on a connected device to start working.","settings.noEnvironments": "No environments associated yet","settings.noRepository": "No GitHub repository linked","settings.reuseEnvironment": "Add an existing environment to this project","settings.reuseEnvironmentDescription": "Already created an environment? Select it to link its repository configuration to this project, then add a working directory for this project.",- "settings.revert": "Revert","settings.saveFailed": "Could not save the change","settings.saved": "Saved","settings.slugDescription": "Used in the project URL. Changing it updates the address; leave blank to use the project ID.","settings.startDirectoryConversation": "New topic here","settings.title": "Project settings",- "settings.unsavedChanges": "Unsaved changes: {{count}}","settings.viewDirectories": "View folders ({{count}})","settings.workLocations": "Working directories","sidebar.agentsEmpty": "No agents are connected yet",diff --git a/locales/zh-CN/project.json b/locales/zh-CN/project.jsonindex 23005e7cc3c..c162cfc9466 100644--- a/locales/zh-CN/project.json+++ b/locales/zh-CN/project.json@@ -325,23 +325,24 @@"settings.identifier": "项目标识","settings.identifierDescription": "本项目任务编号的前缀,创建项目后不可更改;未设置时使用默认前缀。","settings.knowledgeBases": "资料库",- "settings.logoAndName": "头像和名称",- "settings.logoHint": "点击 Logo 上传图片或选择 Emoji。",+ "settings.logo": "项目 Logo",+ "settings.logoDescription": "显示在项目头部、侧边栏与项目切换器中。",+ "settings.logoHint": "点击 Logo 上传图片或选择 Emoji,修改后立即保存。","settings.logoSizeExceeded": "Logo 需小于 2 MB。",+ "settings.logoUpdated": "Logo 已更新","settings.logoUploadFailed": "Logo 上传失败","settings.members": "成员",+ "settings.nameHint": "最多 255 个字符。","settings.noDirectories": "还没有工作目录。添加已连接设备上的文件夹后,即可在此新建对话。","settings.noEnvironments": "尚未关联环境","settings.noRepository": "未关联 GitHub 仓库","settings.reuseEnvironment": "将已有环境添加到本项目","settings.reuseEnvironmentDescription": "如果之前已创建过环境,可从列表选择,将它的仓库配置关联到本项目,再为本项目添加工作目录。",- "settings.revert": "撤销","settings.saveFailed": "保存失败","settings.saved": "已保存","settings.slugDescription": "用于项目链接。修改后地址会更新,留空则使用项目 ID。","settings.startDirectoryConversation": "在此新建话题","settings.title": "项目设置",- "settings.unsavedChanges": "有 {{count}} 处修改还没保存","settings.viewDirectories": "查看目录({{count}})","settings.workLocations": "工作目录","sidebar.agentsEmpty": "还没有关联智能体",diff --git a/packages/locales/src/default/project.ts b/packages/locales/src/default/project.tsindex 90bcd49a92a..d2168069871 100644--- a/packages/locales/src/default/project.ts+++ b/packages/locales/src/default/project.ts@@ -72,7 +72,12 @@ export default {'settings.creator': 'Creator','settings.creatorUnknown': 'Former member','settings.general': 'General',- 'settings.logoHint': 'Click the logo to upload an image or pick an emoji.',+ 'settings.logo': 'Logo',+ 'settings.logoDescription': 'Shown in the project header, sidebar and switcher.',+ 'settings.logoHint':+ 'Click the logo to upload an image or pick an emoji. Changes are saved right away.',+ 'settings.logoUpdated': 'Logo updated',+ 'settings.nameHint': 'Use 255 characters at most.','settings.saveFailed': 'Could not save the change','settings.saved': 'Saved','settings.logoSizeExceeded': 'The logo must be smaller than 2 MB.',@@ -406,9 +411,6 @@ export default {'review.sites.detectWaitingDescription':"Put the line above in your site's <head> and deploy, then open any page of the site. This notice disappears once the script is detected.",'review.sites.detectWaitingTitle': 'Waiting for the script to load for the first time',- 'settings.logoAndName': 'Logo and name',- 'settings.revert': 'Revert',- 'settings.unsavedChanges': 'Unsaved changes: {{count}}','create.moreSettings': 'More settings (identifier, slug)','create.afterCreateHint':"After it's created, the project home helps you connect code folders, sites and libraries.",diff --git a/src/features/Projects/WorkingDirectories/GeneralSettings.tsx b/src/features/Projects/WorkingDirectories/GeneralSettings.tsxindex fff709f2277..f2402b6385b 100644--- a/src/features/Projects/WorkingDirectories/GeneralSettings.tsx+++ b/src/features/Projects/WorkingDirectories/GeneralSettings.tsx@@ -1,157 +1,186 @@-import { Flexbox, Input, Text, TextArea } from '@lobehub/ui';-import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';-import * as stylex from '@stylexjs/stylex';-import type { ReactNode } from 'react';+import { Button, Flexbox, Input, TextArea } from '@lobehub/ui';+import { useState } from 'react';import { useTranslation } from 'react-i18next';import EmojiPicker from '@/components/EmojiPicker';+import SettingCard from '@/components/SettingCard';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';import type { ProjectDetail } from '@/store/project';import { isProjectSlugValid } from '../createProjectForm';-import SettingsSaveBar from './SettingsSaveBar';-import { useGeneralSettingsForm } from './useProjectGeneralSettings';+import { useProjectLogo, useSaveProjectField } from './useProjectGeneralSettings';const NAME_MAX = 255;const SLUG_MAX = 100;-const styles = stylex.create({- form: {- borderColor: cssVar.colorBorderSecondary,- borderRadius: cssVar.borderRadiusLG,- borderStyle: 'solid',- borderWidth: 1,- display: 'flex',- flexDirection: 'column',- },- label: {- display: 'flex',- flexDirection: 'column',- gap: 4,- },- row: {- borderBlockStartColor: {- 'default': cssVar.colorBorderSecondary,- ':first-child': 'transparent',- },- borderBlockStartStyle: 'solid',- borderBlockStartWidth: 1,- display: 'grid',- gap: 16,- gridTemplateColumns: { 'default': '180px minmax(0, 1fr)', '@media (max-width: 640px)': '1fr' },- paddingBlock: 16,- paddingInline: 20,- },-});--interface RowProps {- children: ReactNode;- error?: string;- hint?: string;- label: string;+type Project = ProjectDetail['project'];++interface CardProps {+ project: Project;}-const Row = ({ children, error, hint, label }: RowProps) => (- <div {...stylex.props(styles.row)}>- <div {...stylex.props(styles.label)}>- <Text fontSize={13} weight={500}>- {label}- </Text>- {hint ? (- <Text fontSize={12} type="secondary">- {hint}- </Text>- ) : null}- </div>- <Flexbox gap={6}>- {children}- {error ? (- <Text fontSize={12} type="danger">- {error}- </Text>- ) : null}- </Flexbox>- </div>-);+const SaveButton = ({+ disabled,+ loading,+ onClick,+}: {+ disabled: boolean;+ loading: boolean;+ onClick: () => void;+}) => {+ const { t } = useTranslation('common');-interface GeneralSettingsProps {- project: ProjectDetail['project'];-}+ return (+ <Button disabled={disabled || loading} loading={loading} type="primary" onClick={onClick}>+ {t('save')}+ </Button>+ );+};-export function GeneralSettings({ project }: GeneralSettingsProps) {+const LogoCard = ({ project }: CardProps) => {+ const { t } = useTranslation('project');+ const { avatar, busy, onChange, onDelete, onUpload } = useProjectLogo(project);++ return (+ <SettingCard+ description={t('settings.logoDescription')}+ hint={t('settings.logoHint')}+ title={t('settings.logo')}+ extra={+ <EmojiPicker+ allowDelete={!!avatar}+ allowUpload={{ enableEmoji: true }}+ loading={busy}+ shape="square"+ size={80}+ // Seeds the generated avatar shown while the project has no logo.+ title={project.name}+ value={avatar || undefined}+ onChange={onChange}+ onDelete={onDelete}+ onUpload={onUpload}+ />+ }+ />+ );+};++const NameCard = ({ project }: CardProps) => {+ const { t } = useTranslation('project');+ const { save, saving } = useSaveProjectField(project.id);+ const [name, setName] = useState(project.name);+ const trimmed = name.trim();++ return (+ <SettingCard+ hint={t('settings.nameHint')}+ title={t('create.nameLabel')}+ action={+ <SaveButton+ disabled={!trimmed || trimmed === project.name}+ loading={saving}+ onClick={() => save({ name: trimmed })}+ />+ }+ >+ <Input+ aria-label={t('create.nameLabel')}+ maxLength={NAME_MAX}+ style={{ maxWidth: 420 }}+ value={name}+ onChange={(e) => setName(e.target.value)}+ />+ </SettingCard>+ );+};++const IdentifierCard = ({ project }: CardProps) => {+ const { t } = useTranslation('project');++ return (+ <SettingCard description={t('settings.identifierDescription')} title={t('settings.identifier')}>+ <Input+ readOnly+ aria-label={t('settings.identifier')}+ style={{ maxWidth: 420 }}+ value={project.identifier ?? ''}+ />+ </SettingCard>+ );+};++const SlugCard = ({ project }: CardProps) => {const { t } = useTranslation('project');const navigate = useWorkspaceAwareNavigate();- const { count, draft, logo, revert, save, saving, setField, valid } =- useGeneralSettingsForm(project);- const slugValid = isProjectSlugValid(draft.slug);+ const { save, saving } = useSaveProjectField(project.id);+ const [slug, setSlug] = useState(project.slug ?? '');+ const valid = isProjectSlugValid(slug);- const handleSave = async () => {- const previousSlug = project.slug ?? null;- const saved = await save();+ const saveSlug = async () => {+ const saved = await save({ slug: slug.trim() || null });// The settings URL carries the slug, so follow it to the new address.- if (saved && (saved.slug ?? null) !== previousSlug)- navigate(`/project/${saved.slug ?? saved.id}/settings/general`, { replace: true });+ if (saved) navigate(`/project/${saved.slug ?? saved.id}/settings/general`, { replace: true });};return (- <Flexbox gap={16}>- <div {...stylex.props(styles.form)}>- <Row hint={t('settings.logoHint')} label={t('settings.logoAndName')}>- <Flexbox horizontal align="center" gap={12}>- <EmojiPicker- allowDelete={!!draft.avatar}- allowUpload={{ enableEmoji: true }}- loading={logo.busy}- shape="square"- size={40}- // Seeds the generated avatar shown while the project has no logo.- title={draft.name || project.name}- value={draft.avatar || undefined}- onChange={logo.onChange}- onDelete={logo.onDelete}- onUpload={logo.onUpload}- />- <Input- aria-label={t('create.nameLabel')}- maxLength={NAME_MAX}- style={{ flex: 1 }}- value={draft.name}- onChange={(e) => setField('name', e.target.value)}- />- </Flexbox>- </Row>- <Row- error={slugValid ? undefined : t('create.slugInvalid')}- hint={t('settings.slugDescription')}- label={t('create.slugLabel')}- >- <Input- aria-invalid={!slugValid || undefined}- aria-label={t('create.slugLabel')}- maxLength={SLUG_MAX}- value={draft.slug}- onChange={(e) => setField('slug', e.target.value.toLowerCase())}- />- </Row>- <Row hint={t('settings.identifierDescription')} label={t('settings.identifier')}>- <Input readOnly aria-label={t('settings.identifier')} value={project.identifier ?? ''} />- </Row>- <Row label={t('settings.description')}>- <TextArea- aria-label={t('settings.description')}- autoSize={{ maxRows: 8, minRows: 3 }}- value={draft.description}- onChange={(e) => setField('description', e.target.value)}- />- </Row>- </div>- <SettingsSaveBar- count={count}- disabled={!valid}- saving={saving}- onRevert={revert}- onSave={handleSave}+ <SettingCard+ description={t('settings.slugDescription')}+ hint={valid ? undefined : t('create.slugInvalid')}+ title={t('create.slugLabel')}+ action={+ <SaveButton+ disabled={!valid || slug.trim() === (project.slug ?? '')}+ loading={saving}+ onClick={saveSlug}+ />+ }+ >+ <Input+ aria-invalid={!valid || undefined}+ aria-label={t('create.slugLabel')}+ maxLength={SLUG_MAX}+ style={{ maxWidth: 420 }}+ value={slug}+ onChange={(e) => setSlug(e.target.value.toLowerCase())}+ />+ </SettingCard>+ );+};++const DescriptionCard = ({ project }: CardProps) => {+ const { t } = useTranslation('project');+ const { save, saving } = useSaveProjectField(project.id);+ const [description, setDescription] = useState(project.description ?? '');++ return (+ <SettingCard+ title={t('settings.description')}+ action={+ <SaveButton+ disabled={description.trim() === (project.description ?? '')}+ loading={saving}+ onClick={() => save({ description: description.trim() || null })}+ />+ }+ >+ <TextArea+ aria-label={t('settings.description')}+ autoSize={{ maxRows: 8, minRows: 3 }}+ value={description}+ onChange={(e) => setDescription(e.target.value)}/>+ </SettingCard>+ );+};++export function GeneralSettings({ project }: CardProps) {+ return (+ <Flexbox gap={16}>+ <LogoCard project={project} />+ <NameCard project={project} />+ <IdentifierCard project={project} />+ <SlugCard project={project} />+ <DescriptionCard project={project} /></Flexbox>);}diff --git a/src/features/Projects/WorkingDirectories/SettingsSaveBar.tsx b/src/features/Projects/WorkingDirectories/SettingsSaveBar.tsxdeleted file mode 100644index d5e238f3719..00000000000--- a/src/features/Projects/WorkingDirectories/SettingsSaveBar.tsx+++ /dev/null@@ -1,91 +0,0 @@-import { Button, Text } from '@lobehub/ui';-import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';-import * as stylex from '@stylexjs/stylex';-import { AnimatePresence } from 'motion/react';-import * as m from 'motion/react-m';-import { useTranslation } from 'react-i18next';--const styles = stylex.create({- bar: {- alignItems: 'center',- backdropFilter: 'blur(16px) saturate(1.2)',- backgroundColor: `color-mix(in srgb, ${cssVar.colorBgElevated} 88%, transparent)`,- borderColor: cssVar.colorBorderSecondary,- borderRadius: cssVar.borderRadiusLG,- borderStyle: 'solid',- borderWidth: 1,- boxShadow: cssVar.boxShadowSecondary,- display: 'flex',- gap: 8,- insetBlockEnd: 24,- justifyContent: 'space-between',- paddingBlock: 8,- paddingInlineStart: '16px',- paddingInlineEnd: '8px',- position: 'sticky',- zIndex: 10,- },- dot: {- backgroundColor: cssVar.colorWarning,- borderRadius: '50%',- flexShrink: 0,- height: 6,- width: 6,- },- message: {- alignItems: 'center',- display: 'flex',- gap: 8,- },-});--interface SettingsSaveBarProps {- count: number;- disabled: boolean;- onRevert: () => void;- onSave: () => void;- saving: boolean;-}--const SettingsSaveBar = ({ count, disabled, onRevert, onSave, saving }: SettingsSaveBarProps) => {- const { t } = useTranslation(['project', 'common']);-- return (- <AnimatePresence>- {count > 0 && (- <m.div- animate={{ opacity: 1, y: 0 }}- aria-live="polite"- exit={{ opacity: 0, y: 12 }}- initial={{ opacity: 0, y: 12 }}- role="status"- transition={{ duration: 0.18, ease: 'easeOut' }}- {...stylex.props(styles.bar)}- >- <span {...stylex.props(styles.message)}>- <span {...stylex.props(styles.dot)} />- <Text fontSize={13} type="secondary">- {t('settings.unsavedChanges', { count })}- </Text>- </span>- <span {...stylex.props(styles.message)}>- <Button disabled={saving} size="small" type="text" onClick={onRevert}>- {t('settings.revert')}- </Button>- <Button- disabled={disabled}- loading={saving}- size="small"- type="primary"- onClick={onSave}- >- {t('save', { ns: 'common' })}- </Button>- </span>- </m.div>- )}- </AnimatePresence>- );-};--export default SettingsSaveBar;diff --git a/src/features/Projects/WorkingDirectories/generalSettingsForm.test.ts b/src/features/Projects/WorkingDirectories/generalSettingsForm.test.tsdeleted file mode 100644index 306f1223b6c..00000000000--- a/src/features/Projects/WorkingDirectories/generalSettingsForm.test.ts+++ /dev/null@@ -1,67 +0,0 @@-import { describe, expect, it } from 'vitest';--import { diffGeneralSettings, toGeneralSettingsDraft } from './generalSettingsForm';--const project = {- avatar: '🧭',- description: null,- name: 'Website revamp',- slug: 'website-revamp',-};--describe('toGeneralSettingsDraft', () => {- it('fills empty strings for missing text fields and carries no type', () => {- expect(toGeneralSettingsDraft({ ...project, slug: null, type: 'web' } as never)).toEqual({- avatar: '🧭',- description: '',- name: 'Website revamp',- slug: '',- });- });-});--describe('diffGeneralSettings', () => {- const draft = toGeneralSettingsDraft(project);-- it('has nothing to save when the draft matches the project', () => {- expect(diffGeneralSettings(project, draft)).toEqual({ count: 0, patch: {}, valid: true });- });-- it('collects every changed field into one patch, trimmed', () => {- expect(- diffGeneralSettings(project, {- avatar: null,- description: ' Relaunch the marketing site ',- name: ' Website 2026 ',- slug: 'site-2026',- }),- ).toEqual({- count: 4,- patch: {- avatar: null,- description: 'Relaunch the marketing site',- name: 'Website 2026',- slug: 'site-2026',- },- valid: true,- });- });-- it('clears the slug and description to null', () => {- expect(- diffGeneralSettings(- { ...project, description: 'Old' },- { ...draft, description: ' ', slug: '' },- ).patch,- ).toEqual({ description: null, slug: null });- });-- it('ignores whitespace-only edits', () => {- expect(diffGeneralSettings(project, { ...draft, name: ' Website revamp ' }).count).toBe(0);- });-- it('is invalid with an empty name or a malformed slug', () => {- expect(diffGeneralSettings(project, { ...draft, name: ' ' }).valid).toBe(false);- expect(diffGeneralSettings(project, { ...draft, slug: '-bad-' }).valid).toBe(false);- });-});diff --git a/src/features/Projects/WorkingDirectories/generalSettingsForm.ts b/src/features/Projects/WorkingDirectories/generalSettingsForm.tsdeleted file mode 100644index c42afe744d0..00000000000--- a/src/features/Projects/WorkingDirectories/generalSettingsForm.ts+++ /dev/null@@ -1,50 +0,0 @@-import { isProjectSlugValid } from '../createProjectForm';--export interface GeneralSettingsSource {- avatar?: string | null;- description?: string | null;- name: string;- slug?: string | null;-}--export interface GeneralSettingsDraft {- avatar: string | null;- description: string;- name: string;- slug: string;-}--export interface GeneralSettingsPatch {- avatar?: string | null;- description?: string | null;- name?: string;- slug?: string | null;-}--export const toGeneralSettingsDraft = (project: GeneralSettingsSource): GeneralSettingsDraft => ({- avatar: project.avatar ?? null,- description: project.description ?? '',- name: project.name,- slug: project.slug ?? '',-});--export const diffGeneralSettings = (- project: GeneralSettingsSource,- draft: GeneralSettingsDraft,-) => {- const patch: GeneralSettingsPatch = {};- const name = draft.name.trim();- const slug = draft.slug.trim() || null;- const description = draft.description.trim() || null;-- if (name && name !== project.name) patch.name = name;- if (slug !== (project.slug || null)) patch.slug = slug;- if (description !== (project.description || null)) patch.description = description;- if (draft.avatar !== (project.avatar ?? null)) patch.avatar = draft.avatar;-- return {- count: Object.keys(patch).length,- patch,- valid: Boolean(name) && isProjectSlugValid(draft.slug),- };-};diff --git a/src/features/Projects/WorkingDirectories/useProjectGeneralSettings.test.ts b/src/features/Projects/WorkingDirectories/useProjectGeneralSettings.test.tsindex ad6db81fd41..d7eb6a43ffc 100644--- a/src/features/Projects/WorkingDirectories/useProjectGeneralSettings.test.ts+++ b/src/features/Projects/WorkingDirectories/useProjectGeneralSettings.test.ts@@ -3,17 +3,16 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import type { ProjectDetail } from '@/store/project';-import { useGeneralSettingsForm, useSaveProjectField } from './useProjectGeneralSettings';+import { useProjectLogo, useSaveProjectField } from './useProjectGeneralSettings';const mocks = vi.hoisted(() => ({- confirmModal: vi.fn(),toast: { error: vi.fn(), success: vi.fn() },updateProject: vi.fn(),uploadWithProgress: vi.fn(),}));vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));-vi.mock('@lobehub/ui', () => ({ confirmModal: mocks.confirmModal, toast: mocks.toast }));+vi.mock('@lobehub/ui', () => ({ toast: mocks.toast }));vi.mock('@/store/file', () => ({useFileStore: (selector: (s: unknown) => unknown) =>selector({ uploadWithProgress: mocks.uploadWithProgress }),@@ -64,69 +63,57 @@ describe('useSaveProjectField', () => {});});-describe('useGeneralSettingsForm', () => {- const current = project as unknown as ProjectDetail['project'];-+describe('useProjectLogo', () => {beforeEach(() => {vi.clearAllMocks();- mocks.updateProject.mockResolvedValue({ id: 'prj_1', slug: 'alpha' });+ mocks.updateProject.mockResolvedValue(project);});- it('keeps a picked logo in the draft until saved', async () => {- const { result } = renderHook(() => useGeneralSettingsForm(current));+ it('saves a picked logo straight away', async () => {+ const { result } = renderHook(() => useProjectLogo(project));await act(async () => {- result.current.logo.onChange('🚀');+ result.current.onChange('🚀');});- expect(result.current.draft.avatar).toBe('🚀');- expect(result.current.count).toBe(1);- expect(mocks.updateProject).not.toHaveBeenCalled();+ expect(mocks.updateProject).toHaveBeenCalledWith('prj_1', { avatar: '🚀' });+ expect(mocks.toast.success).toHaveBeenCalledWith('settings.logoUpdated');});- it('puts an uploaded file in the draft by its stored URL, not the data URL preview', async () => {- mocks.uploadWithProgress.mockResolvedValue({ url: 'https://cdn/logo.png' });- const { result } = renderHook(() => useGeneralSettingsForm(current));- const file = new File(['x'], 'logo.png', { type: 'image/png' });+ it('saves a deleted logo as null, once', async () => {+ const { result } = renderHook(() => useProjectLogo({ ...project, avatar: '🚀' }));await act(async () => {- result.current.logo.onChange('data:image/png;base64,eA==');- await result.current.logo.onUpload(file);+ // The picker reports the cleared value before calling onDelete.+ result.current.onChange(null);+ await result.current.onDelete();});- expect(result.current.draft.avatar).toBe('https://cdn/logo.png');- expect(mocks.updateProject).not.toHaveBeenCalled();+ expect(mocks.updateProject).toHaveBeenCalledTimes(1);+ expect(mocks.updateProject).toHaveBeenCalledWith('prj_1', { avatar: null });});- it('saves every change in one update without asking and resolves to the saved project', async () => {- const { result } = renderHook(() => useGeneralSettingsForm(current));+ it('saves an uploaded file by its stored URL, not the data URL preview', async () => {+ mocks.uploadWithProgress.mockResolvedValue({ url: 'https://cdn/logo.png' });+ const { result } = renderHook(() => useProjectLogo(project));+ const file = new File(['x'], 'logo.png', { type: 'image/png' });- act(() => {- result.current.setField('name', 'Beta');- result.current.setField('description', 'Relaunch');- });- let saved: unknown;await act(async () => {- saved = await result.current.save();+ result.current.onChange('data:image/png;base64,eA==');+ await result.current.onUpload(file);});- expect(mocks.confirmModal).not.toHaveBeenCalled();expect(mocks.updateProject).toHaveBeenCalledTimes(1);- expect(mocks.updateProject).toHaveBeenCalledWith('prj_1', {- description: 'Relaunch',- name: 'Beta',- });- expect(saved).toEqual({ id: 'prj_1', slug: 'alpha' });+ expect(mocks.updateProject).toHaveBeenCalledWith('prj_1', { avatar: 'https://cdn/logo.png' });});- it('reverts the draft to the saved project', () => {- const { result } = renderHook(() => useGeneralSettingsForm(current));+ it('does not save a logo that did not change', async () => {+ const { result } = renderHook(() => useProjectLogo({ ...project, avatar: '🚀' }));- act(() => result.current.setField('name', 'Beta'));- expect(result.current.count).toBe(1);- act(() => result.current.revert());+ await act(async () => {+ result.current.onChange('🚀');+ });- expect(result.current.count).toBe(0);- expect(result.current.draft.name).toBe('Alpha');+ expect(mocks.updateProject).not.toHaveBeenCalled();});});diff --git a/src/features/Projects/WorkingDirectories/useProjectGeneralSettings.ts b/src/features/Projects/WorkingDirectories/useProjectGeneralSettings.tsindex 9b9fbdabd0e..e497659c2c7 100644--- a/src/features/Projects/WorkingDirectories/useProjectGeneralSettings.ts+++ b/src/features/Projects/WorkingDirectories/useProjectGeneralSettings.ts@@ -7,12 +7,6 @@ import { useFileStore } from '@/store/file';import type { ProjectDetail } from '@/store/project';import { useProjectStore } from '@/store/project';-import {- diffGeneralSettings,- type GeneralSettingsDraft,- toGeneralSettingsDraft,-} from './generalSettingsForm';-const MAX_LOGO_SIZE = 2 * 1024 * 1024;type ProjectPatch = Parameters<typeof projectService.update>[1];@@ -44,22 +38,17 @@ export const useSaveProjectField = (projectId: string) => {return { save, saving };};-export const useGeneralSettingsForm = (project: ProjectDetail['project']) => {+/** The logo saves as soon as it changes: there is no draft to confirm. */+export const useProjectLogo = (project: ProjectDetail['project']) => {const { t } = useTranslation('project');const uploadWithProgress = useFileStore((s) => s.uploadWithProgress);- const { save: saveField, saving } = useSaveProjectField(project.id);- const [draft, setDraft] = useState(() => toGeneralSettingsDraft(project));+ const { save, saving } = useSaveProjectField(project.id);const [uploading, setUploading] = useState(false);- const { count, patch, valid } = diffGeneralSettings(project, draft);-- const setField = <K extends keyof GeneralSettingsDraft>(key: K, value: GeneralSettingsDraft[K]) =>- setDraft((current) => ({ ...current, [key]: value }));-- const revert = () => setDraft(toGeneralSettingsDraft(project));+ const avatar = project.avatar || null;- const save = async () => {- if (count === 0 || !valid) return;- return saveField(patch);+ const saveLogo = async (next: string | null) => {+ if (next === avatar) return;+ await save({ avatar: next }, t('settings.logoUpdated'));};const onUpload = async (file: File) => {@@ -75,7 +64,7 @@ export const useGeneralSettingsForm = (project: ProjectDetail['project']) => {toast.error(t('settings.logoUploadFailed'));return;}- setField('avatar', result.url);+ await saveLogo(result.url);} catch (error) {console.error('Failed to upload project logo', error);toast.error(t('settings.logoUploadFailed'));@@ -84,20 +73,14 @@ export const useGeneralSettingsForm = (project: ProjectDetail['project']) => {}};- // Uploads arrive as data URLs before `onUpload` has stored the file.+ // Deleting goes through `onDelete`; uploads arrive as data URLs before+ // `onUpload` has stored the file.const onChange = (next: string | null | undefined) => {if (!next || next.startsWith('data:')) return;- setField('avatar', next);+ void saveLogo(next);};- return {- count,- draft,- logo: { busy: uploading, onChange, onDelete: () => setField('avatar', null), onUpload },- revert,- save,- saving,- setField,- valid,- };+ const onDelete = () => saveLogo(null);++ return { avatar, busy: uploading || saving, onChange, onDelete, onUpload };};