@@ -4,15 +4,15 @@ import {
44 createChunkRequestTS ,
55 hybridSearchRequest ,
66 hybridSearchRequestTS ,
7+ searchComponentRequest ,
78} from "../utils/createCodeSnippets" ;
89import { DatasetContext } from "../contexts/DatasetContext" ;
9- import { Accessor , createSignal , Setter , Show , useContext } from "solid-js" ;
10+ import { createSignal , Show , useContext } from "solid-js" ;
1011import { Button } from "terracotta" ;
1112import { ApiKeyGenerateModal } from "./ApiKeyGenerateModal" ;
1213
1314export const CodeExamples = ( ) => {
1415 const { datasetId } = useContext ( DatasetContext ) ;
15- const [ selectedTab , setSelectedTab ] = createSignal ( "fetch" ) ;
1616 const [ openModal , setOpenModal ] = createSignal ( false ) ;
1717 const [ apiKey , setApiKey ] = createSignal < string > (
1818 "tr-********************************" ,
@@ -60,8 +60,6 @@ export const CodeExamples = () => {
6060 < CodeExample
6161 fetchContent = { createChunkRequest ( datasetId ( ) , apiKey ( ) ) }
6262 tsContent = { createChunkRequestTS ( datasetId ( ) , apiKey ( ) ) }
63- selectedTab = { selectedTab }
64- setSelectedTab = { setSelectedTab }
6563 />
6664 </ div >
6765 < div class = "flex flex-col space-y-2" >
@@ -79,8 +77,7 @@ export const CodeExamples = () => {
7977 < CodeExample
8078 fetchContent = { hybridSearchRequest ( datasetId ( ) , apiKey ( ) ) }
8179 tsContent = { hybridSearchRequestTS ( datasetId ( ) , apiKey ( ) ) }
82- selectedTab = { selectedTab }
83- setSelectedTab = { setSelectedTab }
80+ componentContent = { searchComponentRequest ( datasetId ( ) , apiKey ( ) ) }
8481 />
8582 </ div >
8683 < ApiKeyGenerateModal
@@ -97,41 +94,61 @@ export const CodeExamples = () => {
9794const CodeExample = ( props : {
9895 tsContent : string ;
9996 fetchContent : string ;
100- selectedTab : Accessor < string > ;
101- setSelectedTab : Setter < string > ;
97+ componentContent ?: string ;
10298} ) => {
99+ const [ selectedTab , setSelectedTab ] = createSignal ( "fetch" ) ;
103100 return (
104101 < div >
105102 < div class = "mb-4 flex gap-4 border-b pb-1" >
106103 < Button
107104 classList = { {
108105 "font-medium" : true ,
109- "text-fuchsia-800" : props . selectedTab ( ) === "fetch" ,
106+ "text-fuchsia-800" : selectedTab ( ) === "fetch" ,
110107 } }
111- onClick = { ( ) => props . setSelectedTab ( "fetch" ) }
108+ onClick = { ( ) => setSelectedTab ( "fetch" ) }
112109 >
113110 Using Fetch
114111 </ Button >
115112 < Button
116113 classList = { {
117114 "font-medium" : true ,
118- "text-fuchsia-800" : props . selectedTab ( ) === "ts" ,
115+ "text-fuchsia-800" : selectedTab ( ) === "ts" ,
119116 } }
120- onClick = { ( ) => props . setSelectedTab ( "ts" ) }
117+ onClick = { ( ) => setSelectedTab ( "ts" ) }
121118 >
122119 Using the TS SDK
123120 </ Button >
121+ < Show when = { props . componentContent } >
122+ < Button
123+ classList = { {
124+ "font-medium" : true ,
125+ "text-fuchsia-800" : selectedTab ( ) === "component" ,
126+ } }
127+ onClick = { ( ) => setSelectedTab ( "component" ) }
128+ >
129+ Using the Search Component
130+ </ Button >
131+ </ Show >
124132 </ div >
125- < Show when = { props . selectedTab ( ) === "ts" } >
133+ < Show when = { selectedTab ( ) === "ts" } >
126134 < Codeblock content = { `npm install trieve-ts-sdk` } />
127135 < div class = "h-3" />
128136 </ Show >
129- < Show when = { props . selectedTab ( ) === "fetch" } >
137+ < Show when = { selectedTab ( ) === "component" } >
138+ < Codeblock content = { `npm install trieve-search-component` } />
139+ < div class = "h-3" />
140+ </ Show >
141+ < Show when = { selectedTab ( ) === "fetch" } >
130142 < Codeblock content = { props . fetchContent } />
131143 </ Show >
132- < Show when = { props . selectedTab ( ) === "ts" } >
144+ < Show when = { selectedTab ( ) === "ts" } >
133145 < Codeblock content = { props . tsContent } />
134146 </ Show >
147+ < Show when = { selectedTab ( ) === "component" } >
148+ < Show when = { props . componentContent } >
149+ { ( content ) => < Codeblock content = { content ( ) } /> }
150+ </ Show >
151+ </ Show >
135152 </ div >
136153 ) ;
137154} ;
0 commit comments