Skip to content

Commit

Permalink
feat(js): refresh cache periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss committed Oct 8, 2018
1 parent 995c216 commit d127509
Show file tree
Hide file tree
Showing 14 changed files with 5,112 additions and 0 deletions.
9 changes: 9 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
3 changes: 3 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/dist
/.cache
3 changes: 3 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: 'algolia',
};
22 changes: 22 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/dist
/.cache

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
5 changes: 5 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"proseWrap": "never",
"trailingComma": "es5"
}
21 changes: 21 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# refresh-cache-periodically

_This project was generated with [create-instantsearch-app](https://github.com/algolia/create-instantsearch-app) by [Algolia](https://algolia.com)._

## Get started

To run this project locally, install the dependencies and run the local server:

```sh
npm install
npm start
```

Alternatively, you may use [Yarn](https://http://yarnpkg.com/):

```sh
yarn
yarn start
```

Open http://localhost:3000 to see your app.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">

<link rel="manifest" href="./manifest.webmanifest">
<link rel="shortcut icon" href="./favicon.png">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.8.0/dist/instantsearch.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.8.0/dist/instantsearch-theme-algolia.min.css">
<link rel="stylesheet" href="./src/index.css">
<link rel="stylesheet" href="./src/app.css">

<title>InstantSearch.js - Refresh cache periodically</title>
</head>

<body>
<div class="ais-InstantSearch">
<h1>InstantSearch.js e-commerce demo</h1>

<p>
The cache is refreshed automatically every 5 seconds.
</p>

<div class="left-panel">
<h2>Brands</h2>
<div id="brand-list"></div>
</div>

<div class="right-panel">
<div id="searchbox" class="ais-SearchBox"></div>
<div id="hits"></div>
<div id="pagination"></div>
</div>
</div>

<script src="https://cdn.jsdelivr.net/npm/algoliasearch@3.30.0/dist/algoliasearchLite.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@2.8.0"></script>
<script src="./src/app.js"></script>
</body>

</html>
15 changes: 15 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/manifest.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "refresh-cache-periodically",
"name": "refresh-cache-periodically Sample",
"icons": [
{
"src": "favicon.png",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
21 changes: 21 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "refresh-cache-periodically",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "parcel index.html --port 3000",
"build": "parcel build index.html",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix"
},
"devDependencies": {
"babel-eslint": "8.2.6",
"eslint": "5.5.0",
"eslint-config-algolia": "13.2.3",
"eslint-config-prettier": "3.0.1",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-prettier": "2.6.2",
"parcel-bundler": "1.9.7",
"prettier": "1.14.2"
}
}
51 changes: 51 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/src/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
body {
font-family: sans-serif;
padding: 1em;
}

em {
font-style: normal;
background-color: cyan;
}

.ais-SearchBox {
margin: 1em 0;
}

.ais-Pagination {
margin-top: 1em;
}

.left-panel {
float: left;
width: 250px;
}

.right-panel {
margin-left: 260px;
}

.ais-InstantSearch {
max-width: 960px;
overflow: hidden;
margin: 0 auto;
}

.ais-Hits-item {
margin-bottom: 1em;
width: calc(50% - 1rem);
}

.ais-Hits-item img {
margin-right: 1em;
}

.hit-name {
margin-bottom: 0.5em;
}

.hit-description {
color: #888;
font-size: 14px;
margin-bottom: 0.5em;
}
56 changes: 56 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* global instantsearch algoliasearch */

const searchClient = algoliasearch(
'B1G2GM9NG0',
'aadef574be1f9252bb48d4ea09b5cfe5'
);

const search = instantsearch({
indexName: 'demo_ecommerce',
searchClient,
});

search.addWidget(
instantsearch.widgets.searchBox({
container: '#searchbox',
})
);

search.addWidget(
instantsearch.widgets.refinementList({
container: '#brand-list',
attributeName: 'brand',
})
);

search.addWidget(
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: `
<div class="ais-Hits-item">
<header class="hit-name">
{{{_highlightResult.name.value}}}
</header>
<img src="{{image}}" align="left" />
<p class="hit-description">
{{{_highlightResult.description.value}}}
</p>
<p class="hit-price">\${{price}}</p>
</div>
`,
},
})
);

search.addWidget(
instantsearch.widgets.pagination({
container: '#pagination',
})
);

setInterval(() => {
search.refresh();
}, 5000);

search.start();
10 changes: 10 additions & 0 deletions InstantSearch.js/refresh-cache-periodically/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body,
h1 {
margin: 0;
padding: 0;
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
}
Loading

0 comments on commit d127509

Please sign in to comment.