- This shows when creating a post, or when viewing a post.
- Fixes #131
data.community_id,
None,
None,
+ None,
user_id,
show_nsfw,
false,
#[derive(Serialize, Deserialize)]
pub struct SearchResponse {
op: String,
+ type_: String,
comments: Vec<CommentView>,
posts: Vec<PostView>,
communities: Vec<CommunityView>,
data.community_id,
None,
Some(data.q.to_owned()),
+ None,
None,
true,
false,
data.community_id,
None,
Some(data.q.to_owned()),
+ None,
None,
true,
false,
Some(data.q.to_owned()),
data.page,
data.limit)?;
+ },
+ SearchType::Url => {
+ posts = PostView::list(
+ &conn,
+ PostListingType::All,
+ &sort,
+ data.community_id,
+ None,
+ None,
+ Some(data.q.to_owned()),
+ None,
+ true,
+ false,
+ false,
+ data.page,
+ data.limit)?;
}
};
Ok(
SearchResponse {
op: self.op.to_string(),
+ type_: data.type_.to_owned(),
comments: comments,
posts: posts,
communities: communities,
data.community_id,
None,
None,
+ None,
Some(user_details_id),
show_nsfw,
data.saved_only,
data.community_id,
Some(user_details_id),
None,
+ None,
user_id,
show_nsfw,
data.saved_only,
#[derive(EnumString,ToString,Debug, Serialize, Deserialize)]
pub enum SearchType {
- All, Comments, Posts, Communities, Users
+ All, Comments, Posts, Communities, Users, Url
}
pub fn fuzzy_search(q: &str) -> String {
for_community_id: Option<i32>,
for_creator_id: Option<i32>,
search_term: Option<String>,
+ url_search: Option<String>,
my_user_id: Option<i32>,
show_nsfw: bool,
saved_only: bool,
query = query.filter(name.ilike(fuzzy_search(&search_term)));
};
+ if let Some(url_search) = url_search {
+ query = query.filter(url.eq(url_search));
+ };
+
// TODO these are wrong, bc they'll only show saved for your logged in user, not theirs
if saved_only {
query = query.filter(saved.eq(true));
};
- let read_post_listings_with_user = PostView::list(&conn,
- PostListingType::Community,
- &SortType::New, Some(inserted_community.id),
- None,
- None,
- Some(inserted_user.id),
- false,
- false,
- false,
- None,
- None).unwrap();
- let read_post_listings_no_user = PostView::list(&conn,
- PostListingType::Community,
- &SortType::New,
- Some(inserted_community.id),
- None,
- None,
- None,
- false,
- false,
- false,
- None,
- None).unwrap();
+ let read_post_listings_with_user = PostView::list(
+ &conn,
+ PostListingType::Community,
+ &SortType::New,
+ Some(inserted_community.id),
+ None,
+ None,
+ None,
+ Some(inserted_user.id),
+ false,
+ false,
+ false,
+ None,
+ None).unwrap();
+ let read_post_listings_no_user = PostView::list(
+ &conn,
+ PostListingType::Community,
+ &SortType::New,
+ Some(inserted_community.id),
+ None,
+ None,
+ None,
+ None,
+ false,
+ false,
+ false,
+ None,
+ None).unwrap();
let read_post_listing_no_user = PostView::read(&conn, inserted_post.id, None).unwrap();
let read_post_listing_with_user = PostView::read(&conn, inserted_post.id, Some(inserted_user.id)).unwrap();
None,
None,
None,
+ None,
false,
false,
false,
loading: boolean;
suggestedTitle: string;
suggestedPosts: Array<Post>;
+ crossPosts: Array<Post>;
}
export class PostForm extends Component<PostFormProps, PostFormState> {
loading: false,
suggestedTitle: undefined,
suggestedPosts: [],
+ crossPosts: [],
}
constructor(props: any, context: any) {
{this.state.suggestedTitle &&
<div class="mt-1 text-muted small font-weight-bold pointer" onClick={linkEvent(this, this.copySuggestedTitle)}><T i18nKey="copy_suggested_title" interpolation={{title: this.state.suggestedTitle}}>#</T></div>
}
+ {this.state.crossPosts.length > 0 &&
+ <>
+ <div class="my-1 text-muted small font-weight-bold"><T i18nKey="cross_posts">#</T></div>
+ <PostListings showCommunity posts={this.state.crossPosts} />
+ </>
+ }
</div>
</div>
<div class="form-group row">
handlePostUrlChange(i: PostForm, event: any) {
i.state.postForm.url = event.target.value;
if (validURL(i.state.postForm.url)) {
+
+ let form: SearchForm = {
+ q: i.state.postForm.url,
+ type_: SearchType[SearchType.Url],
+ sort: SortType[SortType.TopAll],
+ page: 1,
+ limit: 6,
+ };
+
+ WebSocketService.Instance.search(form);
+
+ // Fetch the page title
getPageTitle(i.state.postForm.url).then(d => {
i.state.suggestedTitle = d;
i.setState(i.state);
});
} else {
i.state.suggestedTitle = undefined;
+ i.state.crossPosts = [];
}
+
i.setState(i.state);
}
this.props.onEdit(res.post);
} else if (op == UserOperation.Search) {
let res: SearchResponse = msg;
- this.state.suggestedPosts = res.posts;
+
+ if (res.type_ == SearchType[SearchType.Posts]) {
+ this.state.suggestedPosts = res.posts;
+ } else if (res.type_ == SearchType[SearchType.Url]) {
+ this.state.crossPosts = res.posts;
+ }
this.setState(this.state);
}
}
import { Component, linkEvent } from 'inferno';
import { Subscription } from "rxjs";
import { retryWhen, delay, take } from 'rxjs/operators';
-import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, BanUserResponse, AddModToCommunityResponse, AddAdminResponse, UserView } from '../interfaces';
+import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, BanUserResponse, AddModToCommunityResponse, AddAdminResponse, UserView, SearchType, SortType, SearchForm, SearchResponse } from '../interfaces';
import { WebSocketService, UserService } from '../services';
import { msgOp, hotRank } from '../utils';
import { PostListing } from './post-listing';
+import { PostListings } from './post-listings';
import { Sidebar } from './sidebar';
import { CommentForm } from './comment-form';
import { CommentNodes } from './comment-nodes';
scrolled?: boolean;
scrolled_comment_id?: number;
loading: boolean;
+ crossPosts: Array<PostI>;
}
export class Post extends Component<any, PostState> {
moderators: [],
admins: [],
scrolled: false,
- loading: true
+ loading: true,
+ crossPosts: [],
}
constructor(props: any, context: any) {
moderators={this.state.moderators}
admins={this.state.admins}
/>
+ {this.state.crossPosts.length > 0 &&
+ <>
+ <div class="my-1 text-muted small font-weight-bold"><T i18nKey="cross_posts">#</T></div>
+ <PostListings showCommunity posts={this.state.crossPosts} />
+ </>
+ }
<div className="mb-2" />
<CommentForm postId={this.state.post.id} disabled={this.state.post.locked} />
{this.sortRadios()}
this.state.admins = res.admins;
this.state.loading = false;
document.title = `${this.state.post.name} - ${WebSocketService.Instance.site.name}`;
+
+ // Get cross-posts
+ let form: SearchForm = {
+ q: res.post.url,
+ type_: SearchType[SearchType.Url],
+ sort: SortType[SortType.TopAll],
+ page: 1,
+ limit: 6,
+ };
+
+ WebSocketService.Instance.search(form);
+
this.setState(this.state);
} else if (op == UserOperation.CreateComment) {
let res: CommentResponse = msg;
let res: AddAdminResponse = msg;
this.state.admins = res.admins;
this.setState(this.state);
+ } else if (op == UserOperation.Search) {
+ let res: SearchResponse = msg;
+ this.state.crossPosts = res.posts.filter(p => p.id != this.state.post.id);
+ this.setState(this.state);
}
}
page: 1,
searchResponse: {
op: null,
+ type_: null,
posts: [],
comments: [],
communities: [],
}
export enum SearchType {
- All, Comments, Posts, Communities, Users
+ All, Comments, Posts, Communities, Users, Url
}
export interface User {
export interface SearchResponse {
op: string;
+ type_: string;
posts?: Array<Post>;
comments?: Array<Comment>;
communities: Array<Community>;
number_of_posts:'{{count}} Posts',
posts: 'Posts',
related_posts: 'These posts might be related',
+ cross_posts: 'This link has also been posted to:',
comments: 'Comments',
number_of_comments:'{{count}} Comments',
remove_comment: 'Remove Comment',