Skip to content

Commit 42f006e

Browse files
committed
fix(org): keep a Home chat when switching to Search
1 parent 6f6b2f9 commit 42f006e

4 files changed

Lines changed: 39 additions & 10 deletions

File tree

‎apps/sim/platform/app/(shell)/home/_components/home-conversation/home-conversation.tsx‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import { useState, useTransition } from 'react'
44
import { useRouter } from 'next/navigation'
5+
import { useSession } from '@/lib/auth/client'
56
import { organizationRoutes } from '@/lib/navigation/paths'
67
import { OrganizationConversation } from '@/app/o/[organizationId]/components/organization-conversation'
78
import { useOrganizationContext } from '@/app/o/[organizationId]/providers/organization-provider'
89
import { SEARCH_MODES } from '@/app/o/[organizationId]/search/use-organization-search'
910
import { HomeDashboardSkeleton } from '@/platform/app/(shell)/home/_components/home-dashboard/home-dashboard-skeleton'
1011
import { LiveHome } from '@/platform/app/(shell)/home/_components/live-home/live-home'
1112
import { SearchSurfaceHeader } from '@/platform/app/(shell)/search/_components/search-surface/search-surface-header'
13+
import { useMothershipDraftsStore } from '@/stores/mothership-drafts/store'
1214

1315
/** Search's Assistant keeps its own unsent question; the agent composer keeps the default `home` key. */
1416
const HOME_ASSISTANT_DRAFT_ID = 'home-assistant'
@@ -21,6 +23,7 @@ interface HomeConversationProps {
2123
export function HomeConversation({ requestMode }: HomeConversationProps) {
2224
const { organization } = useOrganizationContext()
2325
const router = useRouter()
26+
const { data: session } = useSession()
2427
const routes = organizationRoutes(organization.id)
2528
const [conversationInstance, setConversationInstance] = useState(0)
2629
const [isStartingNew, startNewTransition] = useTransition()
@@ -32,16 +35,25 @@ export function HomeConversation({ requestMode }: HomeConversationProps) {
3235
activeMode: 'assistant',
3336
modes: [...SEARCH_MODES],
3437
changeMode: (mode) => {
35-
if (mode === 'search') router.push(`${routes.search}?mode=search`)
38+
if (mode !== 'search') return
39+
const { pathname } = window.location
40+
const chatPath = pathname.startsWith(`${routes.search}/chat/`) ? pathname : routes.search
41+
router.push(`${chatPath}?mode=search`)
3642
},
3743
newLabel: 'New chat',
3844
canStartNew: true,
3945
isStartingNew,
40-
startNew: () =>
46+
startNew: () => {
47+
useMothershipDraftsStore
48+
.getState()
49+
.clearDraft(
50+
`${session?.user?.id}:organization:${organization.id}:${HOME_ASSISTANT_DRAFT_ID}`
51+
)
4152
startNewTransition(() => {
4253
setConversationInstance((current) => current + 1)
4354
router.push(routes.home, { scroll: false })
44-
}),
55+
})
56+
},
4557
}}
4658
/>
4759
)

‎apps/sim/platform/app/(shell)/search/_components/search-surface/search-surface.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { RedesignSurface } from '@/app/o/[organizationId]/_redesign/redesign-hos
55
import { useOrganizationContext } from '@/app/o/[organizationId]/providers/organization-provider'
66
import { SearchFrame } from '@/app/o/[organizationId]/search/search-frame'
77
import {
8-
type OrganizationSearchState,
98
useOrganizationSearch,
109
useSearchFieldDraft,
1110
} from '@/app/o/[organizationId]/search/use-organization-search'
@@ -16,7 +15,7 @@ import { SearchResults } from '@/platform/app/(shell)/_components/search/search-
1615
import { SearchHistory } from '@/platform/app/(shell)/search/_components/search-surface/search-history'
1716
import styles from '@/platform/app/(shell)/search/_components/search-surface/search-surface.module.css'
1817
import { SearchSurfaceHeader } from '@/platform/app/(shell)/search/_components/search-surface/search-surface-header'
19-
import { Button, IconButton } from '@/platform/design-system/components/button/button'
18+
import { IconButton } from '@/platform/design-system/components/button/button'
2019
import { Icon } from '@/platform/design-system/components/icon/icon'
2120
import { useScrollEdges } from '@/platform/design-system/components/scroll-area/use-scroll-edges'
2221

‎apps/sim/platform/design-system/components/button/button.shared.module.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
.chipAction:has([aria-expanded="true"]) {
159159
opacity: 1;
160160
}
161-
.chipRow[data-action-side="start"]:hover > .chip > svg {
161+
.chipRow[data-action-side="start"]:is(:hover, :has(:focus-visible)) > .chip > svg {
162162
visibility: hidden;
163163
}
164164

‎apps/sim/scripts/test-org-redesign-e2e.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,10 +1335,17 @@ async function homeChecks() {
13351335
})
13361336
const chatId = new URL(page.url()).pathname.split('/').at(-1)
13371337
await expect(page.getByRole('navigation', { name: 'Search views' })).toBeVisible()
1338-
await page.getByRole('button', { name: 'New chat' }).click()
1339-
await expect(page).toHaveURL(/\/home$/)
1340-
await expect(composer(page)).toBeVisible()
1341-
await page.goto(orgUrl(`/search/chat/${chatId}`))
1338+
await composer(page).fill('An unsent follow-up')
1339+
await page
1340+
.getByRole('navigation', { name: 'Search views' })
1341+
.getByRole('button', { name: 'Search' })
1342+
.click()
1343+
await expect(page).toHaveURL(new RegExp(`/search/chat/${chatId}\\?mode=search`))
1344+
await expect(searchField(page)).toBeVisible()
1345+
await page
1346+
.getByRole('navigation', { name: 'Search views' })
1347+
.getByRole('button', { name: 'Assistant' })
1348+
.click()
13421349
await expect(page.getByText('Hello from the scripted agent.')).toBeVisible()
13431350
await expect(
13441351
sidebar(page)
@@ -1348,6 +1355,17 @@ async function homeChecks() {
13481355
})
13491356
}
13501357
)
1358+
await check('New chat on a chat started from Home returns to an empty Home', async () => {
1359+
await withSession(MEMBER, async ({ page }) => {
1360+
await page.goto(orgUrl('/home'))
1361+
await composer(page).fill('Say hello again from Home')
1362+
await composer(page).press('Enter')
1363+
await expect(page).toHaveURL(/\/search\/chat\/[^/?]+/, { timeout: 30_000 })
1364+
await page.getByRole('button', { name: 'New chat' }).click()
1365+
await expect(page).toHaveURL(/\/home$/)
1366+
await expect(composer(page)).toHaveValue('')
1367+
})
1368+
})
13511369
await check('Home, Search and the agent keep separate drafts', async () => {
13521370
await withSession(MEMBER, async ({ page }) => {
13531371
await page.goto(orgUrl('/home'))

0 commit comments

Comments
 (0)