From f1be771611c6bd7983ea2b16c2cb4ecc7c4f55fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Mon, 20 Feb 2017 11:17:18 +0100 Subject: [PATCH] Disambiguate TypeScript with `tsx` extension. (#3464) Using the technique as discussed in #2761. --- lib/linguist/heuristics.rb | 8 + samples/TypeScript/import.tsx | 384 ++++++++ samples/TypeScript/react-native.tsx | 366 ++++++++ samples/TypeScript/require.tsx | 240 +++++ samples/TypeScript/triple-slash-reference.tsx | 863 ++++++++++++++++++ .../TypeScript/tsxAttributeResolution9.tsx | 27 - test/test_heuristics.rb | 7 + 7 files changed, 1868 insertions(+), 27 deletions(-) create mode 100644 samples/TypeScript/import.tsx create mode 100644 samples/TypeScript/react-native.tsx create mode 100644 samples/TypeScript/require.tsx create mode 100644 samples/TypeScript/triple-slash-reference.tsx delete mode 100644 samples/TypeScript/tsxAttributeResolution9.tsx diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 514ddb8a..ab8c4599 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -465,5 +465,13 @@ module Linguist Language["Scilab"] end end + + disambiguate ".tsx" do |data| + if /^\s*(import.+(from\s+|require\()['"]react|\/\/\/\s* Promise + selectExample: (selectedExample: Example) => any + gettingStartedState: GettingStartedState +} + +interface State { + mouseOver: boolean +} + +class PlaygroundCPopup extends React.Component { + + state = { + mouseOver: false, + } + + refs: { + [key: string]: any + exampleAnchor: HTMLDivElement + congratsAnchor: HTMLDivElement + scroller: HTMLDivElement, + } + + componentDidUpdate(prevProps: Props, prevState: State) { + if (prevProps.gettingStartedState.selectedExample !== this.props.gettingStartedState.selectedExample) { + this.refs.scroller.scrollTop += this.refs.exampleAnchor.getBoundingClientRect().top + } + + if (prevProps.gettingStartedState.isCurrentStep('STEP5_WAITING') + && this.props.gettingStartedState.isCurrentStep('STEP5_DONE')) { + this.refs.scroller.scrollTop += this.refs.congratsAnchor.getBoundingClientRect().top + + const snd = new Audio(require('../../../assets/success.mp3') as string) + snd.volume = 0.5 + snd.play() + } + } + + render() { + const {mouseOver} = this.state + const {selectedExample} = this.props.gettingStartedState + const hovering = !this.props.gettingStartedState.isCurrentStep('STEP4_CLICK_TEASER_STEP5') + const downloadUrl = (example) => `${__BACKEND_ADDR__}/resources/getting-started-example?repository=${examples[example].path}&project_id=${this.props.projectId}&user=graphcool-examples` // tslint:disable-line + return ( +
+
+
this.setState({ mouseOver: false })} + onMouseEnter={() => { + this.setState({ mouseOver: true }) + }} + onMouseOver={(e: any) => { + if (this.props.gettingStartedState.isCurrentStep('STEP4_CLICK_TEASER_STEP5')) { + this.props.nextStep() + } + }} + > +
+
+ You did it! Time to run an example. +
+
+ You have successfully set up your own Instagram backend.{' '} + When building an app with Graphcool you can easily explore queries in the{' '} + playground and "copy & paste" selected queries into your code.{' '} + Of course, to do so, you need to implement the frontend first. +
+
+
We put together a simple app to show and add posts
+
using the backend you just built, to test and run it locally.
+
+
+
+
+ Select your preferred technology to download the example. +
+
+
this.props.selectExample('ReactRelay')} + > + React + Relay +
+
this.props.selectExample('ReactApollo')} + > + React + Apollo +
+
this.props.selectExample('ReactNativeApollo')} + > + React Native + Apollo +
+
this.props.selectExample('AngularApollo')} + > + Angular + Apollo +
+
+
+ {selectedExample && +
+
+