Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

list comments and add input field

goenningbd7f9168790b
diff --git a/app/feedback/handler.go b/app/feedback/handler.go
index 782d32da0..21c22d7c9 100644
--- a/app/feedback/handler.go
+++ b/app/feedback/handler.go
@@ -5,8 +5,6 @@ import (
"strconv"
- "fmt"
-
"github.com/WeCanHearYou/wechy/app/identity"
"github.com/labstack/echo"
)
@@ -67,14 +65,13 @@ func (h IndexHandlder) Details() echo.HandlerFunc {
return func(c echo.Context) error {
tenant := c.Get("Tenant").(*identity.Tenant)
ideaID, _ := strconv.Atoi(c.Param("id"))
- idea, err := h.ideaService.GetByID(tenant.ID, int64(ideaID))
- if err != nil {
- fmt.Println(err)
- }
+ idea, _ := h.ideaService.GetByID(tenant.ID, int64(ideaID))
+ comments, _ := h.ideaService.GetCommentsByIdeaID(tenant.ID, idea.ID)
return c.Render(200, "idea.html", echo.Map{
- "Tenant": tenant,
- "Idea": idea,
+ "Tenant": tenant,
+ "Comments": comments,
+ "Idea": idea,
})
}
}
diff --git a/app/feedback/handler_test.go b/app/feedback/handler_test.go
index 6b699e21e..c8472aa0b 100644
--- a/app/feedback/handler_test.go
+++ b/app/feedback/handler_test.go
@@ -19,6 +19,10 @@ func (svc mockIdeaService) GetAll(tenantID int64) ([]*feedback.Idea, error) {
return make([]*feedback.Idea, 0), nil
}
+func (svc mockIdeaService) GetCommentsByIdeaID(tenantID, ideaID int64) ([]*feedback.Comment, error) {
+ return make([]*feedback.Comment, 0), nil
+}
+
func (svc mockIdeaService) Save(tenantID, userID int64, title, description string) (*feedback.Idea, error) {
return nil, nil
}
diff --git a/app/feedback/model.go b/app/feedback/model.go
index 8e538bd23..e1254ee77 100644
--- a/app/feedback/model.go
+++ b/app/feedback/model.go
@@ -14,3 +14,11 @@ type Idea struct {
CreatedOn time.Time `json:"createdOn"`
User identity.User `json:"user"`
}
+
+//Comment represents an user comment on an idea
+type Comment struct {
+ ID int64 `json:"id"`
+ Content string `json:"content"`
+ CreatedOn time.Time `json:"createdOn"`
+ User identity.User `json:"user"`
+}
diff --git a/app/feedback/service.go b/app/feedback/service.go
index 9b20e18ff..ebd42e9db 100644
--- a/app/feedback/service.go
+++ b/app/feedback/service.go
@@ -3,6 +3,7 @@ package feedback
// IdeaService contains read and write operations for ideas
type IdeaService interface {
GetByID(tenantID, ideaID int64) (*Idea, error)
+ GetCommentsByIdeaID(tenantID, ideaID int64) ([]*Comment, error)
GetAll(tenantID int64) ([]*Idea, error)
Save(tenantID, userID int64, title, description string) (*Idea, error)
}
diff --git a/app/postgres/feedback.go b/app/postgres/feedback.go
index efa411204..3fc9fd6bd 100644
--- a/app/postgres/feedback.go
+++ b/app/postgres/feedback.go
@@ -18,7 +18,7 @@ type IdeaService struct {
func (svc IdeaService) GetAll(tenantID int64) ([]*feedback.Idea, error) {
rows, err := svc.DB.Query(`SELECT i.id, i.title, i.description, i.created_on, u.id, u.name, u.email
FROM ideas i
- LEFT JOIN users u
+ INNER JOIN users u
ON u.id = i.user_id
WHERE i.tenant_id = $1
ORDER BY i.created_on DESC`, tenantID)
@@ -40,7 +40,7 @@ func (svc IdeaService) GetAll(tenantID int64) ([]*feedback.Idea, error) {
func (svc IdeaService) GetByID(tenantID, ideaID int64) (*feedback.Idea, error) {
rows, err := svc.DB.Query(`SELECT i.id, i.title, i.description, i.created_on, u.id, u.name, u.email
FROM ideas i
- LEFT JOIN users u
+ INNER JOIN users u
ON u.id = i.user_id
WHERE i.tenant_id = $1
AND i.id = $2
@@ -57,6 +57,31 @@ func (svc IdeaService) GetByID(tenantID, ideaID int64) (*feedback.Idea, error) {
return nil, identity.ErrNotFound
}
+// GetCommentsByIdeaID returns all coments from given idea
+func (svc IdeaService) GetCommentsByIdeaID(tenantID, ideaID int64) ([]*feedback.Comment, error) {
+ rows, err := svc.DB.Query(`SELECT c.id, c.content, c.created_on, u.id, u.name, u.email
+ FROM comments c
+ INNER JOIN ideas i
+ ON i.id = c.idea_id
+ INNER JOIN users u
+ ON u.id = c.user_id
+ WHERE i.id = $1
+ AND i.tenant_id = $2
+ ORDER BY c.created_on DESC`, ideaID, tenantID)
+ if err != nil {
+ return nil, err
+ }
+
+ var comments []*feedback.Comment
+ for rows.Next() {
+ c := &feedback.Comment{}
+ rows.Scan(&c.ID, &c.Content, &c.CreatedOn, &c.User.ID, &c.User.Name, &c.User.Email)
+ comments = append(comments, c)
+ }
+
+ return comments, nil
+}
+
// Save a new idea in the database
func (svc IdeaService) Save(tenantID, userID int64, title, description string) (*feedback.Idea, error) {
tx, err := svc.DB.Begin()
diff --git a/public/components/ShowIdeaRoot.tsx b/public/components/ShowIdeaRoot.tsx
index e72bfa849..09a2158b8 100644
--- a/public/components/ShowIdeaRoot.tsx
+++ b/public/components/ShowIdeaRoot.tsx
@@ -1,8 +1,9 @@
import * as moment from "moment";
import * as React from "react";
-import { Idea } from "../models";
+import { Comment, Idea } from "../models";
import * as storage from "../storage";
import { Gravatar, MultiLineText } from "./Common";
+import { SocialSignInButton } from "./SocialSignInButton";
import { Footer } from "./Footer";
import { Header } from "./Header";
@@ -10,7 +11,43 @@ import { IdeaInput } from "./IdeaInput";
export class ShowIdeaRoot extends React.Component<{}, {}> {
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) =>
+ <div className="comment">
+ <a className="avatar">
+ <Gravatar email={c.user.email} />
+ </a>
+ <div className="content">
+ <span className="author">{ c.user.name }</span>
+ <div className="metadata">
+ <span className="date" title={c.createdOn}>{ moment(c.createdOn).fromNow() }</span>
+ </div>
+ <div className="text">
+ { c.content }
+ </div>
+ </div>
+ </div>
+ ) : <p>No comments yet.</p>;
+
+ const addComment = user ? <form className="ui reply form">
+ <div className="field">
+ <textarea></textarea>
+ </div>
+ <div className="ui blue labeled submit icon button">
+ <i className="icon edit"></i> Add Comment
+ </div>
+ </form> :
+ <div className="ui message">
+ <div className="header">
+ Please log in before leaving a comment
+ </div>
+ <p>This only takes a second and you'll be good to go!</p>
+ <SocialSignInButton provider="facebook" small={true} />
+ <SocialSignInButton provider="google" small={true} />
+ </div>;
return <div>
<Header />
@@ -24,7 +61,11 @@ export class ShowIdeaRoot extends React.Component<{}, {}> {
&nbsp;shared <u title={idea.createdOn}>{ moment(idea.createdOn).fromNow() }</u>
</p>
- <p><a href="/">Back</a></p>
+ <div className="ui comments">
+ <h3 className="ui dividing header">Comments</h3>
+ { commentsList }
+ </div>
+ { addComment }
</div>
<Footer />
</div>;
diff --git a/public/models.ts b/public/models.ts
index 794b187fd..8bca4e27f 100644
--- a/public/models.ts
+++ b/public/models.ts
@@ -17,3 +17,10 @@ export interface Idea {
createdOn: string;
user: User;
}
+
+export interface Comment {
+ id: number;
+ content: string;
+ createdOn: string;
+ user: User;
+}
diff --git a/views/idea.html b/views/idea.html
index ef00ee875..0fb602e2e 100644
--- a/views/idea.html
+++ b/views/idea.html
@@ -4,6 +4,7 @@
{{define "javascript"}}
set("idea", {{ .Idea }});
+ set("comments", {{ .Comments }});
{{end}}
{{define "content"}}{{end}}
\ No newline at end of file