Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

some refactoring

goenning0f6a1fcd6746
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 793f61a5d..268d6039a 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -21,6 +21,11 @@
".cover": true,
"cover.out": true
},
+ "search.exclude": {
+ "**/node_modules": true,
+ "**/bower_components": true,
+ "vendor": true
+ },
"vsicons.presets.angular": true,
"go.coverageOptions": "showBothCoveredAndUncoveredCode",
"go.coverOnSave": true,
diff --git a/public/admin/HomePage.tsx b/public/admin/HomePage.tsx
new file mode 100644
index 000000000..4d097f8ba
--- /dev/null
+++ b/public/admin/HomePage.tsx
@@ -0,0 +1,22 @@
+import * as React from "react";
+
+import { Footer } from "../shared/Footer";
+import { Header } from "../shared/Header";
+
+export class HomePage extends React.Component<{}, {}> {
+
+ constructor(props: {}) {
+ super(props);
+ }
+
+ public render() {
+ return <div>
+ <Header />
+ <div className="ui container">
+ <h1 className="ui header">Administration</h1>
+ <span>You're a Member or Admin!</span>
+ </div>
+ <Footer />
+ </div>;
+ }
+}
diff --git a/public/css/main.css b/public/css/main.css
index afa3f5ad1..a6f48c1e1 100644
--- a/public/css/main.css
+++ b/public/css/main.css
@@ -36,4 +36,8 @@
#menu {
margin-top: 0px;
+}
+
+.fdr-profile-popup div.item {
+ padding: 10px 5px !important;
}
\ No newline at end of file
diff --git a/public/index.tsx b/public/index.tsx
index a67b6ee1f..dbf5991a1 100644
--- a/public/index.tsx
+++ b/public/index.tsx
@@ -1,15 +1,17 @@
import * as React from "react";
import * as ReactDOM from "react-dom";
-import { Root } from "./components/Root";
-import { ShowIdeaRoot } from "./components/ShowIdeaRoot";
+import { HomePage as AdminHomePage } from "./admin/HomePage";
+import { HomePage as SiteHomePage } from "./site/HomePage";
+import { ShowIdeaPage } from "./site/ShowIdeaPage";
import { setup } from "./storage";
import "./css/main.css";
const pathRegex = [
- { regex: new RegExp("^\/$"), component: <Root /> },
- { regex: new RegExp("^\/ideas\/\\d+$"), component: <ShowIdeaRoot /> },
+ { regex: new RegExp("^\/$"), component: <SiteHomePage /> },
+ { regex: new RegExp("^\/admin$"), component: <AdminHomePage /> },
+ { regex: new RegExp("^\/ideas\/\\d+$"), component: <ShowIdeaPage /> },
];
const resolveRootComponent = (path: string): JSX.Element => {
diff --git a/public/models.ts b/public/models.ts
index efd006b39..5fa9aa2c5 100644
--- a/public/models.ts
+++ b/public/models.ts
@@ -9,6 +9,7 @@ export interface User {
name: string;
email: string;
supportedIdeas: number[];
+ role: number;
}
export interface Idea {
diff --git a/public/components/CommentInput.tsx b/public/shared/CommentInput.tsx
similarity index 100%
rename from public/components/CommentInput.tsx
rename to public/shared/CommentInput.tsx
diff --git a/public/components/Common.tsx b/public/shared/Common.tsx
similarity index 100%
rename from public/components/Common.tsx
rename to public/shared/Common.tsx
diff --git a/public/components/Footer.tsx b/public/shared/Footer.tsx
similarity index 79%
rename from public/components/Footer.tsx
rename to public/shared/Footer.tsx
index 248ce5612..be3c542c3 100644
--- a/public/components/Footer.tsx
+++ b/public/shared/Footer.tsx
@@ -31,12 +31,12 @@ import * as React from "react";
export class Footer extends React.Component<{}, {}> {
public render() {
- return <div id="footer" className="ui inverted vertical footer segment">
+ return <div id="footer" className="ui 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">
- <span>Powered by</span>
- <a className="item" target="_blank" href="http://getfider.com/">Fider</a>
+ <div className="ui horizontal small divided link list">
+ <span>Powered by </span>
+ <b><a className="item" target="_blank" href="http://getfider.com/">Fider</a></b>
</div>
</div>
</div>;
diff --git a/public/components/Header.tsx b/public/shared/Header.tsx
similarity index 51%
rename from public/components/Header.tsx
rename to public/shared/Header.tsx
index d18d13a63..98f4c80ef 100644
--- a/public/components/Header.tsx
+++ b/public/shared/Header.tsx
@@ -1,5 +1,5 @@
import * as React from "react";
-import { Tenant } from "../models";
+import { User, Tenant } from "../models";
import { get, getCurrentUser } from "../storage";
import { EnvironmentInfo, Gravatar } from "./Common";
import { SocialSignInList } from "./SocialSignInList";
@@ -7,6 +7,15 @@ import { SocialSignInList } from "./SocialSignInList";
export class Header extends React.Component<{}, {}> {
private dropdown: HTMLElement;
private list: HTMLElement;
+ private user: User;
+ private tenant: Tenant;
+
+ constructor(props: {}) {
+ super(props);
+
+ this.user = getCurrentUser();
+ this.tenant = get<Tenant>("tenant");
+ }
public componentDidMount() {
$(this.dropdown).popup({
@@ -18,39 +27,47 @@ export class Header extends React.Component<{}, {}> {
}
public render() {
- const user = getCurrentUser();
- const tenant = get<Tenant>("tenant");
- const env = get<string>("env");
-
- const items = user ? <div className="ui list">
+ const items = this.user ?
+ <div className="ui divided list">
+ <div className="item">
+ <b>{ this.user.email }</b>
+ </div>
+ { this.isMember() &&
<div className="item">
- { user.email }
- </div>
- <div className="item right">
- <a href="/logout?redirect=/">
- Sign out
+ <a href="/admin">
+ Administration
</a>
</div>
- </div> :
- <SocialSignInList orientation="vertical" size="normal" />;
+ }
+ <div className="item">
+ <a href="/logout?redirect=/">
+ Sign out
+ </a>
+ </div>
+ </div> :
+ <SocialSignInList orientation="vertical" size="normal" />;
return <div>
<EnvironmentInfo />
<div id="menu" className="ui menu no-border">
<div className="ui container">
<a href="/" className="header item">
- { tenant.name }
+ { this.tenant.name }
</a>
<a ref={(e) => { this.dropdown = e; } } className="item right signin">
- <Gravatar email={user.email} />
- { user.name || "Sign in" }
+ <Gravatar email={this.user.email} />
+ { this.user.name || "Sign in" }
<i className="dropdown icon"></i>
</a>
</div>
</div>
- <div ref={(e) => { this.list = e; } } className="ui popup transition hidden">
+ <div ref={(e) => { this.list = e; } } className="fdr-profile-popup ui popup transition hidden">
{ items }
</div>
</div>;
}
+
+ private isMember() {
+ return this.user.role >= 2;
+ }
}
diff --git a/public/components/SocialSignInButton.tsx b/public/shared/SocialSignInButton.tsx
similarity index 100%
rename from public/components/SocialSignInButton.tsx
rename to public/shared/SocialSignInButton.tsx
diff --git a/public/components/SocialSignInList.tsx b/public/shared/SocialSignInList.tsx
similarity index 100%
rename from public/components/SocialSignInList.tsx
rename to public/shared/SocialSignInList.tsx
diff --git a/public/components/SupportCounter.tsx b/public/shared/SupportCounter.tsx
similarity index 100%
rename from public/components/SupportCounter.tsx
rename to public/shared/SupportCounter.tsx
diff --git a/public/components/Root.tsx b/public/site/HomePage.tsx
similarity index 71%
rename from public/components/Root.tsx
rename to public/site/HomePage.tsx
index e514dcc07..b3b222c77 100644
--- a/public/components/Root.tsx
+++ b/public/site/HomePage.tsx
@@ -1,22 +1,28 @@
import * as moment from "moment";
import * as React from "react";
-import { Idea } from "../models";
+import { Idea, User } from "../models";
import * as storage from "../storage";
-import { Gravatar, MultiLineText } from "./Common";
-import { SupportCounter } from "./SupportCounter";
+import { Gravatar, MultiLineText } from "../shared/Common";
+import { SupportCounter } from "../shared/SupportCounter";
-import { Footer } from "./Footer";
-import { Header } from "./Header";
+import { Footer } from "../shared/Footer";
+import { Header } from "../shared/Header";
import { IdeaInput } from "./IdeaInput";
-export class Root extends React.Component<{}, {}> {
- public render() {
- const user = storage.getCurrentUser();
- const ideas = storage.get<Idea[]>("ideas") || [];
+export class HomePage extends React.Component<{}, {}> {
+ private user: User;
+ private ideas: Idea[];
+
+ constructor(props: {}) {
+ super(props);
+ this.user = storage.getCurrentUser();
+ this.ideas = storage.get<Idea[]>("ideas") || [];
+ }
- const ideasList = ideas.map((x) =>
+ public render() {
+ const ideasList = this.ideas.map((x) =>
<div className="item" key={x.id}>
- <SupportCounter user={user} idea={x} />
+ <SupportCounter user={this.user} idea={x} />
<div className="content">
<a href={`/ideas/${x.number}`} className="header">
<i className="idea icon"></i> { x.title }
@@ -31,7 +37,7 @@ export class Root extends React.Component<{}, {}> {
</div>
</div>);
- const displayIdeas = (ideas.length > 0) ? <div>
+ const displayIdeas = (this.ideas.length > 0) ? <div>
<h3>Top Ideas</h3>
<div className="ui divided unstackable items">
{ ideasList }
diff --git a/public/components/IdeaInput.tsx b/public/site/IdeaInput.tsx
similarity index 95%
rename from public/components/IdeaInput.tsx
rename to public/site/IdeaInput.tsx
index 529a4150e..93ff35d65 100644
--- a/public/components/IdeaInput.tsx
+++ b/public/site/IdeaInput.tsx
@@ -1,8 +1,8 @@
import axios from "axios";
import * as React from "react";
import { getCurrentUser } from "../storage";
-import { DisplayError } from "./Common";
-import { SocialSignInList } from "./SocialSignInList";
+import { DisplayError } from "../shared/Common";
+import { SocialSignInList } from "../shared/SocialSignInList";
interface IdeaInputState {
title: string;
diff --git a/public/components/ShowIdeaRoot.tsx b/public/site/ShowIdeaPage.tsx
similarity index 51%
rename from public/components/ShowIdeaRoot.tsx
rename to public/site/ShowIdeaPage.tsx
index 4c2d0179d..5d6529681 100644
--- a/public/components/ShowIdeaRoot.tsx
+++ b/public/site/ShowIdeaPage.tsx
@@ -2,23 +2,32 @@ import * as moment from "moment";
import * as React from "react";
import * as storage from "../storage";
-import { Comment, Idea } from "../models";
-import { CommentInput } from "./CommentInput";
-import { Gravatar, MultiLineText } from "./Common";
-import { SocialSignInButton } from "./SocialSignInButton";
-import { SupportCounter } from "./SupportCounter";
+import { User, Comment, Idea } from "../models";
+import { CommentInput } from "../shared/CommentInput";
+import { Gravatar, MultiLineText } from "../shared/Common";
+import { SocialSignInButton } from "../shared/SocialSignInButton";
+import { SupportCounter } from "../shared/SupportCounter";
-import { Footer } from "./Footer";
-import { Header } from "./Header";
+import { Footer } from "../shared/Footer";
+import { Header } from "../shared/Header";
import { IdeaInput } from "./IdeaInput";
-export class ShowIdeaRoot extends React.Component<{}, {}> {
+export class ShowIdeaPage extends React.Component<{}, {}> {
+ private user: User;
+ private idea: Idea;
+ private comments: Comment[];
+
+ constructor(props: {}) {
+ super(props);
+
+ this.user = storage.getCurrentUser();
+ this.idea = storage.get<Idea>("idea");
+ this.comments = storage.get<Comment[]>("comments") || [];
+ }
+
public render() {
- const user = storage.getCurrentUser();
- const idea = storage.get<Idea>("idea");
- const comments = storage.get<Comment[]>("comments") || [];
- const commentsList = comments.length ? comments.map((c) =>
+ const commentsList = this.comments.length ? this.comments.map((c) =>
<div className="comment">
<a className="avatar">
<Gravatar email={c.user.email} />
@@ -41,27 +50,27 @@ export class ShowIdeaRoot extends React.Component<{}, {}> {
<div className="ui items unstackable">
<div className="item">
- <SupportCounter user={user} idea={idea} />
+ <SupportCounter user={this.user} idea={this.idea} />
<div className="idea-header">
- <h1 className="ui header">{ idea.title }</h1>
+ <h1 className="ui header">{ this.idea.title }</h1>
<p>
- #{ idea.number } shared by &nbsp;
- <Gravatar email={idea.user.email}/> <u>{idea.user.name}</u> &nbsp;
- <span title={idea.createdOn}>{ moment(idea.createdOn).fromNow() }</span>
+ #{ this.idea.number } shared by &nbsp;
+ <Gravatar email={this.idea.user.email}/> <u>{this.idea.user.name}</u> &nbsp;
+ <span title={this.idea.createdOn}>{ moment(this.idea.createdOn).fromNow() }</span>
</p>
</div>
</div>
</div>
- <p>{ idea.description }</p>
+ <p>{ this.idea.description }</p>
<div className="ui comments">
<h3 className="ui dividing header">Comments</h3>
{ commentsList }
</div>
- <CommentInput idea={idea} />
+ <CommentInput idea={this.idea} />
</div>
<Footer />
</div>;
diff --git a/router.go b/router.go
index 3479eadf1..501df2c9d 100644
--- a/router.go
+++ b/router.go
@@ -1,14 +1,13 @@
package main
import (
- "net/http"
-
"github.com/getfider/fider/app/handlers"
"github.com/getfider/fider/app/middlewares"
"github.com/getfider/fider/app/models"
"github.com/getfider/fider/app/pkg/oauth"
"github.com/getfider/fider/app/pkg/web"
"github.com/getfider/fider/app/storage"
+ "github.com/labstack/echo"
)
// AppServices holds reference to all Fider services
@@ -75,7 +74,7 @@ func GetMainEngine(ctx *AppServices) *web.Engine {
admin.Use(middlewares.IsAuthorized(models.RoleMember, models.RoleAdministrator))
admin.Get("", func(ctx web.Context) error {
- return ctx.HTML(http.StatusOK, "Welcome to Admin Page :)")
+ return ctx.Page(echo.Map{})
})
}
diff --git a/tslint.json b/tslint.json
index 76e030902..afbe55058 100644
--- a/tslint.json
+++ b/tslint.json
@@ -7,6 +7,9 @@
],
"interface-name": [
false
+ ],
+ "ordered-imports": [
+ false
]
}
}
\ No newline at end of file