Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

reactify all the things!

Oenningf46a750f66b8
diff --git a/app/renderer.go b/app/renderer.go
index dbb50f3bc..88a043467 100644
--- a/app/renderer.go
+++ b/app/renderer.go
@@ -64,11 +64,6 @@ func (r *HTMLRenderer) Render(w io.Writer, name string, data interface{}, c echo
tmpl = r.add(name)
}
- protocol := "http://"
- if c.Request().TLS != nil {
- protocol = "https://"
- }
-
//TODO: refactor (and move somewhere else?)
m := data.(echo.Map)
claims, ok := c.Get("Claims").(*identity.WechyClaims)
@@ -78,7 +73,6 @@ func (r *HTMLRenderer) Render(w io.Writer, name string, data interface{}, c echo
m["Claims"] = claims
m["Gravatar"] = toMDF5(claims.UserEmail)
}
- m["CurrentUrl"] = protocol + c.Request().Host + c.Request().URL.String()
files, _ := ioutil.ReadDir("dist/js")
if len(files) > 0 {
diff --git a/app/router.go b/app/router.go
index be8a688b7..edb3f1ce4 100644
--- a/app/router.go
+++ b/app/router.go
@@ -29,6 +29,8 @@ type WechyServices struct {
}
func errorHandler(e error, c echo.Context) {
+ c.Logger().Debug(e)
+
if strings.Contains(e.Error(), "code=404") {
c.Render(http.StatusNotFound, "404.html", echo.Map{})
} else {
diff --git a/public/components/Footer.tsx b/public/components/Footer.tsx
new file mode 100644
index 000000000..68375a949
--- /dev/null
+++ b/public/components/Footer.tsx
@@ -0,0 +1,43 @@
+import * as React from "react";
+
+/*
+<!--
+<div class="ui stackable inverted divided grid">
+<div class="six wide column">
+ <h4 class="ui inverted header">Trending ideas</h4>
+ <div class="ui inverted link list">
+ <a href="#" class="item">Link #1</a>
+ <a href="#" class="item">Link #2</a>
+ <a href="#" class="item">Link #3</a>
+ <a href="#" class="item">Link $3</a>
+ </div>
+</div>
+<div class="six wide column">
+ <h4 class="ui inverted header">Latest activity</h4>
+ <div class="ui inverted link list">
+ <a href="#" class="item">Someone did something</a>
+ <a href="#" class="item">New idea was posted</a>
+ <a href="#" class="item">Someone commented on idea #1</a>
+ <a href="#" class="item">Idea #2 changed to Shipped</a>
+ </div>
+</div>
+<div class="four wide column">
+ <h4 class="ui inverted header">Footer Header</h4>
+ <p>Extra space for a call to action inside the footer that could help re-engage users.</p>
+</div>
+</div>
+-->
+*/
+
+export class Footer extends React.Component<{}, {}> {
+ render() {
+ return <div id="footer" className="ui inverted vertical footer segment">
+ <div className="ui center aligned container">
+ <div className="ui inverted section divider"></div>
+ <div className="ui horizontal inverted small divided link list">
+ Powered by <a className="item" target="_blank" href="http://we.canhearyou.com/">WeCanHearYou</a>
+ </div>
+ </div>
+ </div>;
+ }
+}
\ No newline at end of file
diff --git a/public/components/Header.tsx b/public/components/Header.tsx
new file mode 100644
index 000000000..1c6bb9db0
--- /dev/null
+++ b/public/components/Header.tsx
@@ -0,0 +1,62 @@
+import * as React from "react";
+import { SocialSignInButton } from "./SocialSignInButton";
+
+const tenant = (window as any)._tenant;
+const claims = (window as any)._claims;
+const gravatar = (window as any)._gravatar;
+
+/*
+ {{if not .Claims }}
+ {{ else }}
+
+ {{ end }}
+*/
+
+export class Header extends React.Component<{}, {}> {
+ render() {
+ const profile = claims ?
+ <a className="item right signin">
+ <img className="ui avatar image" src={ "https://www.gravatar.com/avatar/" + gravatar } />
+ { claims["user/name"] }
+ <i className="dropdown icon"></i>
+ </a> :
+ <a className="item right signin">
+ <img className="ui avatar image" src="https://www.gravatar.com/avatar/" />
+ Sign in
+ <i className="dropdown icon"></i>
+ </a>;
+
+ const dropdown = claims ?
+ <div id="user-popup" className="ui popup top left transition hidden">
+ <div className="ui">
+ <div className="item">
+ <a href="/logout?redirect=/">
+ Sign out
+ </a>
+ </div>
+ </div>
+ </div> :
+ <div id="user-popup" className="ui popup top left transition hidden">
+ <div className="ui list">
+ <div className="item">
+ <SocialSignInButton provider="facebook"/>
+ </div>
+ <div className="item">
+ <SocialSignInButton provider="google"/>
+ </div>
+ </div>
+ </div>;
+
+ return <div>
+ <div className="ui menu">
+ <div className="ui container">
+ <div className="header item">
+ { tenant.name }
+ </div>
+ { profile }
+ </div>
+ </div>
+ { dropdown }
+ </div>;
+ }
+}
\ No newline at end of file
diff --git a/public/components/IdeaInput.tsx b/public/components/IdeaInput.tsx
index 025bf83e8..77f68337d 100644
--- a/public/components/IdeaInput.tsx
+++ b/public/components/IdeaInput.tsx
@@ -1,9 +1,49 @@
import * as React from "react";
+import { SocialSignInButton } from "./SocialSignInButton";
+
+const claims = (window as any)._claims;
+
+interface IdeaInputState {
+ idea: string;
+}
+
+export class IdeaInput extends React.Component<{}, IdeaInputState> {
+
+ constructor() {
+ super();
+ this.state = { idea: "" };
+ }
-export class IdeaInput extends React.Component<{}, {}> {
render() {
- return <div className="ui fluid input">
- <input id="new-idea-input" type="text" placeholder="Enter your idea, new feature or suggestion here ..." />
+ const details = claims ?
+ <button className="ui positive button">
+ Submit Idea
+ </button> :
+ <div>
+ <p>Please log in before posting an idea...</p>
+ <div className="ui list">
+ <div className="item">
+ <SocialSignInButton provider="facebook"/>
+ </div>
+ <div className="item">
+ <SocialSignInButton provider="google"/>
+ </div>
+ </div>
+ </div>;
+
+ return <div>
+ <div className="ui fluid input">
+ <input id="new-idea-input"
+ type="text"
+ onKeyUp={(e) => {this.setState({ idea: e.currentTarget.value }); }}
+ placeholder="Enter your idea, new feature or suggestion here ..." />
+ </div>
+
+ <div id="new-idea-submit" className="ui grid">
+ <div className="four wide column">
+ { this.state.idea.length > 0 ? details : <div /> }
+ </div>
+ </div>
</div>;
}
}
\ No newline at end of file
diff --git a/public/components/Root.tsx b/public/components/Root.tsx
index ac5a78f45..d8da4424e 100644
--- a/public/components/Root.tsx
+++ b/public/components/Root.tsx
@@ -1,27 +1,13 @@
import * as React from "react";
-import {IdeaInput} from "./IdeaInput";
-import {SocialSignInButton} from "./SocialSignInButton";
+import { IdeaInput } from "./IdeaInput";
+import { Header } from "./Header";
+import { Footer } from "./Footer";
const claims = (window as any)._claims;
const ideas:any[] = (window as any)._ideas || [];
export class Root extends React.Component<{}, {}> {
render() {
- const details = claims ?
- <button className="ui positive button">
- Submit Idea
- </button> :
- <div>
- <p>Please log in before posting an idea...</p>
- <div className="ui list">
- <div className="item">
- <SocialSignInButton provider="facebook"/>
- </div>
- <div className="item">
- <SocialSignInButton provider="google"/>
- </div>
- </div>
- </div>
const ideasList = ideas.map(x =>
<div className="item" key={x.id}>
@@ -48,25 +34,20 @@ export class Root extends React.Component<{}, {}> {
</div>
: <p>No ideas have been shared yet.</p>
- return <div className="ui container">
- <div className="ui container">
- <h1 className="ui header">Welcome to our feedback forum!</h1>
- </div>
+ return <div>
+ <Header />
+ <div className="ui container">
+ <h1 className="ui header">Welcome to our feedback forum!</h1>
- <div className="ui container">
- <h3>I want ...</h3>
- </div>
- <IdeaInput />
+ <h3>I want ...</h3>
- <div id="new-idea-submit" className="ui grid">
- <div className="four wide column">
- { details }
- </div>
- </div>
+ <IdeaInput />
- <div className="ui container ideas-list">
- { displayIdeas }
- </div>
+ <div className="ui container ideas-list">
+ { displayIdeas }
+ </div>
+ </div>
+ <Footer />
</div>;
}
}
\ No newline at end of file
diff --git a/public/components/SocialSignInButton.tsx b/public/components/SocialSignInButton.tsx
index 75ef96fe1..a8fcd465a 100644
--- a/public/components/SocialSignInButton.tsx
+++ b/public/components/SocialSignInButton.tsx
@@ -3,15 +3,27 @@ import * as React from "react";
const authEndpoint = (window as any)._authEndpoint;
interface SocialSignInButtonProps {
- provider: string
+ provider: string;
}
+interface SocialSignInButtonState {
+ clicked: boolean;
+}
+
+export class SocialSignInButton extends React.Component<SocialSignInButtonProps, SocialSignInButtonState> {
+ constructor() {
+ super();
+ this.state = {
+ clicked: false
+ };
+ }
-export class SocialSignInButton extends React.Component<SocialSignInButtonProps, {}> {
render() {
const providerClassName = this.props.provider == "google" ? "google plus" : "facebook";
const providerDisplayName = this.props.provider == "google" ? "Google" : "Facebook";
-
- return <a href={ authEndpoint + "/oauth/" + this.props.provider + "?redirect=" + location.href } className={providerClassName + " ui fluid button"}>
+ const oauthUrl = `${authEndpoint}/oauth/${this.props.provider}?redirect=${location.href}`;
+ const cssClasses = `${providerClassName} ui fluid button ${this.state.clicked ? "loading" : ""}`;
+
+ return <a href={oauthUrl} className={cssClasses} onClick={() => this.setState({clicked: true})}>
<i className={providerClassName + " icon"}></i>
Sign in with { providerDisplayName }
</a>;
diff --git a/public/index.ts b/public/index.ts
index 4d77cdbc6..ea30c5475 100644
--- a/public/index.ts
+++ b/public/index.ts
@@ -12,30 +12,13 @@ $(document).ready(() => {
$(".ui.dropdown").dropdown();
- $('.menu .signin').popup({
+ $(".menu .signin").popup({
inline: true,
hoverable: true,
- popup: '#user-popup',
- position : 'bottom right',
+ popup: "#user-popup",
+ position : "bottom right",
delay: {
- show: 300
- }
- });
-
- $('#user-popup a').click(function() {
- $(this).addClass("loading");
- });
-
- var input = <HTMLInputElement>document.querySelector("#new-idea-input");
- var submit = <HTMLElement>document.querySelector("#new-idea-submit");
-
- submit.style.display = 'none';
-
- input.addEventListener("keyup", function() {
- if (this.value) {
- submit.style.display = 'block';
- } else {
- submit.style.display = 'none';
+ show: 300
}
});
});
diff --git a/public/init.tsx b/public/init.tsx
index 37e821f41..555244446 100644
--- a/public/init.tsx
+++ b/public/init.tsx
@@ -1,3 +1,4 @@
+// tslint:disable-next-line:no-unused-variable
import * as React from "react";
import * as ReactDOM from "react-dom";
@@ -5,7 +6,7 @@ import { Root } from "./components/Root";
export default function init() {
ReactDOM.render(
- <Root />,
+ location.pathname === "/" ? <Root /> : <div />,
document.getElementById("root")
);
}
\ No newline at end of file
diff --git a/views/404.html b/views/404.html
index 15a467f9f..6046fffe3 100644
--- a/views/404.html
+++ b/views/404.html
@@ -2,6 +2,8 @@
404: Page not found
{{end}}
+{{define "javascript"}}{{end}}
+
{{define "content"}}
<h1>404: Page not found</h1>
{{end}}
diff --git a/views/500.html b/views/500.html
index 586857bbd..1829a8901 100644
--- a/views/500.html
+++ b/views/500.html
@@ -2,6 +2,8 @@
404: Page not found
{{end}}
+{{define "javascript"}}{{end}}
+
{{define "content"}}
<h1>500: Oops, something unexpected happened... :(</h1>
{{end}}
diff --git a/views/base.html b/views/base.html
index aac3fa61b..f1bab1031 100644
--- a/views/base.html
+++ b/views/base.html
@@ -9,98 +9,15 @@
<body>
<script type="text/javascript">
var _authEndpoint = {{ .AuthEndpoint }};
+ var _tenant = {{ .Tenant }};
var _claims = {{ .Claims }};
+ var _gravatar = {{ .Gravatar }}
{{template "javascript" .}}
</script>
- <div class="ui menu">
- <div class="ui container">
- <div class="header item">
- {{ .Tenant.Name }}
- </div>
- {{if not .Claims }}
- <a class="item right signin">
- <img class="ui avatar image" src="https://www.gravatar.com/avatar/">
- Sign in {{ .Claims }}
- <i class="dropdown icon"></i>
- </a>
- {{ else }}
- <a class="item right signin">
- <img class="ui avatar image" src="https://www.gravatar.com/avatar/{{ .Gravatar }}">
- {{ .Claims.UserName }}
- <i class="dropdown icon"></i>
- </a>
- {{ end }}
- </div>
- </div>
-
- {{if not .Claims }}
- <div id="user-popup" class="ui popup top left transition hidden">
- <div class="ui list">
- <div class="item">
- <a href="{{ .AuthEndpoint }}/oauth/facebook?redirect={{ .CurrentUrl }}" class="ui fluid facebook button">
- <i class="facebook icon"></i>
- Sign in with Facebook
- </a>
- </div>
- <div class="item">
- <a href="{{ .AuthEndpoint }}/oauth/google?redirect={{ .CurrentUrl }}" class="ui fluid google plus button">
- <i class="google icon"></i>
- Sign in with Google
- </a>
- </div>
- </div>
- </div>
- {{ else }}
- <div id="user-popup" class="ui popup top left transition hidden">
- <div class="ui">
- <div class="item">
- <a href="/logout?redirect=/">
- Sign out
- </a>
- </div>
- </div>
- </div>
- {{ end }}
-
<div id="root"></div>
+ {{template "content" .}}
- <div id="footer" class="ui inverted vertical footer segment">
- <div class="ui center aligned container">
-
- <!--
- <div class="ui stackable inverted divided grid">
- <div class="six wide column">
- <h4 class="ui inverted header">Trending ideas</h4>
- <div class="ui inverted link list">
- <a href="#" class="item">Link #1</a>
- <a href="#" class="item">Link #2</a>
- <a href="#" class="item">Link #3</a>
- <a href="#" class="item">Link $3</a>
- </div>
- </div>
- <div class="six wide column">
- <h4 class="ui inverted header">Latest activity</h4>
- <div class="ui inverted link list">
- <a href="#" class="item">Someone did something</a>
- <a href="#" class="item">New idea was posted</a>
- <a href="#" class="item">Someone commented on idea #1</a>
- <a href="#" class="item">Idea #2 changed to Shipped</a>
- </div>
- </div>
- <div class="four wide column">
- <h4 class="ui inverted header">Footer Header</h4>
- <p>Extra space for a call to action inside the footer that could help re-engage users.</p>
- </div>
- </div>
- -->
-
- <div class="ui inverted section divider"></div>
- <div class="ui horizontal inverted small divided link list">
- Powered by <a class="item" target="_blank" href="http://we.canhearyou.com/">WeCanHearYou</a>
- </div>
- </div>
- </div>
<script type="text/javascript" src="/assets/js/{{ .JavaScriptBundle }}"></script>
</body>
</html>
diff --git a/views/index.html b/views/index.html
index 88131b449..4dd447ee9 100644
--- a/views/index.html
+++ b/views/index.html
@@ -4,4 +4,6 @@
{{define "javascript"}}
var _ideas = {{ .Ideas }};
-{{end}}
\ No newline at end of file
+{{end}}
+
+{{define "content"}}{{end}}
\ No newline at end of file