- Can lock, remove, and restore posts and comments.
- Can ban and unban users from communities and the site.
- Clean, mobile-friendly interface.
+- i18n / internationalization support.
- High performance.
- Server is written in rust.
- Front end is `~80kB` gzipped.
let sort = SortType::from_str(&data.sort)?;
- let communities: Vec<CommunityView> = CommunityView::list(&conn, user_id, sort, data.page, data.limit)?;
+ let communities: Vec<CommunityView> = CommunityView::list(&conn, &sort, user_id, None, data.page, data.limit)?;
// Return the jwt
Ok(
op: String,
comments: Vec<CommentView>,
posts: Vec<PostView>,
+ communities: Vec<CommunityView>,
+ users: Vec<UserView>,
}
#[derive(Serialize, Deserialize)]
let mut posts = Vec::new();
let mut comments = Vec::new();
+ let mut communities = Vec::new();
+ let mut users = Vec::new();
match type_ {
SearchType::Posts => {
- posts = PostView::list(&conn,
- PostListingType::All,
- &sort,
- data.community_id,
- None,
- Some(data.q.to_owned()),
- None,
- false,
- false,
- data.page,
- data.limit)?;
+ posts = PostView::list(
+ &conn,
+ PostListingType::All,
+ &sort,
+ data.community_id,
+ None,
+ Some(data.q.to_owned()),
+ None,
+ false,
+ false,
+ data.page,
+ data.limit)?;
},
SearchType::Comments => {
- comments = CommentView::list(&conn,
- &sort,
- None,
- None,
- Some(data.q.to_owned()),
- None,
- false,
- data.page,
- data.limit)?;
+ comments = CommentView::list(
+ &conn,
+ &sort,
+ None,
+ None,
+ Some(data.q.to_owned()),
+ None,
+ false,
+ data.page,
+ data.limit)?;
+ },
+ SearchType::Communities => {
+ communities = CommunityView::list(
+ &conn,
+ &sort,
+ None,
+ Some(data.q.to_owned()),
+ data.page,
+ data.limit)?;
+ },
+ SearchType::Users => {
+ users = UserView::list(
+ &conn,
+ &sort,
+ Some(data.q.to_owned()),
+ data.page,
+ data.limit)?;
},
- SearchType::Both => {
- posts = PostView::list(&conn,
- PostListingType::All,
- &sort,
- data.community_id,
- None,
- Some(data.q.to_owned()),
- None,
- false,
- false,
- data.page,
- data.limit)?;
- comments = CommentView::list(&conn,
- &sort,
- None,
- None,
- Some(data.q.to_owned()),
- None,
- false,
- data.page,
- data.limit)?;
+ SearchType::All => {
+ posts = PostView::list(
+ &conn,
+ PostListingType::All,
+ &sort,
+ data.community_id,
+ None,
+ Some(data.q.to_owned()),
+ None,
+ false,
+ false,
+ data.page,
+ data.limit)?;
+ comments = CommentView::list(
+ &conn,
+ &sort,
+ None,
+ None,
+ Some(data.q.to_owned()),
+ None,
+ false,
+ data.page,
+ data.limit)?;
+ communities = CommunityView::list(
+ &conn,
+ &sort,
+ None,
+ Some(data.q.to_owned()),
+ data.page,
+ data.limit)?;
+ users = UserView::list(
+ &conn,
+ &sort,
+ Some(data.q.to_owned()),
+ data.page,
+ data.limit)?;
}
};
op: self.op.to_string(),
comments: comments,
posts: posts,
+ communities: communities,
+ users: users,
}
)
}
}
pub fn list(conn: &PgConnection,
+ sort: &SortType,
from_user_id: Option<i32>,
- sort: SortType,
+ search_term: Option<String>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
let (limit, offset) = limit_and_offset(page, limit);
+ if let Some(search_term) = search_term {
+ query = query.filter(name.ilike(fuzzy_search(&search_term)));
+ };
+
// The view lets you pass a null user_id, if you're not logged in
match sort {
SortType::Hot => query = query.order_by(hot_rank.desc())
#[derive(EnumString,ToString,Debug, Serialize, Deserialize)]
pub enum SearchType {
- Both, Comments, Posts
+ All, Comments, Posts, Communities, Users
}
pub fn fuzzy_search(q: &str) -> String {
}
impl UserView {
+
+ pub fn list(conn: &PgConnection,
+ sort: &SortType,
+ search_term: Option<String>,
+ page: Option<i64>,
+ limit: Option<i64>,
+ ) -> Result<Vec<Self>, Error> {
+ use super::user_view::user_view::dsl::*;
+
+ let (limit, offset) = limit_and_offset(page, limit);
+
+ let mut query = user_view.into_boxed();
+
+ if let Some(search_term) = search_term {
+ query = query.filter(name.ilike(fuzzy_search(&search_term)));
+ };
+
+ query = match sort {
+ SortType::Hot => query.order_by(comment_score.desc())
+ .then_order_by(published.desc()),
+ SortType::New => query.order_by(published.desc()),
+ SortType::TopAll => query.order_by(comment_score.desc()),
+ SortType::TopYear => query
+ .filter(published.gt(now - 1.years()))
+ .order_by(comment_score.desc()),
+ SortType::TopMonth => query
+ .filter(published.gt(now - 1.months()))
+ .order_by(comment_score.desc()),
+ SortType::TopWeek => query
+ .filter(published.gt(now - 1.weeks()))
+ .order_by(comment_score.desc()),
+ SortType::TopDay => query
+ .filter(published.gt(now - 1.days()))
+ .order_by(comment_score.desc())
+ };
+
+ query = query
+ .limit(limit)
+ .offset(offset);
+
+ query.load::<Self>(conn)
+ }
+
pub fn read(conn: &PgConnection, from_user_id: i32) -> Result<Self, Error> {
use super::user_view::user_view::dsl::*;
import { Component, linkEvent } from 'inferno';
+import { Link } from 'inferno-router';
import { Subscription } from "rxjs";
import { retryWhen, delay, take } from 'rxjs/operators';
-import { UserOperation, Post, Comment, SortType, SearchForm, SearchResponse, SearchType } from '../interfaces';
+import { UserOperation, Post, Comment, Community, UserView, SortType, SearchForm, SearchResponse, SearchType } from '../interfaces';
import { WebSocketService } from '../services';
import { msgOp, fetchLimit } from '../utils';
import { PostListing } from './post-listing';
private subscription: Subscription;
private emptyState: SearchState = {
q: undefined,
- type_: SearchType.Both,
+ type_: SearchType.All,
sort: SortType.TopAll,
page: 1,
searchResponse: {
op: null,
posts: [],
comments: [],
+ communities: [],
+ users: [],
},
loading: false,
}
<h5><T i18nKey="search">#</T></h5>
{this.selects()}
{this.searchForm()}
- {this.state.type_ == SearchType.Both &&
- this.both()
+ {this.state.type_ == SearchType.All &&
+ this.all()
}
{this.state.type_ == SearchType.Comments &&
this.comments()
{this.state.type_ == SearchType.Posts &&
this.posts()
}
+ {this.state.type_ == SearchType.Communities &&
+ this.communities()
+ }
+ {this.state.type_ == SearchType.Users &&
+ this.users()
+ }
{this.noResults()}
{this.paginator()}
</div>
<div className="mb-2">
<select value={this.state.type_} onChange={linkEvent(this, this.handleTypeChange)} class="custom-select custom-select-sm w-auto">
<option disabled><T i18nKey="type">#</T></option>
- <option value={SearchType.Both}><T i18nKey="both">#</T></option>
+ <option value={SearchType.All}><T i18nKey="all">#</T></option>
<option value={SearchType.Comments}><T i18nKey="comments">#</T></option>
<option value={SearchType.Posts}><T i18nKey="posts">#</T></option>
+ <option value={SearchType.Communities}><T i18nKey="communities">#</T></option>
+ <option value={SearchType.Users}><T i18nKey="users">#</T></option>
</select>
<select value={this.state.sort} onChange={linkEvent(this, this.handleSortChange)} class="custom-select custom-select-sm w-auto ml-2">
<option disabled><T i18nKey="sort_type">#</T></option>
}
- both() {
- let combined: Array<{type_: string, data: Comment | Post}> = [];
+ all() {
+ let combined: Array<{type_: string, data: Comment | Post | Community | UserView}> = [];
let comments = this.state.searchResponse.comments.map(e => {return {type_: "comments", data: e}});
let posts = this.state.searchResponse.posts.map(e => {return {type_: "posts", data: e}});
+ let communities = this.state.searchResponse.communities.map(e => {return {type_: "communities", data: e}});
+ let users = this.state.searchResponse.users.map(e => {return {type_: "users", data: e}});
combined.push(...comments);
combined.push(...posts);
+ combined.push(...communities);
+ combined.push(...users);
// Sort it
if (this.state.sort == SortType.New) {
combined.sort((a, b) => b.data.published.localeCompare(a.data.published));
} else {
- combined.sort((a, b) => b.data.score - a.data.score);
+ combined.sort((a, b) => ((b.data as Comment | Post).score
+ | (b.data as Community).number_of_subscribers
+ | (b.data as UserView).comment_score)
+ - ((a.data as Comment | Post).score
+ | (a.data as Community).number_of_subscribers
+ | (a.data as UserView).comment_score));
}
return (
<div>
{combined.map(i =>
<div>
- {i.type_ == "posts"
- ? <PostListing post={i.data as Post} showCommunity viewOnly />
- : <CommentNodes nodes={[{comment: i.data as Comment}]} viewOnly noIndent />
+ {i.type_ == "posts" &&
+ <PostListing post={i.data as Post} showCommunity viewOnly />
+ }
+ {i.type_ == "comments" &&
+ <CommentNodes nodes={[{comment: i.data as Comment}]} viewOnly noIndent />
+ }
+ {i.type_ == "communities" &&
+ <div>
+ <span><Link to={`/c/${(i.data as Community).name}`}>{`/c/${(i.data as Community).name}`}</Link></span>
+ <span>{` - ${(i.data as Community).title} - ${(i.data as Community).number_of_subscribers} subscribers`}</span>
+ </div>
+ }
+ {i.type_ == "users" &&
+ <div>
+ <span><Link className="text-info" to={`/u/${(i.data as UserView).name}`}>{`/u/${(i.data as UserView).name}`}</Link></span>
+ <span>{` - ${(i.data as UserView).comment_score} comment karma`}</span>
+ </div>
}
</div>
)
);
}
+ // Todo possibly create UserListing and CommunityListing
+ communities() {
+ return (
+ <div>
+ {this.state.searchResponse.communities.map(community =>
+ <div>
+ <span><Link to={`/c/${community.name}`}>{`/c/${community.name}`}</Link></span>
+ <span>{` - ${community.title} - ${community.number_of_subscribers} subscribers`}</span>
+ </div>
+ )}
+ </div>
+ );
+ }
+
+ users() {
+ return (
+ <div>
+ {this.state.searchResponse.users.map(user =>
+ <div>
+ <span><Link className="text-info" to={`/u/${user.name}`}>{`/u/${user.name}`}</Link></span>
+ <span>{` - ${user.comment_score} comment karma`}</span>
+ </div>
+ )}
+ </div>
+ );
+ }
+
paginator() {
return (
<div class="mt-2">
i.state.sort = Number(event.target.value);
i.state.page = 1;
i.setState(i.state);
- i.search();
}
handleTypeChange(i: Search, event: any) {
i.state.type_ = Number(event.target.value);
i.state.page = 1;
i.setState(i.state);
- i.search();
}
handleSearchSubmit(i: Search, event: any) {
}
export enum SearchType {
- Both, Comments, Posts
+ All, Comments, Posts, Communities, Users
}
export interface User {
op: string;
posts?: Array<Post>;
comments?: Array<Comment>;
+ communities: Array<Community>;
+ users: Array<UserView>;
}
number_of_comments:'{{count}} Comments',
remove_comment: 'Remove Comment',
communities: 'Communities',
+ users: 'Users',
create_a_community: 'Create a community',
create_community: 'Create Community',
remove_community: 'Remove Community',