Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

refactor: rename QueryString filters (#542)

Guilherme Oenning6fc92a5382f1
diff --git a/app/handlers/apiv1/post.go b/app/handlers/apiv1/post.go
index 1c446b21c..1d945b971 100644
--- a/app/handlers/apiv1/post.go
+++ b/app/handlers/apiv1/post.go
@@ -11,10 +11,10 @@ import (
func SearchPosts() web.HandlerFunc {
return func(c web.Context) error {
posts, err := c.Services().Posts.Search(
- c.QueryParam("q"),
- c.QueryParam("f"),
- c.QueryParam("l"),
- c.QueryParamAsArray("t"),
+ c.QueryParam("query"),
+ c.QueryParam("view"),
+ c.QueryParam("limit"),
+ c.QueryParamAsArray("tags"),
)
if err != nil {
return c.Failure(err)
diff --git a/app/handlers/post.go b/app/handlers/post.go
index 38982290c..f31431734 100644
--- a/app/handlers/post.go
+++ b/app/handlers/post.go
@@ -10,10 +10,10 @@ import (
func Index() web.HandlerFunc {
return func(c web.Context) error {
posts, err := c.Services().Posts.Search(
- c.QueryParam("q"),
- c.QueryParam("f"),
- c.QueryParam("l"),
- c.QueryParamAsArray("t"),
+ c.QueryParam("query"),
+ c.QueryParam("view"),
+ c.QueryParam("limit"),
+ c.QueryParamAsArray("tags"),
)
if err != nil {
return c.Failure(err)
diff --git a/app/storage/inmemory/post.go b/app/storage/inmemory/post.go
index ceca5c867..bec998f58 100644
--- a/app/storage/inmemory/post.go
+++ b/app/storage/inmemory/post.go
@@ -89,7 +89,7 @@ func (s *PostStorage) CountPerStatus() (map[models.PostStatus]int, error) {
}
// Search existing posts based on input
-func (s *PostStorage) Search(query, filter, limit string, tags []string) ([]*models.Post, error) {
+func (s *PostStorage) Search(query, view, limit string, tags []string) ([]*models.Post, error) {
return s.posts, nil
}
diff --git a/app/storage/postgres/common.go b/app/storage/postgres/common.go
index c29f29c5e..783739a3d 100644
--- a/app/storage/postgres/common.go
+++ b/app/storage/postgres/common.go
@@ -16,7 +16,7 @@ func ToTSQuery(input string) string {
return strings.Join(strings.Fields(input), "|")
}
-func getFilterData(filter string) (string, []models.PostStatus, string) {
+func getViewData(view string) (string, []models.PostStatus, string) {
var (
condition string
sort string
@@ -26,7 +26,7 @@ func getFilterData(filter string) (string, []models.PostStatus, string) {
models.PostStarted,
models.PostPlanned,
}
- switch filter {
+ switch view {
case "recent":
sort = "id"
case "my-votes":
diff --git a/app/storage/postgres/post.go b/app/storage/postgres/post.go
index e4cd35971..48e7ab176 100644
--- a/app/storage/postgres/post.go
+++ b/app/storage/postgres/post.go
@@ -272,7 +272,7 @@ func (s *PostStorage) CountPerStatus() (map[models.PostStatus]int, error) {
}
// Search existing posts based on input
-func (s *PostStorage) Search(query, filter, limit string, tags []string) ([]*models.Post, error) {
+func (s *PostStorage) Search(query, view, limit string, tags []string) ([]*models.Post, error) {
innerQuery := s.getPostQuery("p.tenant_id = $1 AND p.status = ANY($2)")
if limit != "all" {
@@ -301,7 +301,7 @@ func (s *PostStorage) Search(query, filter, limit string, tags []string) ([]*mod
models.PostDeclined,
}), ToTSQuery(query), query)
} else {
- condition, statuses, sort := getFilterData(filter)
+ condition, statuses, sort := getViewData(view)
sql := fmt.Sprintf(`
SELECT * FROM (%s) AS q
WHERE tags @> $3 %s
diff --git a/app/storage/storage.go b/app/storage/storage.go
index a8366d296..522380adf 100644
--- a/app/storage/storage.go
+++ b/app/storage/storage.go
@@ -19,7 +19,7 @@ type Post interface {
GetBySlug(slug string) (*models.Post, error)
GetByNumber(number int) (*models.Post, error)
GetCommentsByPost(post *models.Post) ([]*models.Comment, error)
- Search(query, filter, limit string, tags []string) ([]*models.Post, error)
+ Search(query, view, limit string, tags []string) ([]*models.Post, error)
GetAll() ([]*models.Post, error)
CountPerStatus() (map[models.PostStatus]int, error)
Add(title, description string) (*models.Post, error)
diff --git a/public/pages/Home/components/PostFilter.tsx b/public/pages/Home/components/PostFilter.tsx
index 9ff9f2171..7004d40bf 100644
--- a/public/pages/Home/components/PostFilter.tsx
+++ b/public/pages/Home/components/PostFilter.tsx
@@ -4,9 +4,9 @@ import { Dropdown, DropdownItemProps, DropdownProps } from "@fider/components";
import { Fider } from "@fider/services";
interface PostFilterProps {
- activeFilter: string;
+ activeView: string;
countPerStatus: { [key: string]: number };
- filterChanged: (name: string) => void;
+ viewChanged: (name: string) => void;
}
export class PostFilter extends React.Component<PostFilterProps, {}> {
@@ -14,8 +14,8 @@ export class PostFilter extends React.Component<PostFilterProps, {}> {
super(props);
}
- private handleChangeFilter = (item: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => {
- this.props.filterChanged(data.value as string);
+ private handleChangeView = (item: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => {
+ this.props.viewChanged(data.value as string);
};
public render() {
@@ -42,8 +42,8 @@ export class PostFilter extends React.Component<PostFilterProps, {}> {
});
});
- const filterExists = options.filter(x => x.value === this.props.activeFilter).length > 0;
- const activeFilter = filterExists ? this.props.activeFilter : "trending";
+ const viewExists = options.filter(x => x.value === this.props.activeView).length > 0;
+ const activeView = viewExists ? this.props.activeView : "trending";
return (
<>
@@ -53,8 +53,8 @@ export class PostFilter extends React.Component<PostFilterProps, {}> {
header="What do you want to see?"
inline={true}
options={options}
- defaultValue={activeFilter}
- onChange={this.handleChangeFilter}
+ defaultValue={activeView}
+ onChange={this.handleChangeView}
/>
</>
);
diff --git a/public/pages/Home/components/PostsContainer.tsx b/public/pages/Home/components/PostsContainer.tsx
index 7c0443681..d090b3610 100644
--- a/public/pages/Home/components/PostsContainer.tsx
+++ b/public/pages/Home/components/PostsContainer.tsx
@@ -16,7 +16,7 @@ interface PostsContainerProps {
interface PostsContainerState {
loading: boolean;
posts?: Post[];
- filter: string;
+ view: string;
tags: string[];
query: string;
limit?: number;
@@ -29,10 +29,10 @@ export class PostsContainer extends React.Component<PostsContainerProps, PostsCo
this.state = {
posts: this.props.posts,
loading: false,
- filter: querystring.get("f"),
- query: querystring.get("q"),
- tags: querystring.getArray("t"),
- limit: querystring.getNumber("l")
+ view: querystring.get("view"),
+ query: querystring.get("query"),
+ tags: querystring.getArray("tags"),
+ limit: querystring.getNumber("limit")
};
}
@@ -44,23 +44,23 @@ export class PostsContainer extends React.Component<PostsContainerProps, PostsCo
const query = this.state.query.trim().toLowerCase();
navigator.replaceState(
querystring.stringify({
- t: this.state.tags,
- q: query,
- f: this.state.filter,
- l: this.state.limit
+ tags: this.state.tags,
+ query,
+ view: this.state.view,
+ limit: this.state.limit
})
);
- this.searchPosts(query, this.state.filter, this.state.limit, this.state.tags, reset);
+ this.searchPosts(query, this.state.view, this.state.limit, this.state.tags, reset);
});
}
private timer?: number;
- private async searchPosts(query: string, filter: string, limit: number | undefined, tags: string[], reset: boolean) {
+ private async searchPosts(query: string, view: string, limit: number | undefined, tags: string[], reset: boolean) {
window.clearTimeout(this.timer);
this.setState({ posts: reset ? undefined : this.state.posts, loading: true });
this.timer = window.setTimeout(() => {
- actions.searchPosts({ query, filter, limit, tags }).then(response => {
+ actions.searchPosts({ query, view, limit, tags }).then(response => {
if (this.state.loading) {
this.setState({ loading: false, posts: response.data });
}
@@ -68,8 +68,8 @@ export class PostsContainer extends React.Component<PostsContainerProps, PostsCo
}, 200);
}
- private handleFilterChanged = (filter: string) => {
- this.changeFilterCriteria({ filter }, true);
+ private handleViewChanged = (view: string) => {
+ this.changeFilterCriteria({ view }, true);
};
private handleTagsFilterChanged = (tags: string[]) => {
@@ -105,8 +105,8 @@ export class PostsContainer extends React.Component<PostsContainerProps, PostsCo
<div className="l-filter-col col-sm-7 col-md-8 col-lg-9 mb-2">
<Field>
<PostFilter
- activeFilter={this.state.filter}
- filterChanged={this.handleFilterChanged}
+ activeView={this.state.view}
+ viewChanged={this.handleViewChanged}
countPerStatus={this.props.countPerStatus}
/>
<TagsFilter
diff --git a/public/services/actions/post.ts b/public/services/actions/post.ts
index fd1b80576..8df1ebbe7 100644
--- a/public/services/actions/post.ts
+++ b/public/services/actions/post.ts
@@ -7,7 +7,7 @@ export const getAllPosts = async (): Promise<Result<Post[]>> => {
export interface SearchPostsParams {
query?: string;
- filter?: string;
+ view?: string;
limit?: number;
tags?: string[];
}
@@ -15,10 +15,10 @@ export interface SearchPostsParams {
export const searchPosts = async (params: SearchPostsParams): Promise<Result<Post[]>> => {
return await http.get<Post[]>(
`/api/v1/posts${querystring.stringify({
- t: params.tags,
- q: params.query,
- f: params.filter,
- l: params.limit
+ tags: params.tags,
+ query: params.query,
+ view: params.view,
+ limit: params.limit
})}`
);
};