Skip to content

Commit 6cd2c17

Browse files
bors[bot]bidoubiwa
andauthored
Merge #1015
1015: Fix error handler and playground r=bidoubiwa a=bidoubiwa I introduced a bug in the previous release where information about errors was completely lost. This one fixes that. ALso the javascript playground really works now Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 35b6241 + e3a2b91 commit 6cd2c17

File tree

16 files changed

+5392
-173
lines changed

16 files changed

+5392
-173
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"url": "https://github.com/meilisearch/meilisearch-js"
2828
},
2929
"scripts": {
30+
"playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript start",
3031
"clear_jest": "jest --clearCache",
3132
"cleanup": "shx rm -rf dist/",
3233
"build": "yarn cleanup && rollup -c && rollup -c --environment NODE_ENV:production",

playgrounds/javascript/README.md

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
# Vanilla JavaScript Playground
2-
3-
## Required
4-
5-
- Yarn or NPM
6-
- Parent directory should have its packages installed
7-
8-
## Start
9-
10-
First:
1+
# Javascript Playground
112

3+
## Project setup
124
```
135
yarn install
146
```
157

16-
Run development server
8+
### Compiles and hot-reloads for development
179
```
18-
yarn dev
10+
yarn start
1911
```
2012

21-
## Play
22-
23-
When running `yarn dev` a server it should be served on `http://localhost:3000/`.
24-
25-
Changes in `main.js` and `../../src` hot reload the server.
13+
### Compiles and minifies for production
14+
```
15+
yarn build
16+
```

playgrounds/javascript/index.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="UTF-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>MeiliSearch Playground</title>
4+
<meta charset="utf-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
8+
/>
9+
<meta name="theme-color" content="#000000" />
710
</head>
811
<body>
9-
<div id="app"></div>
10-
<script type="module" src="/main.js"></script>
12+
13+
14+
15+
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
16+
<script src="/src/app.js"></script>
1117
</body>
1218
</html>

playgrounds/javascript/main.js

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
{
2-
"version": "0.0.0",
2+
"name": "js-playground",
3+
"version": "0.1.0",
4+
"description": "Instant-meilisearch playground written with vanilla javascript",
5+
"main": "index.js",
36
"scripts": {
4-
"dev": "vite",
5-
"build": "vite build",
6-
"serve": "vite preview"
7+
"start": "parcel serve index.html --open --port 2222",
8+
"build": "parcel build index.html"
79
},
810
"devDependencies": {
9-
"vite": "^2.4.0"
11+
"@babel/core": "^7.13.1",
12+
"parcel-bundler": "^1.12.4"
1013
},
14+
"resolutions": {
15+
"node-forge": "^0.10.0"
16+
},
17+
"browserslist": [
18+
"last 3 and_chr versions",
19+
"last 3 chrome versions",
20+
"last 3 opera versions",
21+
"last 3 ios_saf versions",
22+
"last 3 safari versions"
23+
],
24+
"license": "MIT",
1125
"dependencies": {}
1226
}

playgrounds/javascript/src/app.css

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
body {
2+
font-family: sans-serif;
3+
padding: 1em;
4+
}
5+
6+
.ais-ClearRefinements {
7+
margin: 1em 0;
8+
}
9+
10+
.ais-SearchBox {
11+
margin: 1em 0;
12+
}
13+
14+
.ais-Pagination {
15+
margin-top: 1em;
16+
}
17+
18+
.left-panel {
19+
float: left;
20+
width: 200px;
21+
}
22+
23+
.right-panel {
24+
margin-left: 210px;
25+
}
26+
27+
.ais-InstantSearch {
28+
max-width: 960px;
29+
overflow: hidden;
30+
margin: 0 auto;
31+
}
32+
33+
.ais-Hits-item {
34+
margin-bottom: 1em;
35+
width: calc(50% - 1rem);
36+
}
37+
38+
.ais-Hits-item img {
39+
margin-right: 1em;
40+
width: 100%;
41+
height: 100%;
42+
margin-bottom: 0.5em;
43+
}
44+
45+
.hit-name {
46+
margin-bottom: 0.5em;
47+
}
48+
49+
.hit-info {
50+
font-size: 90%;
51+
}

playgrounds/javascript/src/app.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { MeiliSearch } from '../../../src/lib/meilisearch'
2+
3+
const config = {
4+
host: 'http://127.0.0.1:7700',
5+
apiKey: 'masterKey',
6+
}
7+
8+
const client = new MeiliSearch(config)
9+
const uid = 'movies'
10+
11+
const addDataset = async () => {
12+
const index = await client.getOrCreateIndex(uid)
13+
const documents = await index.getDocuments()
14+
15+
const dataset = [
16+
{ id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
17+
{ id: 2, title: 'Wonder Woman', genres: ['Action', 'Adventure'] },
18+
{ id: 3, title: 'Life of Pi', genres: ['Adventure', 'Drama'] },
19+
{
20+
id: 4,
21+
title: 'Mad Max: Fury Road',
22+
genres: ['Adventure', 'Science Fiction'],
23+
},
24+
{ id: 5, title: 'Moana', genres: ['Fantasy', 'Action'] },
25+
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
26+
]
27+
if (documents.length === 0) {
28+
const { updateId } = await index.addDocuments(dataset)
29+
await index.waitForPendingUpdate(updateId)
30+
}
31+
}
32+
33+
;(async () => {
34+
await addDataset()
35+
try {
36+
const index = await client.getOrCreateIndex('movies')
37+
38+
const resp = await index.search(
39+
'Moana',
40+
{
41+
limit: 1,
42+
attributesToHighlight: ['title'],
43+
},
44+
'POST'
45+
)
46+
console.log({ resp })
47+
console.log({ hit: resp.hits[0] })
48+
} catch (e) {
49+
console.error(e)
50+
}
51+
})()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
body,
2+
h1 {
3+
margin: 0;
4+
padding: 0;
5+
}
6+
7+
body {
8+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
9+
Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
10+
}

playgrounds/javascript/style.css

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)