Skip to content

Commit a8fdba1

Browse files
committed
add cache name prop
1 parent e934532 commit a8fdba1

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ ReactDOM.render(
4242
);
4343
```
4444

45+
## React Simple Chatbot on midia
46+
47+
1. [webdesignerdepot](https://www.webdesignerdepot.com/2017/08/whats-new-for-designers-august-2017/)
48+
2. [blogduwebdesign](http://www.blogduwebdesign.com/webdesign/ressources-web-du-lundi-aout-164/2507)
49+
3. [codrops](https://tympanus.net/codrops/collective/collective-335/)
50+
4551
## Build with `react-simple-chatbot`
4652

4753
1. [Seth Loh Website](https://github.com/lackdaz/lackdaz.github.io) - Personal website of Seth Loh ([demo](https://www.sethloh.com))

lib/ChatBot.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class ChatBot extends Component {
4949
const {
5050
botDelay,
5151
botAvatar,
52+
cache,
53+
cacheName,
5254
customDelay,
5355
userAvatar,
5456
userDelay,
@@ -86,7 +88,8 @@ class ChatBot extends Component {
8688
previousSteps,
8789
renderedSteps,
8890
} = storage.getData({
89-
cache: this.props.cache,
91+
cacheName,
92+
cache,
9093
firstStep: this.props.steps[0],
9194
steps,
9295
}, () => {
@@ -215,9 +218,10 @@ class ChatBot extends Component {
215218
});
216219
}
217220

218-
if (this.props.cache) {
221+
const { cache, cacheName } = this.props;
222+
if (cache) {
219223
setTimeout(() => {
220-
storage.setData({
224+
storage.setData(cacheName, {
221225
currentStep,
222226
previousStep,
223227
previousSteps,
@@ -547,6 +551,7 @@ ChatBot.propTypes = {
547551
botDelay: PropTypes.number,
548552
bubbleStyle: PropTypes.object,
549553
cache: PropTypes.bool,
554+
cacheName: PropTypes.string,
550555
className: PropTypes.string,
551556
contentStyle: PropTypes.object,
552557
customDelay: PropTypes.number,
@@ -576,6 +581,7 @@ ChatBot.defaultProps = {
576581
botDelay: 1000,
577582
bubbleStyle: {},
578583
cache: false,
584+
cacheName: 'rsc_cache',
579585
className: '',
580586
contentStyle: {},
581587
customStyle: {},

lib/storage.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const JSON = require('circular-json');
22

33
/* istanbul ignore next */
4-
const getData = ({ cache, firstStep, steps }, callback) => {
4+
const getData = ({ cacheName, cache, firstStep, steps }, callback) => {
55
const currentStep = firstStep;
66
const renderedSteps = [steps[currentStep.id]];
77
const previousSteps = [steps[currentStep.id]];
88
const previousStep = {};
99

10-
if (cache && localStorage.getItem('rsc_cache')) {
11-
const data = JSON.parse(localStorage.getItem('rsc_cache'));
10+
if (cache && localStorage.getItem(cacheName)) {
11+
const data = JSON.parse(localStorage.getItem(cacheName));
1212
const lastStep = data.renderedSteps[data.renderedSteps.length - 1];
1313

1414
if (lastStep && lastStep.end) {
@@ -47,8 +47,8 @@ const getData = ({ cache, firstStep, steps }, callback) => {
4747
};
4848

4949
/* istanbul ignore next */
50-
const setData = (data) => {
51-
localStorage.setItem('rsc_cache', JSON.stringify(data));
50+
const setData = (cacheName, data) => {
51+
localStorage.setItem(cacheName, JSON.stringify(data));
5252
};
5353

5454
export {

0 commit comments

Comments
 (0)