From bd94620e1a3741a870546fbd52d9cbd08afec1fa Mon Sep 17 00:00:00 2001 From: Hendrik Liebau Date: Sun, 7 Jul 2019 12:34:34 +0200 Subject: [PATCH] feat(demos): use react-router in history-service demo (#477) --- package.json | 4 +- packages/demos/src/history-service/app.tsx | 2 +- .../src/history-service/history-consumer.tsx | 90 ------------------- .../history-consumer/history-consumer.tsx | 42 +++++++++ .../index.tsx} | 10 +-- .../history-consumer/new-path-control.tsx | 46 ++++++++++ .../history-consumer/pathname-label.tsx | 19 ++++ .../demos/src/history-service/index.test.ts | 10 +-- packages/react/package.json | 2 +- packages/website/package.json | 2 +- yarn.lock | 4 +- 11 files changed, 122 insertions(+), 109 deletions(-) delete mode 100644 packages/demos/src/history-service/history-consumer.tsx create mode 100644 packages/demos/src/history-service/history-consumer/history-consumer.tsx rename packages/demos/src/history-service/{history-consumer-definition.tsx => history-consumer/index.tsx} (80%) create mode 100644 packages/demos/src/history-service/history-consumer/new-path-control.tsx create mode 100644 packages/demos/src/history-service/history-consumer/pathname-label.tsx diff --git a/package.json b/package.json index dcc1e05b..68fb6127 100644 --- a/package.json +++ b/package.json @@ -62,8 +62,8 @@ "npm-run-all": "^4.1.5", "prettier": "^1.15.2", "puppeteer": "^1.11.0", - "react": "^16.6.3", - "react-dom": "^16.6.3", + "react": "^16.8.6", + "react-dom": "^16.8.6", "rimraf": "^2.6.2", "size-limit": "^1.0.0", "sort-package-json": "^1.16.0", diff --git a/packages/demos/src/history-service/app.tsx b/packages/demos/src/history-service/app.tsx index b0d4ed19..cf38b8a9 100644 --- a/packages/demos/src/history-service/app.tsx +++ b/packages/demos/src/history-service/app.tsx @@ -4,7 +4,7 @@ import { FeatureHubContextProvider } from '@feature-hub/react'; import * as React from 'react'; -import {historyConsumerDefinition} from './history-consumer-definition'; +import {historyConsumerDefinition} from './history-consumer'; export interface AppProps { featureAppManager: FeatureAppManager; diff --git a/packages/demos/src/history-service/history-consumer.tsx b/packages/demos/src/history-service/history-consumer.tsx deleted file mode 100644 index 6de5ee63..00000000 --- a/packages/demos/src/history-service/history-consumer.tsx +++ /dev/null @@ -1,90 +0,0 @@ -import { - Button, - Card, - ControlGroup, - H5, - InputGroup, - Label -} from '@blueprintjs/core'; -import {History} from 'history'; -import * as React from 'react'; -import Media from 'react-media'; - -interface HistoryConsumerProps { - readonly history: History; - readonly historyKey: string; -} - -interface HistoryConsumerState { - readonly pathname: string; -} - -export class HistoryConsumer extends React.Component< - HistoryConsumerProps, - HistoryConsumerState -> { - public readonly state = {pathname: this.props.history.location.pathname}; - - private unlisten?: () => void; - private inputElement: HTMLInputElement | null = null; - - public componentDidMount(): void { - const {history} = this.props; - - this.unlisten = history.listen(({pathname}) => this.setState({pathname})); - } - - public componentWillUnmount(): void { - if (this.unlisten) { - this.unlisten(); - } - } - - public render(): React.ReactNode { - const {historyKey} = this.props; - const specifier = historyKey.slice(historyKey.length - 1); - const {pathname} = this.state; - - return ( - -
History Consumer {specifier.toUpperCase()}
- - - - - {matches => ( - - (this.inputElement = ref)} - /> -