Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(user-interviews): semantic search box on topics list page (#58876)

Paul D'Ambrae47f727d2ad5
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 6cf6eb3ae73e..3a1a270e3b5d 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -1851,7 +1851,7 @@ snapshots:
filters-taxonomic-filter-headless--properties--dark:
hash: v1.k794b7964.4ee695e5751c6f73e9742ab0cfeecf61b5adfe829cf3a0d49ab2877cae8b212f.jPN9l5TDgLRy9NzHenXHCU903UDg8-GdeGpf4PXt7aA
filters-taxonomic-filter-headless--properties--light:
- hash: v1.k794b7964.7af6b884e5d826df422db99e4a99d2172f3316561a499dbe386ea098b1fc54a9.rti2DMpqC0WEtd_AtG838vQlgQMHfwjBAR4uLN_HnUk
+ hash: v1.k794b7964.afa422fd784363e602da5668ab488a823260acba8c2b1168dc85bcbf434d3ddf.Wjl32UIE5KhBda_SpJYwXKZ2FGmnlFbtzv4uKDaJRIs
filters-taxonomic-filter-headless--suggested-filters-with-recents--dark:
hash: v1.k794b7964.c3a6cd419610bc486261efa753816547f080f00c838bde0b8720cf12067b3b22.nxBtExiDfJ3USkhV9RY1VPU_U2dGyEYCMFbhvtOcuVs
filters-taxonomic-filter-headless--suggested-filters-with-recents--light:
@@ -4351,9 +4351,9 @@ snapshots:
scenes-app-data-pipelines-event-filtering--live-mode--light:
hash: v1.k794b7964.3b67e943ab5f09a1ab90d710522e6389ed328bf0f7bb8d44e660b528903f8789.qRoUqSLsXr0z-C87p_jkG0jFy7z_3AWiZddCLt1cyIQ
scenes-app-data-pipelines-event-filtering--many-conditions--dark:
- hash: v1.k794b7964.d1d50902f488484286d424a5a2068162005c7733defe4647a2275933d05fd881.86oz8Mi7Ne1129473NVicr-OqW5iWcKuBlkwEiVTCGQ
+ hash: v1.k794b7964.9fe1402f2ebe21e7c89d21b943a2c77f20bc4d0708a668645a7db7cee51ae2c0.zrIB-gPgSDb-7q5zYuWVOpUQ4s-6KLE_ShFv32XIy3M
scenes-app-data-pipelines-event-filtering--many-conditions--light:
- hash: v1.k794b7964.2cf08a3d69032568049faf0ad425b4de71b634a8fe99f742361d609fa0490dac.nkd2u1xpfTsBpkmmTpuIk3YC8cAsrdHtUpDQjYJqfx8
+ hash: v1.k794b7964.9e3d017978dabf9a194a9fcf50a823faf391b9408687b33e8d07e1974d402d7a.xOQik9bmulMBDKxoNZCoDJbqpYVrwbomBpKtYt1mb9M
scenes-app-data-pipelines-event-filtering--many-test-cases--dark:
hash: v1.k794b7964.2b3f2079c09de617f4f611b61075c9b8aa2e89678d6e3e7d17d326337c7391e8.Cc1y1vM1UGaECxArQB4Tz80LB0MmlSekf7Y5f9BICm4
scenes-app-data-pipelines-event-filtering--many-test-cases--light:
@@ -5830,6 +5830,18 @@ snapshots:
hash: v1.k794b7964.5fd9cfd154dfac9e92c492b11d72f4b26f8f6c91b073d7b8c728ecbcb8f699e4.Y7xIgQfsOCcp9HiLZaExdWRFGE7WFst8c13z8uM8tME
scenes-app-surveys-surveyresponsekeysreference--webhook--light:
hash: v1.k794b7964.9b5c484a3a1bd7a09c266a1f164e3ed9eef3ffabbcd12253f0843b3f0b69a808.cc6Rai2vShlFJA_KypMbVcc1IIaVX0nTcZ29RPEEZjo
+ scenes-app-user-research-topics--search-no-results--dark:
+ hash: v1.k794b7964.194b84216db3619fdf87c7b1e7fcb01c3006e9de717ee1a7f0a6586cd19e6430.hVr4aj9pbjvmrSYZzZqj0u5Y6htcodeHNOM44V6BEQM
+ scenes-app-user-research-topics--search-no-results--light:
+ hash: v1.k794b7964.ff0bc9fb718908b9bd7aec82c9fdfff3d1beacd788bb3ed3721245ee7af9fae3.8_bm5mLUjc3uTKstx8eTREoruP53hFu8KO7wAs3VKMY
+ scenes-app-user-research-topics--search-with-results--dark:
+ hash: v1.k794b7964.eb87efdfd040d41204e1d4cd2af3e5c8a31616c4c75b8597ffdbcf2c218e87e6.yArNJAeAczj4qkuAI7V9KR3CEXwe_LkSgmlapsXpOi8
+ scenes-app-user-research-topics--search-with-results--light:
+ hash: v1.k794b7964.3813435da13a613c0cf9855f40c89ed46a2d38a2408f933e60fb8d79f2126cd9.KBq9Fk2Jf7uSN_j7SPoji-vu5FwJuy2lMv4V_c__UwA
+ scenes-app-user-research-topics--topics-list--dark:
+ hash: v1.k794b7964.d69d7670abb2a83ae34f5fd1d5207f21e5b1ef14e0116997b55b6854f77564a5.BuxfmZGhUt3c9qQw3T27cYFr9cnafBjOJXLbAke8Sx4
+ scenes-app-user-research-topics--topics-list--light:
+ hash: v1.k794b7964.c4ee7785c554f517bcaf7013daa0277ccb038faf2883d1ddb3ccb6f3ac7c7e00.apAT1Kl9oDw_AAmV8akOA9zvcF0mOUCUjtrEwJ1wA54
scenes-app-web-analytics--web-analytics-dashboard--dark:
hash: v1.k794b7964.d493d0022b694b7596a58ee1fd25c7658dc1de6454c588b275980213e90939e6.lMoXkY33jv_2eDy6QZpYKh_mUt95j8VJHjj6m5zmZG8
scenes-app-web-analytics--web-analytics-dashboard--light:
diff --git a/frontend/src/exporter/scenes/ExporterInterviewScene.tsx b/frontend/src/exporter/scenes/ExporterInterviewScene.tsx
index 0649552b644e..4b066e29a1a9 100644
--- a/frontend/src/exporter/scenes/ExporterInterviewScene.tsx
+++ b/frontend/src/exporter/scenes/ExporterInterviewScene.tsx
@@ -8,7 +8,7 @@ import { RobotHog } from 'lib/components/hedgehogs'
import { InterviewExportPayload } from '../types'
-type CallState = 'idle' | 'loading' | 'connecting' | 'in-call' | 'ended' | 'error'
+type CallState = 'already-replied' | 'idle' | 'loading' | 'connecting' | 'in-call' | 'ended' | 'error'
type ConversationPhase = 'agent-talking' | 'listening' | 'thinking'
@@ -109,6 +109,18 @@ function EndedPanel(): JSX.Element {
)
}
+function AlreadyRepliedPanel({ interview }: { interview: InterviewExportPayload }): JSX.Element {
+ return (
+ <>
+ <h2 className="text-2xl font-bold mb-2">Thanks for your response!</h2>
+ <p className="text-muted">
+ We've already received your interview about <strong>{interview.topic}</strong>. We really appreciate you
+ taking the time — your feedback helps us build a better product.
+ </p>
+ </>
+ )
+}
+
function ErrorPanel({ errorMessage }: { errorMessage: string | null }): JSX.Element {
return (
<div className="text-danger">
@@ -150,6 +162,7 @@ function CallActionButton({
Try again
</LemonButton>
)
+ case 'already-replied':
case 'connecting':
case 'ended':
return null
@@ -174,6 +187,7 @@ const CallBodyPanel = memo(function CallBodyPanel({
const isPreCall = state === 'idle' || state === 'loading'
return (
<div className="flex-1 min-w-0">
+ {state === 'already-replied' && <AlreadyRepliedPanel interview={interview} />}
{isPreCall && <PreCallIntro interview={interview} />}
{state === 'connecting' && <ConnectingPanel />}
{state === 'in-call' && <LivePanel />}
@@ -211,7 +225,7 @@ export default function ExporterInterviewScene({
interview: InterviewExportPayload
accessToken?: string
}): JSX.Element {
- const [state, setState] = useState<CallState>('idle')
+ const [state, setState] = useState<CallState>(interview.already_replied ? 'already-replied' : 'idle')
// Default to 'thinking' — between connection-up and the agent's first speech-start
// the assistant is loading its opener, which can take a few seconds. After
// speech-end transitions us into 'listening', subsequent silent moments correctly
diff --git a/frontend/src/exporter/stories/ExporterInterview.stories.tsx b/frontend/src/exporter/stories/ExporterInterview.stories.tsx
index 4d46fa201d1c..e39ef2bcf3fc 100644
--- a/frontend/src/exporter/stories/ExporterInterview.stories.tsx
+++ b/frontend/src/exporter/stories/ExporterInterview.stories.tsx
@@ -10,6 +10,7 @@ const interview: InterviewExportPayload = {
interviewee_identifier: 'interviewee-abc',
user_name: 'Sam',
topic: 'how you use dashboards',
+ already_replied: false,
}
type Story = StoryObj<ExportedData>
diff --git a/frontend/src/exporter/types.ts b/frontend/src/exporter/types.ts
index ce50a6dbb58c..688090153f92 100644
--- a/frontend/src/exporter/types.ts
+++ b/frontend/src/exporter/types.ts
@@ -25,6 +25,7 @@ export interface InterviewExportPayload {
interviewee_identifier: string
user_name: string
topic: string
+ already_replied: boolean
/**
* NOTE: `agent_context`, `questions`, and the Vapi credentials are intentionally NOT in
* this payload. They live behind `POST /api/user_interviews/share/<token>/start_call/`
diff --git a/frontend/src/scenes/user-research/UserInterviews.stories.tsx b/frontend/src/scenes/user-research/UserInterviews.stories.tsx
new file mode 100644
index 000000000000..66958d67f360
--- /dev/null
+++ b/frontend/src/scenes/user-research/UserInterviews.stories.tsx
@@ -0,0 +1,140 @@
+import { MOCK_DEFAULT_BASIC_USER } from '~/lib/api.mock'
+
+import type { Meta, StoryObj } from '@storybook/react'
+import { within } from '@testing-library/dom'
+import userEvent from '@testing-library/user-event'
+
+import { App } from 'scenes/App'
+import { urls } from 'scenes/urls'
+
+import { mswDecorator } from '~/mocks/browser'
+import { toPaginatedResponse } from '~/mocks/handlers'
+
+import type {
+ UserInterviewSearchResultApi,
+ UserInterviewTopicApi,
+} from '../../../../products/user_interviews/frontend/generated/api.schemas'
+
+const MOCK_TOPICS = [
+ {
+ id: '01999999-0000-0000-0000-000000000001',
+ created_by: MOCK_DEFAULT_BASIC_USER,
+ created_at: '2026-05-15T10:00:00Z',
+ topic: 'How users discover the MCP integration',
+ interviewee_distinct_ids: [],
+ agent_context: '',
+ questions: ['Why MCP?', 'Web UI experience?', 'What could we improve?'],
+ },
+ {
+ id: '01999999-0000-0000-0000-000000000002',
+ created_by: MOCK_DEFAULT_BASIC_USER,
+ created_at: '2026-05-12T09:30:00Z',
+ topic: 'Trial users that did not convert',
+ interviewee_emails: ['[email protected]', '[email protected]'],
+ interviewee_distinct_ids: ['distinct-no-email'],
+ agent_context: 'Be warm, the trial just ended',
+ questions: ['What was missing?', 'What were you hoping for?'],
+ },
+ {
+ id: '01999999-0000-0000-0000-000000000003',
+ created_by: MOCK_DEFAULT_BASIC_USER,
+ created_at: '2026-05-10T14:00:00Z',
+ topic: 'Power users of session replay',
+ interviewee_emails: [],
+ interviewee_distinct_ids: ['power-user-1', 'power-user-2'],
+ agent_context: '',
+ questions: ['How did you discover replay?', 'What workflow does it support?'],
+ },
+] as unknown as UserInterviewTopicApi[]
+
+const MOCK_SEARCH_RESULTS: UserInterviewSearchResultApi[] = [
+ {
+ interview_id: 'i-1',
+ topic_id: '01999999-0000-0000-0000-000000000001',
+ document_type: 'transcript',
+ similarity: 0.92,
+ interviewee_identifier: '[email protected]',
+ content_snippet:
+ "I just use the MCP from Claude Code. Honestly I've never opened the PostHog web UI to make a chart — the agent does it faster and I trust it.",
+ created_at: '2026-05-12T10:00:00Z',
+ },
+ {
+ interview_id: 'i-2',
+ topic_id: '01999999-0000-0000-0000-000000000001',
+ document_type: 'summary',
+ similarity: 0.84,
+ interviewee_identifier: '[email protected]',
+ content_snippet:
+ 'Heavy MCP user. Prefers conversational queries over clicking through filters. Wants chart-saving via the MCP to be more obvious.',
+ created_at: '2026-05-11T09:30:00Z',
+ },
+ {
+ interview_id: 'i-3',
+ topic_id: '01999999-0000-0000-0000-000000000001',
+ document_type: 'transcript',
+ similarity: 0.71,
+ interviewee_identifier: '[email protected]',
+ content_snippet:
+ "Most of my colleagues still use the web UI, but I'm a CLI person. The MCP fits my workflow because I'm already in my terminal all day.",
+ created_at: '2026-05-10T16:00:00Z',
+ },
+]
+
+type Empty = Record<string, never>
+
+const meta: Meta<Empty> = {
+ component: App,
+ title: 'Scenes-App/User Research/Topics',
+ parameters: {
+ layout: 'fullscreen',
+ viewMode: 'story',
+ mockDate: '2026-05-19',
+ pageUrl: urls.userInterviews(),
+ testOptions: {
+ waitForLoadersToDisappear: true,
+ },
+ },
+ decorators: [
+ mswDecorator({
+ get: {
+ '/api/environments/:team_id/user_interview_topics/': toPaginatedResponse(MOCK_TOPICS),
+ },
+ post: {
+ '/api/environments/:team_id/user_interviews/search/': MOCK_SEARCH_RESULTS,
+ },
+ }),
+ ],
+}
+export default meta
+type Story = StoryObj<Empty>
+
+async function typeSearch(canvasElement: HTMLElement, query: string): Promise<void> {
+ const canvas = within(canvasElement)
+ const input = await canvas.findByPlaceholderText(/Search what users said/i)
+ await userEvent.type(input, query)
+}
+
+export const TopicsList: Story = {}
+
+export const SearchWithResults: Story = {
+ play: async ({ canvasElement }) => {
+ await typeSearch(canvasElement, 'how do you use the mcp')
+ },
+}
+
+export const SearchNoResults: Story = {
+ decorators: [
+ mswDecorator({
+ get: {
+ '/api/environments/:team_id/user_interview_topics/': toPaginatedResponse(MOCK_TOPICS),
+ },
+ post: {
+ '/api/environments/:team_id/user_interviews/search/': [] as UserInterviewSearchResultApi[],
+ },
+ }),
+ ],
+ play: async ({ canvasElement }) => {
+ await typeSearch(canvasElement, 'something nobody talked about')
+ },
+}
diff --git a/posthog/api/sharing.py b/posthog/api/sharing.py
index 0a859dbf8155..f8ac03273f6c 100644
--- a/posthog/api/sharing.py
+++ b/posthog/api/sharing.py
@@ -1046,13 +1046,18 @@ class SharingViewerPageViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSe
except Exception:
raise NotFound("No heatmap found")
elif isinstance(resource, SharingConfiguration) and resource.interviewee_context:
- from products.user_interviews.backend.facade.api import parse_interviewee_identifier
+ from products.user_interviews.backend.facade.api import has_replied, parse_interviewee_identifier
ic = resource.interviewee_context
topic = ic.topic
asset_title = topic.topic or "User interview"
asset_description = "PostHog AI user interview"
user_name = parse_interviewee_identifier(ic.interviewee_identifier).display_name
+ already_replied = has_replied(
+ team_id=topic.team_id,
+ topic_id=topic.id,
+ interviewee_identifier=ic.interviewee_identifier,
+ )
# Keep agent_context, questions, and Vapi credentials OUT of the public HTML —
# the recipient would otherwise see their own internal-notes context in view-source.
# The exporter scene fetches those server-side via /start_call/ when the user clicks Start.
@@ -1064,6 +1069,7 @@ class SharingViewerPageViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSe
"interviewee_identifier": ic.interviewee_identifier,
"user_name": user_name,
"topic": topic.topic,
+ "already_replied": already_replied,
},
}
)
diff --git a/products/user_interviews/frontend/UserInterviews.tsx b/products/user_interviews/frontend/UserInterviews.tsx
index faec866f2674..46802a95173d 100644
--- a/products/user_interviews/frontend/UserInterviews.tsx
+++ b/products/user_interviews/frontend/UserInterviews.tsx
@@ -1,9 +1,10 @@
-import { useValues } from 'kea'
+import { useActions, useValues } from 'kea'
-import { IconSparkles } from '@posthog/icons'
-import { LemonButton, LemonTable } from '@posthog/lemon-ui'
+import { IconSearch, IconSparkles } from '@posthog/icons'
+import { LemonButton, LemonInput, LemonTable, LemonTag, Link } from '@posthog/lemon-ui'
import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'
+import { cn } from 'lib/utils/css-classes'
import { useMaxTool } from 'scenes/max/useMaxTool'
import { sceneConfigurations } from 'scenes/scenes'
import { Scene, SceneExport } from 'scenes/sceneTypes'
@@ -12,7 +13,7 @@ import { urls } from 'scenes/urls'
import { SceneContent } from '~/layout/scenes/components/SceneContent'
import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
-import type { UserInterviewTopicApi } from './generated/api.schemas'
+import type { UserInterviewSearchResultApi, UserInterviewTopicApi } from './generated/api.schemas'
import { userInterviewsLogic } from './userInterviewsLogic'
export const scene: SceneExport = {
@@ -46,8 +47,53 @@ const NEW_TOPIC_SUGGESTIONS = [
'Research how teams are using dashboards day-to-day',
]
+function SearchResultCard({ result }: { result: UserInterviewSearchResultApi }): JSX.Element {
+ const target = result.topic_id
+ ? urls.userInterviewResponse(result.topic_id, encodeURIComponent(result.interviewee_identifier))
+ : null
+ const card = (
+ <div className="border rounded p-3 hover:bg-accent-highlight-secondary">
+ <div className="flex items-center gap-2 mb-1 text-sm">
+ <LemonTag type="muted">{result.document_type}</LemonTag>
+ <span className="text-muted">{Math.round(result.similarity * 100)}% match</span>
+ <span className="text-muted">·</span>
+ <span>{result.interviewee_identifier}</span>
+ </div>
+ <p className="text-sm">{result.content_snippet}</p>
+ </div>
+ )
+ return target ? (
+ <Link to={target} className="block">
+ {card}
+ </Link>
+ ) : (
+ card
+ )
+}
+
+function SearchResults({
+ results,
+ loading,
+}: {
+ results: UserInterviewSearchResultApi[]
+ loading: boolean
+}): JSX.Element {
+ if (results.length === 0) {
+ return <p className="text-muted">{loading ? 'Searching…' : 'No matching responses yet.'}</p>
+ }
+ return (
+ <div className={cn('flex flex-col gap-2 transition-opacity', loading && 'opacity-50')}>
+ {results.map((r) => (
+ <SearchResultCard key={`${r.interview_id}-${r.document_type}`} result={r} />
+ ))}
+ </div>
+ )
+}
+
export function UserInterviews(): JSX.Element {
- const { topics, topicsLoading } = useValues(userInterviewsLogic)
+ const { topics, topicsLoading, searchQuery, searchResults, searchResultsLoading } = useValues(userInterviewsLogic)
+ const { setSearchQuery } = useActions(userInterviewsLogic)
+ const hasSearch = searchQuery.trim().length > 0
const { openMax } = useMaxTool({
identifier: 'create_user_interview_topic',
@@ -76,57 +122,71 @@ export function UserInterviews(): JSX.Element {
</LemonButton>
}
/>
- <LemonTable
- loading={topicsLoading}
- columns={[
- {
- title: 'Topic',
- key: 'topic',
- render: (_, row: UserInterviewTopicApi) => (
- <LemonTableLink title={row.topic} to={urls.userInterview(row.id)} />
- ),
- },
- {
- title: 'Targeting',
- key: 'targeting',
- render: (_, row: UserInterviewTopicApi) => (
- <span className="text-sm">{targetingLabel(row)}</span>
- ),
- },
- {
- title: 'Questions',
- key: 'questions',
- width: 100,
- render: (_, row: UserInterviewTopicApi) => {
- const count = row.questions?.length || 0
- return (
- <span className="text-muted">
- {count} question{count !== 1 ? 's' : ''}
- </span>
- )
- },
- },
- {
- title: 'Created',
- key: 'created_at',
- render: (_, row: UserInterviewTopicApi) => (
- <span className="text-muted whitespace-nowrap">{row.created_at?.split('T')[0]}</span>
- ),
- sorter: (a, b) => (a.created_at || '').localeCompare(b.created_at || ''),
- },
- {
- title: 'Created by',
- key: 'created_by',
- render: (_, row: UserInterviewTopicApi) => (
- <span>{row.created_by?.first_name || row.created_by?.email || '—'}</span>
- ),
- },
- ]}
- dataSource={topics}
- rowKey="id"
- loadingSkeletonRows={5}
- emptyState="No topics yet. Click 'New topic' to get started with PostHog AI."
+ <LemonInput
+ type="search"
+ prefix={<IconSearch />}
+ placeholder="Search what users said across all interviews — e.g. 'problems with the taxonomic filter'"
+ value={searchQuery}
+ onChange={setSearchQuery}
+ allowClear
+ fullWidth
+ data-attr="user-interviews-search"
/>
+ {hasSearch ? (
+ <SearchResults results={searchResults} loading={searchResultsLoading} />
+ ) : (
+ <LemonTable
+ loading={topicsLoading}
+ columns={[
+ {
+ title: 'Topic',
+ key: 'topic',
+ render: (_, row: UserInterviewTopicApi) => (
+ <LemonTableLink title={row.topic} to={urls.userInterview(row.id)} />
+ ),
+ },
+ {
+ title: 'Targeting',
+ key: 'targeting',
+ render: (_, row: UserInterviewTopicApi) => (
+ <span className="text-sm">{targetingLabel(row)}</span>
+ ),
+ },
+ {
+ title: 'Questions',
+ key: 'questions',
+ width: 100,
+ render: (_, row: UserInterviewTopicApi) => {
+ const count = row.questions?.length || 0
+ return (
+ <span className="text-muted">
+ {count} question{count !== 1 ? 's' : ''}
+ </span>
+ )
+ },
+ },
+ {
+ title: 'Created',
+ key: 'created_at',
+ render: (_, row: UserInterviewTopicApi) => (
+ <span className="text-muted whitespace-nowrap">{row.created_at?.split('T')[0]}</span>
+ ),
+ sorter: (a, b) => (a.created_at || '').localeCompare(b.created_at || ''),
+ },
+ {
+ title: 'Created by',
+ key: 'created_by',
+ render: (_, row: UserInterviewTopicApi) => (
+ <span>{row.created_by?.first_name || row.created_by?.email || '—'}</span>
+ ),
+ },
+ ]}
+ dataSource={topics}
+ rowKey="id"
+ loadingSkeletonRows={5}
+ emptyState="No topics yet. Click 'New topic' to get started with PostHog AI."
+ />
+ )}
</SceneContent>
)
}
diff --git a/products/user_interviews/frontend/userInterviewsLogic.ts b/products/user_interviews/frontend/userInterviewsLogic.ts
index f605e90b0959..6531d4d36296 100644
--- a/products/user_interviews/frontend/userInterviewsLogic.ts
+++ b/products/user_interviews/frontend/userInterviewsLogic.ts
@@ -1,4 +1,4 @@
-import { afterMount, kea, path, selectors } from 'kea'
+import { actions, afterMount, kea, listeners, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
import { teamLogic } from 'scenes/teamLogic'
@@ -6,13 +6,24 @@ import { urls } from 'scenes/urls'
import { Breadcrumb } from '~/types'
-import { userInterviewTopicsList } from './generated/api'
-import type { UserInterviewTopicApi } from './generated/api.schemas'
+import { userInterviewTopicsList, userInterviewsSearchCreate } from './generated/api'
+import type { UserInterviewSearchResultApi, UserInterviewTopicApi } from './generated/api.schemas'
import type { userInterviewsLogicType } from './userInterviewsLogicType'
export const userInterviewsLogic = kea<userInterviewsLogicType>([
path(['products', 'user_interviews', 'frontend', 'userInterviewsLogic']),
- loaders({
+ actions({
+ setSearchQuery: (searchQuery: string) => ({ searchQuery }),
+ }),
+ reducers({
+ searchQuery: [
+ '' as string,
+ {
+ setSearchQuery: (_, { searchQuery }) => searchQuery,
+ },
+ ],
+ }),
+ loaders(({ values }) => ({
topics: {
__default: [] as UserInterviewTopicApi[],
loadTopics: async () => {
@@ -21,7 +32,26 @@ export const userInterviewsLogic = kea<userInterviewsLogicType>([
return response.results
},
},
- }),
+ searchResults: {
+ __default: [] as UserInterviewSearchResultApi[],
+ loadSearchResults: async (_: unknown, breakpoint) => {
+ await breakpoint(300)
+ const query = values.searchQuery.trim()
+ if (!query) {
+ return []
+ }
+ const projectId = String(teamLogic.values.currentTeamId)
+ const results = await userInterviewsSearchCreate(projectId, { query })
+ breakpoint()
+ return results
+ },
+ },
+ })),
+ listeners(({ actions }) => ({
+ setSearchQuery: () => {
+ actions.loadSearchResults(null)
+ },
+ })),
selectors({
breadcrumbs: [
() => [],