Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat - new search react component #2261

Merged
merged 6 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ server/migrations/2024-07-26-165058_move_config_to_table/down.sql
server/migrations/2024-07-26-165058_move_config_to_table/up.sql
dist/**
clients/ts-sdk/dist
clients/search-component/dist
29 changes: 29 additions & 0 deletions .github/workflows/component-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Search component test suite

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

on:
pull_request:
paths:
- "clients/search-component/**"

jobs:
build-test:
runs-on: blacksmith-2vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Running tests
run: yarn build --filter trieve-search-component
tests:
runs-on: blacksmith-2vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Running lint
working-directory: ./clients/search-component
run: yarn lint
2 changes: 0 additions & 2 deletions .github/workflows/ts-sdk-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Deploy TS-SDK docs to github pages
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ embedding-server/data/*
*/dist/**
*/.vite
data/*
clients/ts-sdk/dist/**
clients/ts-sdk/docs/**
clients/ts-sdk/dist
clients/ts-sdk/docs
clients/search-component/dist


server/src/trieve_protobufs/*
server/proto/*
server/migrations/2024-07-26-165058_move_config_to_table/down.sql
server/migrations/2024-07-26-165058_move_config_to_table/up.sql
dist/**
clients/ts-sdk/dist

1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"./frontends/search",
"./frontends/analytics",
"./clients/ts-sdk",
"./clients/search-component"
],
"vitest.disableWorkspaceWarning": true
}
77 changes: 77 additions & 0 deletions clients/search-component/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
## Trieve Search Component

The easiest way to get up and running in your app using trieve search.

## How to use

Install using your favorite package manager:

```
yarn add trieve-search-component
# or
npm install trieve-search-component
# or
pnpm install trieve-search-component
```

After installing the first step is to instantiate a new `TrieveSDK` like so:

```ts
import { TrieveSDK } from "trieve-ts-sdk";

export const trieve = new TrieveSDK({
apiKey: "<your-api-key>",
datasetId: "<dataset-to-use>",
});
```

And then you can use any of the two components in your React application or as web component:

### Search Modal

<details>
<summary>Screenshots</summary>

![light closed](./github/modal-light-1.png)
![dark closed](./github/modal-dark-1.png)
![light open](./github/modal-light-2.png)

</details>

#### Usage in React:

```jsx
<TrieveModalSearch trieve={trieve} />
```

#### Usage in Web Components:

```html
<trieve-modal-search trieve="<your trieve instance>" />
```

### Search Results

<details>
<summary>Screenshots</summary>

![light](./github/search-light.png)
![dark](./github/search-dark.png)

</details>

#### Usage in React:

```jsx
<TrieveSearch trieve={trieve} />
```

#### Usage in Web Components:

```html
<trieve-search trieve="<your trieve instance>" />
```

## License

MIT
10 changes: 10 additions & 0 deletions clients/search-component/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{ ignores: ["**/*.js", "**/*.cjs"] }
);
24 changes: 24 additions & 0 deletions clients/search-component/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
28 changes: 28 additions & 0 deletions clients/search-component/example/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions clients/search-component/example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
32 changes: 32 additions & 0 deletions clients/search-component/example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "example",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.20",
"eslint": "^9.9.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"postcss": "^8.4.41",
"tailwindcss": "^3.4.10",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.1",
"vite": "^5.4.1"
}
}
3 changes: 3 additions & 0 deletions clients/search-component/example/postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
plugins: [require("autoprefixer"), require("tailwindcss")],
};
66 changes: 66 additions & 0 deletions clients/search-component/example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { TrieveSearch, TrieveSDK, TrieveModalSearch } from "../../src/index";
import "../../dist/app.css";
import { useState } from "react";
import { IconMoon, IconNext, IconPrevious, IconSun } from "./Icons";

const trieve = new TrieveSDK({
apiKey: "tr-l1IRx4Jw0iVICiFdf9NroFwmDWQ4CnEd",
datasetId: "85bdeb65-44ec-4c9c-9d64-725601ad672a",
});
export default function App() {
const [theme, setTheme] = useState<"light" | "dark">("light");
const [component, setComponent] = useState(0);
return (
<>
<div
className={`p-12 flex flex-col items-center justify-center w-screen h-screen relative ${
theme === "dark" ? "bg-zinc-900 text-zinc-50" : ""
}`}
>
<div className="absolute top-6 right-6">
<ul>
<li>
<button
onClick={() => setTheme(theme === "light" ? "dark" : "light")}
>
{theme === "light" ? <IconMoon /> : <IconSun />}
</button>
</li>
</ul>
</div>
{component === 0 ? (
<>
<h2 className="font-bold text-center py-8">
Search Modal Component{" "}
</h2>

<TrieveModalSearch trieve={trieve} theme={theme} />
</>
) : (
<>
<h2 className="font-bold text-center py-8">
Search Results Component
</h2>
<TrieveSearch trieve={trieve} theme={theme} />
</>
)}

<ul className="absolute top-1/2 -translate-y-1/2 w-full">
{component > 0 ? (
<li className="left-6 absolute">
<button onClick={() => setComponent(0)}>
<IconPrevious />
</button>
</li>
) : (
<li className="right-6 absolute">
<button onClick={() => setComponent(1)}>
<IconNext />
</button>
</li>
)}
</ul>
</div>
</>
);
}
65 changes: 65 additions & 0 deletions clients/search-component/example/src/Icons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export const IconPrevious = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M15 6l-6 6l6 6" />
</svg>
);

export const IconNext = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M9 6l6 6l-6 6" />
</svg>
);

export const IconMoon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="currentColor"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M12 1.992a10 10 0 1 0 9.236 13.838c.341 -.82 -.476 -1.644 -1.298 -1.31a6.5 6.5 0 0 1 -6.864 -10.787l.077 -.08c.551 -.63 .113 -1.653 -.758 -1.653h-.266l-.068 -.006l-.06 -.002z" />
</svg>
);

export const IconSun = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="icon icon-tabler icons-tabler-outline icon-tabler-sun"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M12 12m-4 0a4 4 0 1 0 8 0a4 4 0 1 0 -8 0" />
<path d="M3 12h1m8 -9v1m8 8h1m-9 8v1m-6.4 -15.4l.7 .7m12.1 -.7l-.7 .7m0 11.4l.7 .7m-12.1 -.7l-.7 .7" />
</svg>
);
Loading
Loading