From 6aec64273427c322cebe5795dc7da49fd378c71f Mon Sep 17 00:00:00 2001 From: Adam Sandle <18138428+adamsandle@users.noreply.github.com> Date: Wed, 10 Oct 2018 20:17:58 +0100 Subject: [PATCH] Add basic text based rule --- src/App.js | 2 +- src/results.js | 7 +++++-- src/rules.js | 12 +++++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/App.js b/src/App.js index 04fb158..1543177 100644 --- a/src/App.js +++ b/src/App.js @@ -41,7 +41,7 @@ class App extends Component { } {showAnswer &&
- {getResult()} + {getResult(this.input.value)} {this.back = back;}} value="Back"/>
} diff --git a/src/results.js b/src/results.js index f533f09..fb74fcc 100644 --- a/src/results.js +++ b/src/results.js @@ -1,9 +1,12 @@ import React from 'react'; import * as Rules from "./rules"; -export default function() { +export default function(value) { if (Rules.Mac.getResult()) { - return

Get a PC

+ return

Get a PC

; + } else if (Rules.Contribute.getResult(value)) { + window.location.href = "https://github.com/hoily/how-do-i"; + return

Github

; } else { return

Don't

} diff --git a/src/rules.js b/src/rules.js index 6806d13..a860ec8 100644 --- a/src/rules.js +++ b/src/rules.js @@ -7,15 +7,21 @@ const Rule = class Rule { if(options.os != null) { this.os = options.os } + if (options.text != null) { + this.text = options.text; + } } - getResult() { - if (this.os != null) { + getResult(input) { + if (this.text != null) { + return input.toLowerCase() === this.text.toLowerCase(); + } else if (this.os != null) { return useragent.getOS().name === this.os; } else { return false } } -} +}; export const Mac = new Rule({os: "Mac OS"}); +export const Contribute = new Rule({ text: "contribute" });