Skip to content

Commit 43df64e

Browse files
authored
Pagination issue in React and add React playground (#31)
* Add playground usage in CONTRIBUTING.md * Add react playground * Fix pagination * Remove useless comment * Remove useless packages
1 parent ed79b82 commit 43df64e

File tree

14 files changed

+11044
-6
lines changed

14 files changed

+11044
-6
lines changed

CONTRIBUTING.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ $ yarn lint:fix
5252
$ yarn build
5353
```
5454

55+
### Playgrounds
56+
57+
To test directly your changes in `instant-meilisearch`, you can run the Vue playground:
58+
59+
```bash
60+
$ yarn playground:vue
61+
```
62+
63+
Or the React playground:
64+
65+
```bash
66+
$ yarn playground:react
67+
```
68+
5569
### Release Process
5670

5771
MeiliSearch tools follow the [Semantic Versioning Convention](https://semver.org/).
@@ -75,7 +89,7 @@ About this automation:
7589
Make a PR modifying the file [`package.json`](/package.json) with the right version.
7690

7791
```javascript
78-
"version": X.X.X
92+
"version": "X.X.X"
7993
```
8094

8195
Once the changes are merged on `master`, you can publish the current draft release via the [GitHub interface](https://github.com/meilisearch/instant-meilisearch/releases).

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"test": "jest",
88
"lint": "eslint --ext .js,.ts,.tsx .",
99
"lint:fix": "eslint --ext .js,.ts,.tsx --fix .",
10-
"build": "rollup -c rollup.config.js && rollup --environment NODE_ENV:production -c rollup.config.js "
10+
"build": "rollup -c rollup.config.js && rollup --environment NODE_ENV:production -c rollup.config.js ",
11+
"playground:vue": "yarn --cwd ./playgrounds/vue && yarn --cwd ./playgrounds/vue serve",
12+
"playground:react": "yarn --cwd ./playgrounds/react && yarn --cwd ./playgrounds/react start"
1113
},
1214
"main": "./dist/instant-meilisearch.umd.js",
1315
"module": "./dist/instant-meilisearch.esm.js",

playgrounds/react/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SKIP_PREFLIGHT_CHECK=true

playgrounds/react/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

playgrounds/react/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `yarn start`
8+
9+
Runs the app in the development mode.<br />
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br />
13+
You will also see any lint errors in the console.
14+
15+
### `yarn test`
16+
17+
Launches the test runner in the interactive watch mode.<br />
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `yarn build`
21+
22+
Builds the app for production to the `build` folder.<br />
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br />
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `yarn eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35+
36+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37+
38+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
To learn React, check out the [React documentation](https://reactjs.org/).
45+
46+
### Code Splitting
47+
48+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49+
50+
### Analyzing the Bundle Size
51+
52+
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53+
54+
### Making a Progressive Web App
55+
56+
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57+
58+
### Advanced Configuration
59+
60+
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61+
62+
### Deployment
63+
64+
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65+
66+
### `yarn build` fails to minify
67+
68+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

playgrounds/react/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "react-playground",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"instantsearch.css": "^7.4.3",
7+
"react": "^16.13.1",
8+
"react-dom": "^16.13.1",
9+
"react-instantsearch-dom": "^6.7.0",
10+
"react-scripts": "3.4.1"
11+
},
12+
"scripts": {
13+
"start": "react-scripts start",
14+
"build": "react-scripts build",
15+
"eject": "react-scripts eject"
16+
},
17+
"eslintConfig": {
18+
"extends": "react-app"
19+
},
20+
"browserslist": {
21+
"production": [
22+
">0.2%",
23+
"not dead",
24+
"not op_mini all"
25+
],
26+
"development": [
27+
"last 1 chrome version",
28+
"last 1 firefox version",
29+
"last 1 safari version"
30+
]
31+
}
32+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<meta name="theme-color" content="#000000" />
7+
<meta
8+
name="description"
9+
content="Demo of MeiliSearch + React InstantSearch usage"
10+
/>
11+
<title>MeiliSearch + React InstantSearch</title>
12+
</head>
13+
<body>
14+
<noscript>You need to enable JavaScript to run this app.</noscript>
15+
<div id="root"></div>
16+
</body>
17+
</html>

playgrounds/react/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/react/src/App.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import "instantsearch.css/themes/algolia-min.css";
2+
import React, { Component } from "react";
3+
import {
4+
InstantSearch,
5+
Hits,
6+
SearchBox,
7+
Pagination,
8+
Highlight,
9+
ClearRefinements,
10+
RefinementList,
11+
Configure
12+
} from "react-instantsearch-dom";
13+
import "./App.css";
14+
import instantMeiliSearch from "./instant-meilisearch.js";
15+
16+
const searchClient = instantMeiliSearch(
17+
"https://demos.meilisearch.com",
18+
"dc3fedaf922de8937fdea01f0a7d59557f1fd31832cb8440ce94231cfdde7f25"
19+
);
20+
21+
class App extends Component {
22+
render() {
23+
return (
24+
<div className="ais-InstantSearch">
25+
<h1>MeiliSearch + React InstantSearch</h1>
26+
<h2>
27+
Search in Steam video games{" "}
28+
<span role="img" aria-label="emoji">
29+
🎮
30+
</span>
31+
</h2>
32+
<p>
33+
This is not the official Steam dataset but only for demo purpose.
34+
Enjoy searching with MeiliSearch!
35+
</p>
36+
<InstantSearch
37+
indexName="steam-video-games"
38+
searchClient={searchClient}
39+
>
40+
<div className="left-panel">
41+
<ClearRefinements />
42+
<h2>Genres</h2>
43+
<RefinementList attribute="genres" />
44+
<h2>Players</h2>
45+
<RefinementList attribute="players" />
46+
<h2>Platforms</h2>
47+
<RefinementList attribute="platforms" />
48+
<h2>Misc</h2>
49+
<RefinementList attribute="misc" />
50+
<Configure hitsPerPage={6} />
51+
</div>
52+
<div className="right-panel">
53+
<SearchBox />
54+
<Hits hitComponent={Hit} />
55+
<Pagination showLast={true}/>
56+
</div>
57+
</InstantSearch>
58+
</div>
59+
);
60+
}
61+
}
62+
63+
function Hit(props) {
64+
return (
65+
<div key={props.hit.id}>
66+
<div className="hit-name">
67+
<Highlight attribute="name" hit={props.hit} />
68+
</div>
69+
<img src={props.hit.image} align="left" alt={props.hit.name} />
70+
<div className="hit-info">price: {props.hit.price}</div>
71+
<div className="hit-info">release date: {props.hit.releaseDate}</div>
72+
</div>
73+
);
74+
}
75+
76+
export default App;

playgrounds/react/src/index.css

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+
}

0 commit comments

Comments
 (0)