Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Sticky Filters and UX changes (#100)

Guilherme Oenning0733198cc723
diff --git a/public/components/CommentInput.tsx b/public/components/CommentInput.tsx
index f46fc325a..9eeab6bbf 100644
--- a/public/components/CommentInput.tsx
+++ b/public/components/CommentInput.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
-import { Idea } from '@fider/models';
-import { Button, DisplayError, SocialSignInList } from '@fider/components/common';
+import { Idea, User } from '@fider/models';
+import { Gravatar, Button, DisplayError, SocialSignInList } from '@fider/components/common';
import { inject, injectables } from '@fider/di';
import { Session, IdeaService, Failure } from '@fider/services';
@@ -23,8 +23,12 @@ export class CommentInput extends React.Component<CommentInputProps, CommentInpu
@inject(injectables.IdeaService)
public service: IdeaService;
+ private user: User;
+
constructor() {
super();
+ this.user = this.session.getCurrentUser();
+
this.state = {
content: ''
};
@@ -60,14 +64,17 @@ export class CommentInput extends React.Component<CommentInputProps, CommentInpu
<SocialSignInList orientation="horizontal" size="small" />
</div>;
- return <div className="ui reply form">
- <DisplayError error={this.state.error} />
- <div className="field">
- <textarea onKeyUp={(e) => { this.setState({ content: e.currentTarget.value }); }}
- rows={3}
- placeholder="Write a comment..."></textarea>
+ return <div>
+ <Gravatar name={this.user.name} hash={this.user.gravatar}/>
+ <div className="ui form comment-input">
+ <DisplayError error={this.state.error} />
+ <div className="field">
+ <textarea onKeyUp={(e) => { this.setState({ content: e.currentTarget.value }); }}
+ rows={3}
+ placeholder="Write a comment..."></textarea>
+ </div>
+ { (this.state.content || user) && button }
</div>
- { (this.state.content || user) && button }
</div>;
}
}
diff --git a/public/components/ShowIdeaResponse.tsx b/public/components/ShowIdeaResponse.tsx
index aeed87cbd..09880dfed 100644
--- a/public/components/ShowIdeaResponse.tsx
+++ b/public/components/ShowIdeaResponse.tsx
@@ -11,12 +11,12 @@ export const ShowIdeaResponse = (props: IdeaResponseProps): JSX.Element => {
const status = IdeaStatus.Get(props.status);
if (props.response && status.show) {
- return <div className="fdr-response item ui raised segment">
- <span className={`ui ribbon label ${status.color}`}>{ status.title }</span>
- <Gravatar name={props.response.user.name} hash={props.response.user.gravatar}/> { props.response.user.name }
- <span className="info">
- <Moment date={props.response.respondedOn} />
- </span>
+ return <div className="fdr-response item ui segment">
+ <span className={`ui label ${status.color}`}>{ status.title }</span>
+ <Gravatar name={props.response.user.name} hash={props.response.user.gravatar}/> { props.response.user.name }
+ <span className="info">
+ <Moment date={props.response.respondedOn} />
+ </span>
<div className="content">
<MultiLineText text={ props.response.text } markdown={true} />
</div>
diff --git a/public/components/common/Gravatar.tsx b/public/components/common/Gravatar.tsx
index 1a9b11518..e8b7af7d9 100644
--- a/public/components/common/Gravatar.tsx
+++ b/public/components/common/Gravatar.tsx
@@ -16,8 +16,8 @@ export const Gravatar = (props: GravatarProps) => {
return (hash && props.name) ?
<img ref={(e) => element = e }
onError={() => { element.src = fallback; }}
- className="ui avatar image"
- title={props.name}
+ className="fdr-avatar"
+ title={ props.name }
src={ `https://www.gravatar.com/avatar/${hash}?d=${encodeURIComponent(fallback)}` }/> :
<div />;
};
diff --git a/public/pages/ShowIdeaPage.tsx b/public/pages/ShowIdeaPage.tsx
index c93030c4b..4aa96bc87 100644
--- a/public/pages/ShowIdeaPage.tsx
+++ b/public/pages/ShowIdeaPage.tsx
@@ -33,9 +33,7 @@ export class ShowIdeaPage extends React.Component<{}, {}> {
const commentsList = this.comments.length ? this.comments.map((c) =>
<div className="comment">
- <a className="avatar">
- <Gravatar name={c.user.name} hash={c.user.gravatar} />
- </a>
+ <Gravatar name={c.user.name} hash={c.user.gravatar} />
<div className="content">
<span className="author">{ c.user.name }</span>
<div className="metadata">
@@ -50,7 +48,7 @@ export class ShowIdeaPage extends React.Component<{}, {}> {
return <div>
<Header />
- <div className="ui container">
+ <div className="page ui container">
<div className="ui items unstackable">
<div className="item">
@@ -81,10 +79,10 @@ export class ShowIdeaPage extends React.Component<{}, {}> {
}
<div className="ui comments">
- <h3 className="ui dividing header">Comments</h3>
+ <h3 className="ui dividing header">Discussion</h3>
{ commentsList }
+ <CommentInput idea={this.idea} />
</div>
- <CommentInput idea={this.idea} />
</div>
<Footer />
</div>;
diff --git a/public/pages/admin/AdminHomePage.tsx b/public/pages/admin/AdminHomePage.tsx
index e1c88fcb8..80f126223 100644
--- a/public/pages/admin/AdminHomePage.tsx
+++ b/public/pages/admin/AdminHomePage.tsx
@@ -45,7 +45,7 @@ export class AdminHomePage extends React.Component<{}, AdminHomePageState> {
public render() {
return <div>
<Header />
- <div className="ui container">
+ <div className="page ui container">
<h1 className="ui header">Administration</h1>
<h4 className="ui header">General Settings</h4>
diff --git a/public/pages/home/IdeaFilter.tsx b/public/pages/home/IdeaFilter.tsx
index fd672c4e0..1d745cfbc 100644
--- a/public/pages/home/IdeaFilter.tsx
+++ b/public/pages/home/IdeaFilter.tsx
@@ -1,10 +1,11 @@
import * as React from 'react';
import { Idea, IdeaStatus } from '@fider/models';
-type IdeaFilterFunction = (ideas: Idea[]) => Idea[];
+export type IdeaFilterFunction = (ideas: Idea[]) => Idea[];
interface IdeaFilterProps {
- filterChanged: (filter: IdeaFilterFunction) => void;
+ activeFilter: string;
+ filterChanged: (name: string, filter: IdeaFilterFunction) => void;
}
const filterers: {[key: string]: (idea: Idea) => boolean} = {
@@ -15,6 +16,14 @@ const filterers: {[key: string]: (idea: Idea) => boolean} = {
'declined': (idea: Idea) => idea.status === IdeaStatus.Declined.value
};
+const names: {[key: string]: string} = {
+ 'recent': 'recent',
+ 'most-wanted': 'most wanted ideas',
+ 'most-discussed': 'most discussed ideas',
+ 'completed': 'completed ideas',
+ 'declined': 'declined ideas'
+};
+
const sorterers: {[key: string]: (left: Idea, right: Idea) => number} = {
'recent': (left: Idea, right: Idea) => new Date(right.createdOn).getTime() - new Date(left.createdOn).getTime(),
'most-wanted': (left: Idea, right: Idea) => right.totalSupporters - left.totalSupporters,
@@ -23,10 +32,6 @@ const sorterers: {[key: string]: (left: Idea, right: Idea) => number} = {
'declined': (left: Idea, right: Idea) => new Date(left.response.respondedOn).getTime() - new Date(left.response.respondedOn).getTime()
};
-const getFilter = (value: string): IdeaFilterFunction => {
- return (ideas: Idea[]) => ideas.filter(filterers[value]).sort(sorterers[value]);
-};
-
export class IdeaFilter extends React.Component<IdeaFilterProps, {}> {
private element: HTMLDivElement;
@@ -34,30 +39,41 @@ export class IdeaFilter extends React.Component<IdeaFilterProps, {}> {
super(props);
}
- public static defaultFilter = getFilter('recent');
+ public static getFilter(value: string): IdeaFilterFunction {
+ if (!filterers[value]) {
+ value = 'recent';
+ }
+
+ return (ideas: Idea[]) => ideas.filter(filterers[value]).sort(sorterers[value]);
+ }
public componentDidMount() {
$(this.element).dropdown({
- onChange: (value: string) => {
- this.props.filterChanged(getFilter(value));
- }
+ onChange: (value: string) => {
+ this.props.filterChanged(value, IdeaFilter.getFilter(value));
+ }
});
}
public render() {
+ let activeFilter = this.props.activeFilter;
+ if (!(this.props.activeFilter in names)) {
+ activeFilter = 'recent';
+ }
+
return <h4 className="ui header">
<div className="content">
Showing {' '}
<div className="ui inline dropdown" ref={(e) => this.element = e!}>
- <div className="text">recent ideas</div>
+ <div className="text">{ names[activeFilter] }</div>
<i className="dropdown icon"></i>
<div className="menu">
<div className="header">What do you want to see?</div>
- <div className="item" data-value="recent" data-text="recent ideas">Recent</div>
- <div className="item" data-value="most-wanted" data-text="most wanted ideas">Most Wanted</div>
- <div className="item" data-value="most-discussed" data-text="most discussed ideas">Most Discussed</div>
- <div className="item" data-value="completed" data-text="completed ideas">Completed</div>
- <div className="item" data-value="declined" data-text="declined ideas">Declined</div>
+ <div className={`item ${activeFilter === 'recent' && 'active'}`} data-value="recent" data-text="recent ideas">Recent</div>
+ <div className={`item ${activeFilter === 'most-wanted' && 'active'}`} data-value="most-wanted" data-text="most wanted ideas">Most Wanted</div>
+ <div className={`item ${activeFilter === 'most-discussed' && 'active'}`} data-value="most-discussed" data-text="most discussed ideas">Most Discussed</div>
+ <div className={`item ${activeFilter === 'completed' && 'active'}`} data-value="completed" data-text="completed ideas">Completed</div>
+ <div className={`item ${activeFilter === 'declined' && 'active'}`} data-value="declined" data-text="declined ideas">Declined</div>
</div>
</div>
</div>
diff --git a/public/pages/home/SiteHomePage.tsx b/public/pages/home/SiteHomePage.tsx
index e8e33d836..dc134d3b8 100644
--- a/public/pages/home/SiteHomePage.tsx
+++ b/public/pages/home/SiteHomePage.tsx
@@ -4,7 +4,7 @@ import { Gravatar, MultiLineText, Moment, Header, Footer } from '@fider/componen
import { ShowIdeaResponse } from '@fider/components/ShowIdeaResponse';
import { SupportCounter } from '@fider/components/SupportCounter';
import { IdeaInput } from './IdeaInput';
-import { IdeaFilter } from './IdeaFilter';
+import { IdeaFilter, IdeaFilterFunction } from './IdeaFilter';
import { inject, injectables } from '@fider/di';
import { Session } from '@fider/services';
@@ -20,6 +20,7 @@ export class SiteHomePage extends React.Component<{}, SiteHomePageState> {
private tenant: Tenant;
private allIdeas: Idea[];
private filter: HTMLDivElement;
+ private activeFilter: string;
@inject(injectables.Session)
public session: Session;
@@ -30,11 +31,19 @@ export class SiteHomePage extends React.Component<{}, SiteHomePageState> {
this.tenant = this.session.getCurrentTenant();
this.allIdeas = this.session.get<Idea[]>('ideas') || [];
+ this.activeFilter = window.location.hash.substring(1);
this.state = {
- ideas: IdeaFilter.defaultFilter(this.allIdeas)
+ ideas: IdeaFilter.getFilter(this.activeFilter)(this.allIdeas)
};
}
+ private filterChanged(name: string, filter: IdeaFilterFunction) {
+ window.location.hash = `#${name}`;
+ this.setState({
+ ideas: filter(this.allIdeas)
+ });
+ }
+
public render() {
const ideasList = this.state.ideas.map((x) =>
<div className="item" key={x.id}>
@@ -67,7 +76,7 @@ We'd love to hear what you're thinking about. This is the place for you to submi
return <div className="SiteHomePage">
<Header />
- <div className="ui container">
+ <div className="page ui container">
<div className="ui grid stackable">
<div className="six wide column">
@@ -82,7 +91,7 @@ We'd love to hear what you're thinking about. This is the place for you to submi
<p>It's lonely out here. Start by sharing an idea!</p>
</div>
: <div>
- <IdeaFilter filterChanged={(filter) => this.setState({ ideas: filter(this.allIdeas) }) } />
+ <IdeaFilter activeFilter={ this.activeFilter } filterChanged={ this.filterChanged.bind(this) } />
{ displayIdeas }
</div>
}
diff --git a/public/pages/signup/SignUpPage.tsx b/public/pages/signup/SignUpPage.tsx
index 49a732ca9..73df17e0a 100644
--- a/public/pages/signup/SignUpPage.tsx
+++ b/public/pages/signup/SignUpPage.tsx
@@ -92,7 +92,7 @@ export class SignUpPage extends React.Component<{}, SignUpPageState> {
public render() {
return <div>
<EnvironmentInfo />
- <div id="fdr-signup-page" className="ui container">
+ <div id="fdr-signup-page" className="page ui container">
<img className="logo" src={logo} />
<h3 className="ui header">1. Who are you?</h3>
diff --git a/public/styles/main.scss b/public/styles/main.scss
index 141d287c0..b91f0858e 100644
--- a/public/styles/main.scss
+++ b/public/styles/main.scss
@@ -47,8 +47,24 @@ code {
}
}
-.avatar {
- border-radius: 500rem !important;
+.fdr-avatar,
+.ui.menu .item>img:not(.ui) {
+ border-radius: .25rem;
+ width: 2em;
+ display: inline-block;
+ margin-right: 0.5em;
+ vertical-align: top;
+}
+
+.comment-input {
+ display: inline-block;
+ min-width: 500px;
+}
+
+.ui.comments {
+ .comment>.content {
+ display: inline-block;
+ }
}
.no-border {
@@ -93,6 +109,15 @@ code {
margin-top: 10px;
}
+ .label {
+ line-height: 28px;
+ padding: 0px 1em;
+ }
+
+ .fdr-avatar {
+ margin-left: 0.5em;
+ }
+
.info {
display: inline !important;
position: relative;
@@ -113,8 +138,6 @@ code {
}
#footer {
- margin-top: 50px;
-
#powered-by {
text-align: center;