Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Replace all textarea with AutoResizableTextArea (#119)

Guilherme Oenninge37813ffd328
diff --git a/app/handlers/oauth.go b/app/handlers/oauth.go
index 347e81259..f50a4b356 100644
--- a/app/handlers/oauth.go
+++ b/app/handlers/oauth.go
@@ -4,7 +4,6 @@ import (
"net/http"
"net/url"
"strings"
- "time"
jwtgo "github.com/dgrijalva/jwt-go"
@@ -135,11 +134,7 @@ func Login(provider string) web.HandlerFunc {
// Logout remove auth cookies
func Logout() web.HandlerFunc {
return func(c web.Context) error {
- c.SetCookie(&http.Cookie{
- Name: "auth",
- MaxAge: -1,
- Expires: time.Now().Add(-100 * time.Hour),
- })
+ c.RemoveCookie("auth")
return c.Redirect(http.StatusTemporaryRedirect, c.QueryParam("redirect"))
}
}
diff --git a/app/middlewares/jwt.go b/app/middlewares/jwt.go
index 11b192ae6..80557beae 100644
--- a/app/middlewares/jwt.go
+++ b/app/middlewares/jwt.go
@@ -5,6 +5,7 @@ import (
"strings"
"time"
+ "github.com/getfider/fider/app"
"github.com/getfider/fider/app/pkg/jwt"
"github.com/getfider/fider/app/pkg/web"
)
@@ -28,8 +29,13 @@ func JwtGetter() web.MiddlewareFunc {
}
services := c.Services()
+ c.Logger().Info(claims)
user, err := services.Users.GetByID(claims.UserID)
if err != nil {
+ if err == app.ErrNotFound {
+ c.RemoveCookie("auth")
+ return next(c)
+ }
return err
}
diff --git a/app/pkg/web/context.go b/app/pkg/web/context.go
index 557d88a4a..9585c40d4 100644
--- a/app/pkg/web/context.go
+++ b/app/pkg/web/context.go
@@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"strconv"
+ "time"
"strings"
@@ -161,6 +162,15 @@ func (ctx *Context) Services() *app.Services {
return ctx.Get(servicesContextKey).(*app.Services)
}
+//RemoveCookie removes a cookie
+func (ctx *Context) RemoveCookie(name string) {
+ ctx.SetCookie(&http.Cookie{
+ Name: name,
+ MaxAge: -1,
+ Expires: time.Now().Add(-100 * time.Hour),
+ })
+}
+
//SetServices update current context with app.Services
func (ctx *Context) SetServices(services *app.Services) {
ctx.Set(servicesContextKey, services)
diff --git a/package-lock.json b/package-lock.json
index 2e06a5d57..a7591aa5e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -49,8 +49,7 @@
"@types/react": {
"version": "15.0.35",
"resolved": "https://registry.npmjs.org/@types/react/-/react-15.0.35.tgz",
- "integrity": "sha512-SDvfa+9dIq7RBTBiPhV0V+NeLT16RSFjcsjcyIJUBLlHpOatja1mHuOlI+P7tJ7fZZeBd8CV5pHxmFt4MdpyGQ==",
- "dev": true
+ "integrity": "sha512-SDvfa+9dIq7RBTBiPhV0V+NeLT16RSFjcsjcyIJUBLlHpOatja1mHuOlI+P7tJ7fZZeBd8CV5pHxmFt4MdpyGQ=="
},
"@types/react-dom": {
"version": "15.5.1",
@@ -61,6 +60,14 @@
"@types/react": "15.0.35"
}
},
+ "@types/react-textarea-autosize": {
+ "version": "4.3.1",
+ "resolved": "https://registry.npmjs.org/@types/react-textarea-autosize/-/react-textarea-autosize-4.3.1.tgz",
+ "integrity": "sha512-50W9dx8TlA1Z2ZemtXXCu5docRHRTvdzIMwMAA1PSzeoivPmPguh3PHQ9ibEkK4WczPecrZblvyZCrA2t5KKnA==",
+ "requires": {
+ "@types/react": "15.0.35"
+ }
+ },
"@types/selenium-webdriver": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/@types/selenium-webdriver/-/selenium-webdriver-3.0.4.tgz",
@@ -4864,6 +4871,14 @@
"prop-types": "15.5.10"
}
},
+ "react-textarea-autosize": {
+ "version": "5.1.0",
+ "resolved": "https://registry.npmjs.org/react-textarea-autosize/-/react-textarea-autosize-5.1.0.tgz",
+ "integrity": "sha1-/7+BZPziF8eUQ8HBfe33MFkt8iQ=",
+ "requires": {
+ "prop-types": "15.5.10"
+ }
+ },
"read-pkg": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz",
diff --git a/package.json b/package.json
index 0a39b3ae9..6325a7bd0 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"lint": "tslint public/**/**.tsx public/**/**.ts"
},
"dependencies": {
+ "@types/react-textarea-autosize": "^4.3.1",
"axios": "^0.16.2",
"inversify": "^4.2.0",
"inversify-inject-decorators": "^3.0.1",
@@ -20,6 +21,7 @@
"moment": "^2.18.1",
"react": "^15.6.1",
"react-dom": "^15.6.1",
+ "react-textarea-autosize": "^5.1.0",
"reflect-metadata": "^0.1.10",
"semantic-ui-css": "^2.2.10",
"throttle-debounce": "^1.0.1"
diff --git a/public/assets/styles/main.scss b/public/assets/styles/main.scss
index 70c8c6fd6..96d469de5 100644
--- a/public/assets/styles/main.scss
+++ b/public/assets/styles/main.scss
@@ -114,6 +114,10 @@ code {
}
}
+textarea {
+ resize: none !important;
+}
+
.support-counter {
margin-right: 10px;
diff --git a/public/components/CommentInput.tsx b/public/components/CommentInput.tsx
index 3418ea828..9a0cb6994 100644
--- a/public/components/CommentInput.tsx
+++ b/public/components/CommentInput.tsx
@@ -1,7 +1,8 @@
import * as React from 'react';
+import Textarea from 'react-textarea-autosize';
import { Idea, User } from '@fider/models';
-import { Gravatar, Button, DisplayError, SocialSignInList } from '@fider/components/common';
+import { Gravatar, UserName, Button, DisplayError, SocialSignInList } from '@fider/components/common';
import { inject, injectables } from '@fider/di';
import { Session, IdeaService, Failure } from '@fider/services';
@@ -67,11 +68,12 @@ export class CommentInput extends React.Component<CommentInputProps, CommentInpu
return <div className="comment-input">
<Gravatar name={ this.user.name } hash={ this.user.gravatar }/>
<div className="ui form">
+ <UserName user={ user } />
<DisplayError error={this.state.error} />
<div className="field">
- <textarea onKeyUp={(e) => { this.setState({ content: e.currentTarget.value }); }}
- rows={3}
- placeholder="Write a comment..."></textarea>
+ <Textarea onChange={(e) => { this.setState({ content: e.currentTarget.value }); }}
+ rows={1}
+ placeholder="Write a comment..."/>
</div>
{ this.state.content && button }
</div>
diff --git a/public/components/IdeaInput.tsx b/public/components/IdeaInput.tsx
index 3708619ba..57b176994 100644
--- a/public/components/IdeaInput.tsx
+++ b/public/components/IdeaInput.tsx
@@ -1,4 +1,5 @@
import * as React from 'react';
+import Textarea from 'react-textarea-autosize';
import { DisplayError, Button, Form, SocialSignInList } from '@fider/components/common';
import { inject, injectables } from '@fider/di';
@@ -10,12 +11,12 @@ interface IdeaInputProps {
interface IdeaInputState {
title: string;
+ description: string;
focused: boolean;
}
export class IdeaInput extends React.Component<IdeaInputProps, IdeaInputState> {
private title: HTMLInputElement;
- private description: HTMLTextAreaElement;
private form: Form;
@inject(injectables.Session)
@@ -28,6 +29,7 @@ export class IdeaInput extends React.Component<IdeaInputProps, IdeaInputState> {
super();
this.state = {
title: '',
+ description: '',
focused: false
};
}
@@ -39,7 +41,7 @@ export class IdeaInput extends React.Component<IdeaInputProps, IdeaInputState> {
public async submit() {
if (this.state.title) {
this.form.clearFailure();
- const result = await this.service.addIdea(this.state.title, this.description.value);
+ const result = await this.service.addIdea(this.state.title, this.state.description);
if (result.ok) {
location.href = `/ideas/${result.data.number}/${result.data.slug}`;
} else if (result.error) {
@@ -66,9 +68,7 @@ export class IdeaInput extends React.Component<IdeaInputProps, IdeaInputState> {
const details = user ?
<div>
<div className="field">
- <textarea ref={(ref) => this.description = ref! }
- rows={6}
- placeholder="Describe your idea"></textarea>
+ <Textarea onChange={(e) => this.setState({ description: e.currentTarget.value })} placeholder="Describe your idea" />
</div>
<Button className={buttonCss} onClick={() => this.form.submit() }>
Submit
diff --git a/public/components/ResponseForm.tsx b/public/components/ResponseForm.tsx
index 52282a4e3..78698329b 100644
--- a/public/components/ResponseForm.tsx
+++ b/public/components/ResponseForm.tsx
@@ -1,26 +1,24 @@
import * as React from 'react';
+import Textarea from 'react-textarea-autosize';
+
import { User, Comment, Idea } from '@fider/models';
import { Button, DisplayError } from '@fider/components/common';
import { inject, injectables } from '@fider/di';
-import { Session, IdeaService, Failure } from '@fider/services';
+import { IdeaService, Failure } from '@fider/services';
interface ResponseFormProps {
idea: Idea;
}
interface ResponseFormState {
+ status: number;
+ text: string;
error?: Failure;
}
export class ResponseForm extends React.Component<ResponseFormProps, ResponseFormState> {
- private user: User;
private modal: HTMLDivElement;
- private text: HTMLTextAreaElement;
- private status: HTMLSelectElement;
-
- @inject(injectables.Session)
- public session: Session;
@inject(injectables.IdeaService)
public service: IdeaService;
@@ -28,13 +26,14 @@ export class ResponseForm extends React.Component<ResponseFormProps, ResponseFor
constructor(props: ResponseFormProps) {
super(props);
- this.user = this.session.getCurrentUser();
- this.state = { };
+ this.state = {
+ status: this.props.idea.status,
+ text: this.props.idea.response && this.props.idea.response.text
+ };
}
private async submit() {
- const status = parseInt(this.status.value, 10);
- const result = await this.service.setResponse(this.props.idea.number, status, this.text.value);
+ const result = await this.service.setResponse(this.props.idea.number, this.state.status, this.state.text);
if (result.ok) {
location.reload();
} else {
@@ -63,7 +62,7 @@ export class ResponseForm extends React.Component<ResponseFormProps, ResponseFor
<div className="field">
<label>Status</label>
<select className="ui dropdown"
- ref={(input) => this.status = input!}>
+ onChange={ (e) => this.setState({ status: parseInt(e.currentTarget.value, 10) }) }>
<option selected={this.props.idea.status === 0} value="0">Open</option>
<option selected={this.props.idea.status === 1} value="1">Started</option>
<option selected={this.props.idea.status === 2} value="2">Completed</option>
@@ -73,11 +72,10 @@ export class ResponseForm extends React.Component<ResponseFormProps, ResponseFor
</div>
<DisplayError fields={['text']} error={this.state.error} />
<div className="field">
- <textarea
- ref={(input) => this.text = input!}
- defaultValue={this.props.idea.response && this.props.idea.response.text}
- placeholder="What's going on with this idea? Let your users know what are your plans...">
- </textarea>
+ <Textarea
+ onChange={ (e) => this.setState({ text: e.currentTarget.value }) }
+ defaultValue={ this.state.text }
+ placeholder="What's going on with this idea? Let your users know what are your plans..." />
</div>
</div>
diff --git a/public/pages/admin/AdminHomePage.tsx b/public/pages/admin/AdminHomePage.tsx
index 02fc6c57a..74d94f2f0 100644
--- a/public/pages/admin/AdminHomePage.tsx
+++ b/public/pages/admin/AdminHomePage.tsx
@@ -1,4 +1,5 @@
import * as React from 'react';
+import Textarea from 'react-textarea-autosize';
import { Tenant } from '@fider/models';
import { setTitle } from '@fider/utils/page';
@@ -73,12 +74,11 @@ export class AdminHomePage extends React.Component<{}, AdminHomePageState> {
<DisplayError fields={['welcomeMessage']} error={this.state.error} />
<div className="field">
<label htmlFor="welcome-message">Welcome Message</label>
- <textarea id="welcome-message"
+ <Textarea id="welcome-message"
placeholder="Welcome Message"
disabled={ !this.session.isAdmin() }
- onChange={(e) => this.setState({ welcomeMessage: e.currentTarget.value })}>
- { this.state.welcomeMessage }
- </textarea>
+ onChange={(e) => this.setState({ welcomeMessage: e.currentTarget.value })}
+ value={ this.state.welcomeMessage } />
<p className="info">
<p>Use this space to change message of your initial page.</p>
<p>Common use cases for this are to briefly explain what is your Company/Product, why you created this space and how the visitors can collaborate.</p>
diff --git a/public/pages/signup/SignUpPage.tsx b/public/pages/signup/SignUpPage.tsx
index a3e0b1ff0..1b4437942 100644
--- a/public/pages/signup/SignUpPage.tsx
+++ b/public/pages/signup/SignUpPage.tsx
@@ -114,12 +114,14 @@ export class SignUpPage extends React.Component<{}, SignUpPageState> {
}
<div className="ui section divider"></div>
- <h3 className="ui header">2. Your Company/Product</h3>
+
+ <h3 className="ui header">2. What is this Feedback Forum for?</h3>
+
<DisplayError fields={['name', 'subdomain']} error={this.state.error} />
<div className="ui form">
<div className="inline field">
<input id="name" type="text"
- placeholder="Name"
+ placeholder="Your Company/Product Name"
maxLength={60}
onChange={(e) => this.setState({ name: e.currentTarget.value })}/>
</div>
@@ -151,6 +153,7 @@ export class SignUpPage extends React.Component<{}, SignUpPageState> {
<p>Make sure information provided above is correct before proceeding.</p>
+
<Button className="positive" size="large" onClick={() => this.confirm()}>Confirm</Button>
</div>
<Footer />
diff --git a/public/pages/site/ShowIdeaPage.scss b/public/pages/site/ShowIdeaPage.scss
index 5772a95ba..3dcd0731c 100644
--- a/public/pages/site/ShowIdeaPage.scss
+++ b/public/pages/site/ShowIdeaPage.scss
@@ -16,10 +16,6 @@
margin-top: 2px;
}
- .name {
- line-height: 30px;
- }
-
.comment > .content {
display: inline-block;
max-width: 85%;
@@ -29,6 +25,10 @@
.comment-input {
margin-top: 10px;
+ textarea {
+ margin-top: 5px;
+ }
+
.form {
display: inline-block;
width: 85%;
diff --git a/public/pages/site/ShowIdeaPage.tsx b/public/pages/site/ShowIdeaPage.tsx
index 1082c8a22..445c7ad8e 100644
--- a/public/pages/site/ShowIdeaPage.tsx
+++ b/public/pages/site/ShowIdeaPage.tsx
@@ -33,7 +33,7 @@ export class ShowIdeaPage extends React.Component<{}, {}> {
public render() {
- const commentsList = this.comments.length ? this.comments.map((c) =>
+ const commentsList = this.comments.map((c) =>
<div className="comment">
<Gravatar name={c.user.name} hash={c.user.gravatar} />
<div className="content">
@@ -46,7 +46,7 @@ export class ShowIdeaPage extends React.Component<{}, {}> {
</div>
</div>
</div>
- ) : <p>No comments have been added yet.</p>;
+ );
return <div className="ShowIdeaPage">
<Header />