mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-23 03:11:25 +00:00
Integrating resolve_user into search. (#377)
* Integrating resolve_user into search. * Upgrading lemmy-js-client.
This commit is contained in:
parent
6a3bdaa85c
commit
0d3e8cac1d
3 changed files with 181 additions and 49 deletions
|
@ -69,7 +69,7 @@
|
||||||
"husky": "^7.0.1",
|
"husky": "^7.0.1",
|
||||||
"import-sort-style-module": "^6.0.0",
|
"import-sort-style-module": "^6.0.0",
|
||||||
"iso-639-1": "^2.1.9",
|
"iso-639-1": "^2.1.9",
|
||||||
"lemmy-js-client": "0.11.4-rc.14",
|
"lemmy-js-client": "0.11.4-rc.16",
|
||||||
"lint-staged": "^11.0.1",
|
"lint-staged": "^11.0.1",
|
||||||
"mini-css-extract-plugin": "^2.1.0",
|
"mini-css-extract-plugin": "^2.1.0",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
|
|
|
@ -11,6 +11,8 @@ import {
|
||||||
PersonViewSafe,
|
PersonViewSafe,
|
||||||
PostResponse,
|
PostResponse,
|
||||||
PostView,
|
PostView,
|
||||||
|
ResolveObject,
|
||||||
|
ResolveObjectResponse,
|
||||||
Search as SearchForm,
|
Search as SearchForm,
|
||||||
SearchResponse,
|
SearchResponse,
|
||||||
SearchType,
|
SearchType,
|
||||||
|
@ -91,6 +93,7 @@ interface SearchState {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
site: Site;
|
site: Site;
|
||||||
searchText: string;
|
searchText: string;
|
||||||
|
resolveObjectResponse: ResolveObjectResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UrlParams {
|
interface UrlParams {
|
||||||
|
@ -103,6 +106,12 @@ interface UrlParams {
|
||||||
page?: number;
|
page?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Combined {
|
||||||
|
type_: string;
|
||||||
|
data: CommentView | PostView | CommunityView | PersonViewSafe;
|
||||||
|
published: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class Search extends Component<any, SearchState> {
|
export class Search extends Component<any, SearchState> {
|
||||||
private isoData = setIsoData(this.context);
|
private isoData = setIsoData(this.context);
|
||||||
private communityChoices: any;
|
private communityChoices: any;
|
||||||
|
@ -128,6 +137,12 @@ export class Search extends Component<any, SearchState> {
|
||||||
communities: [],
|
communities: [],
|
||||||
users: [],
|
users: [],
|
||||||
},
|
},
|
||||||
|
resolveObjectResponse: {
|
||||||
|
comment: null,
|
||||||
|
post: null,
|
||||||
|
community: null,
|
||||||
|
person: null,
|
||||||
|
},
|
||||||
loading: true,
|
loading: true,
|
||||||
site: this.isoData.site_res.site_view.site,
|
site: this.isoData.site_res.site_view.site,
|
||||||
communities: [],
|
communities: [],
|
||||||
|
@ -187,6 +202,7 @@ export class Search extends Component<any, SearchState> {
|
||||||
}
|
}
|
||||||
if (this.state.q != "") {
|
if (this.state.q != "") {
|
||||||
this.state.searchResponse = this.isoData.routeData[2];
|
this.state.searchResponse = this.isoData.routeData[2];
|
||||||
|
this.state.resolveObjectResponse = this.isoData.routeData[3];
|
||||||
this.state.loading = false;
|
this.state.loading = false;
|
||||||
} else {
|
} else {
|
||||||
this.search();
|
this.search();
|
||||||
|
@ -283,8 +299,14 @@ export class Search extends Component<any, SearchState> {
|
||||||
}
|
}
|
||||||
setOptionalAuth(form, req.auth);
|
setOptionalAuth(form, req.auth);
|
||||||
|
|
||||||
|
let resolveObjectForm: ResolveObject = {
|
||||||
|
q: this.getSearchQueryFromProps(pathSplit[3]),
|
||||||
|
};
|
||||||
|
setOptionalAuth(resolveObjectForm, req.auth);
|
||||||
|
|
||||||
if (form.q != "") {
|
if (form.q != "") {
|
||||||
promises.push(req.client.search(form));
|
promises.push(req.client.search(form));
|
||||||
|
promises.push(req.client.resolveObject(resolveObjectForm));
|
||||||
}
|
}
|
||||||
|
|
||||||
return promises;
|
return promises;
|
||||||
|
@ -402,33 +424,78 @@ export class Search extends Component<any, SearchState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
all() {
|
postViewToCombined(postView: PostView): Combined {
|
||||||
let combined: {
|
return {
|
||||||
type_: string;
|
type_: "posts",
|
||||||
data: CommentView | PostView | CommunityView | PersonViewSafe;
|
data: postView,
|
||||||
published: string;
|
published: postView.post.published,
|
||||||
}[] = [];
|
};
|
||||||
let comments = this.state.searchResponse.comments.map(e => {
|
}
|
||||||
return { type_: "comments", data: e, published: e.comment.published };
|
|
||||||
});
|
commentViewToCombined(commentView: CommentView): Combined {
|
||||||
let posts = this.state.searchResponse.posts.map(e => {
|
return {
|
||||||
return { type_: "posts", data: e, published: e.post.published };
|
type_: "comments",
|
||||||
});
|
data: commentView,
|
||||||
let communities = this.state.searchResponse.communities.map(e => {
|
published: commentView.comment.published,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
communityViewToCombined(communityView: CommunityView): Combined {
|
||||||
return {
|
return {
|
||||||
type_: "communities",
|
type_: "communities",
|
||||||
data: e,
|
data: communityView,
|
||||||
published: e.community.published,
|
published: communityView.community.published,
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
let users = this.state.searchResponse.users.map(e => {
|
|
||||||
return { type_: "users", data: e, published: e.person.published };
|
|
||||||
});
|
|
||||||
|
|
||||||
combined.push(...comments);
|
personViewSafeToCombined(personViewSafe: PersonViewSafe): Combined {
|
||||||
combined.push(...posts);
|
return {
|
||||||
combined.push(...communities);
|
type_: "users",
|
||||||
combined.push(...users);
|
data: personViewSafe,
|
||||||
|
published: personViewSafe.person.published,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
buildCombined(): Combined[] {
|
||||||
|
let combined: Combined[] = [];
|
||||||
|
|
||||||
|
// Push the possible resolve / federated objects first
|
||||||
|
let resolveComment = this.state.resolveObjectResponse.comment;
|
||||||
|
if (resolveComment) {
|
||||||
|
combined.push(this.commentViewToCombined(resolveComment));
|
||||||
|
}
|
||||||
|
let resolvePost = this.state.resolveObjectResponse.post;
|
||||||
|
if (resolvePost) {
|
||||||
|
combined.push(this.postViewToCombined(resolvePost));
|
||||||
|
}
|
||||||
|
let resolveCommunity = this.state.resolveObjectResponse.community;
|
||||||
|
if (resolveCommunity) {
|
||||||
|
combined.push(this.communityViewToCombined(resolveCommunity));
|
||||||
|
}
|
||||||
|
let resolveUser = this.state.resolveObjectResponse.person;
|
||||||
|
if (resolveUser) {
|
||||||
|
combined.push(this.personViewSafeToCombined(resolveUser));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push the search results
|
||||||
|
combined.push(
|
||||||
|
...this.state.searchResponse.comments.map(e =>
|
||||||
|
this.commentViewToCombined(e)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
combined.push(
|
||||||
|
...this.state.searchResponse.posts.map(e => this.postViewToCombined(e))
|
||||||
|
);
|
||||||
|
combined.push(
|
||||||
|
...this.state.searchResponse.communities.map(e =>
|
||||||
|
this.communityViewToCombined(e)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
combined.push(
|
||||||
|
...this.state.searchResponse.users.map(e =>
|
||||||
|
this.personViewSafeToCombined(e)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Sort it
|
// Sort it
|
||||||
if (this.state.sort == SortType.New) {
|
if (this.state.sort == SortType.New) {
|
||||||
|
@ -444,7 +511,11 @@ export class Search extends Component<any, SearchState> {
|
||||||
(a.data as PersonViewSafe).counts.comment_score)
|
(a.data as PersonViewSafe).counts.comment_score)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return combined;
|
||||||
|
}
|
||||||
|
|
||||||
|
all() {
|
||||||
|
let combined = this.buildCombined();
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{combined.map(i => (
|
{combined.map(i => (
|
||||||
|
@ -482,9 +553,18 @@ export class Search extends Component<any, SearchState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
comments() {
|
comments() {
|
||||||
|
let comments: CommentView[] = [];
|
||||||
|
|
||||||
|
let resolveComment = this.state.resolveObjectResponse.comment;
|
||||||
|
if (resolveComment) {
|
||||||
|
comments.push(resolveComment);
|
||||||
|
}
|
||||||
|
|
||||||
|
comments.push(...this.state.searchResponse.comments);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CommentNodes
|
<CommentNodes
|
||||||
nodes={commentsToFlatNodes(this.state.searchResponse.comments)}
|
nodes={commentsToFlatNodes(comments)}
|
||||||
locked
|
locked
|
||||||
noIndent
|
noIndent
|
||||||
enableDownvotes={this.state.site.enable_downvotes}
|
enableDownvotes={this.state.site.enable_downvotes}
|
||||||
|
@ -493,9 +573,18 @@ export class Search extends Component<any, SearchState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
posts() {
|
posts() {
|
||||||
|
let posts: PostView[] = [];
|
||||||
|
|
||||||
|
let resolvePost = this.state.resolveObjectResponse.post;
|
||||||
|
if (resolvePost) {
|
||||||
|
posts.push(resolvePost);
|
||||||
|
}
|
||||||
|
|
||||||
|
posts.push(...this.state.searchResponse.posts);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{this.state.searchResponse.posts.map(post => (
|
{posts.map(post => (
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<PostListing
|
<PostListing
|
||||||
|
@ -512,9 +601,17 @@ export class Search extends Component<any, SearchState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
communities() {
|
communities() {
|
||||||
|
let communities: CommunityView[] = [];
|
||||||
|
|
||||||
|
let resolveCommunity = this.state.resolveObjectResponse.community;
|
||||||
|
if (resolveCommunity) {
|
||||||
|
communities.push(resolveCommunity);
|
||||||
|
}
|
||||||
|
|
||||||
|
communities.push(...this.state.searchResponse.communities);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{this.state.searchResponse.communities.map(community => (
|
{communities.map(community => (
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">{this.communityListing(community)}</div>
|
<div class="col-12">{this.communityListing(community)}</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -523,6 +620,26 @@ export class Search extends Component<any, SearchState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
users() {
|
||||||
|
let users: PersonViewSafe[] = [];
|
||||||
|
|
||||||
|
let resolveUser = this.state.resolveObjectResponse.person;
|
||||||
|
if (resolveUser) {
|
||||||
|
users.push(resolveUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
users.push(...this.state.searchResponse.users);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{users.map(user => (
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">{this.userListing(user)}</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
communityListing(community_view: CommunityView) {
|
communityListing(community_view: CommunityView) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -549,18 +666,6 @@ export class Search extends Component<any, SearchState> {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
users() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{this.state.searchResponse.users.map(user => (
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-12">{this.userListing(user)}</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
communityFilter() {
|
communityFilter() {
|
||||||
return (
|
return (
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
|
@ -609,11 +714,17 @@ export class Search extends Component<any, SearchState> {
|
||||||
|
|
||||||
resultsCount(): number {
|
resultsCount(): number {
|
||||||
let res = this.state.searchResponse;
|
let res = this.state.searchResponse;
|
||||||
|
let resObj = this.state.resolveObjectResponse;
|
||||||
|
let resObjCount =
|
||||||
|
resObj.post || resObj.person || resObj.community || resObj.comment
|
||||||
|
? 1
|
||||||
|
: 0;
|
||||||
return (
|
return (
|
||||||
res.posts.length +
|
res.posts.length +
|
||||||
res.comments.length +
|
res.comments.length +
|
||||||
res.communities.length +
|
res.communities.length +
|
||||||
res.users.length
|
res.users.length +
|
||||||
|
resObjCount
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,8 +749,14 @@ export class Search extends Component<any, SearchState> {
|
||||||
form.creator_id = this.state.creatorId;
|
form.creator_id = this.state.creatorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let resolveObjectForm: ResolveObject = {
|
||||||
|
q: this.state.q,
|
||||||
|
auth: authField(false),
|
||||||
|
};
|
||||||
|
|
||||||
if (this.state.q != "") {
|
if (this.state.q != "") {
|
||||||
WebSocketService.Instance.send(wsClient.search(form));
|
WebSocketService.Instance.send(wsClient.search(form));
|
||||||
|
WebSocketService.Instance.send(wsClient.resolveObject(resolveObjectForm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,8 +886,19 @@ export class Search extends Component<any, SearchState> {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
let op = wsUserOp(msg);
|
let op = wsUserOp(msg);
|
||||||
if (msg.error) {
|
if (msg.error) {
|
||||||
|
if (msg.error != "couldnt_find_object") {
|
||||||
toast(i18n.t(msg.error), "danger");
|
toast(i18n.t(msg.error), "danger");
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
resolveObjectResponse: {
|
||||||
|
comment: null,
|
||||||
|
community: null,
|
||||||
|
person: null,
|
||||||
|
post: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (op == UserOperation.Search) {
|
} else if (op == UserOperation.Search) {
|
||||||
let data = wsJsonToRes<SearchResponse>(msg).data;
|
let data = wsJsonToRes<SearchResponse>(msg).data;
|
||||||
this.state.searchResponse = data;
|
this.state.searchResponse = data;
|
||||||
|
@ -794,6 +922,10 @@ export class Search extends Component<any, SearchState> {
|
||||||
this.state.communities = data.communities;
|
this.state.communities = data.communities;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
this.setupCommunityFilter();
|
this.setupCommunityFilter();
|
||||||
|
} else if (op == UserOperation.ResolveObject) {
|
||||||
|
let data = wsJsonToRes<ResolveObjectResponse>(msg).data;
|
||||||
|
this.state.resolveObjectResponse = data;
|
||||||
|
this.setState(this.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4664,10 +4664,10 @@ lcid@^1.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
invert-kv "^1.0.0"
|
invert-kv "^1.0.0"
|
||||||
|
|
||||||
lemmy-js-client@0.11.4-rc.14:
|
lemmy-js-client@0.11.4-rc.16:
|
||||||
version "0.11.4-rc.14"
|
version "0.11.4-rc.16"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.4-rc.14.tgz#dcac5b8dc78c3b04e6b3630ff9351a94aa73e109"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.4-rc.16.tgz#bd8a4a714d5dcfbd9640bc419fd412443be6ab44"
|
||||||
integrity sha512-R8M+myyriNQljQlTweVqtUKGBpgmaM7RI4ebYb7N7sYr5Bk5Ip6v2qTNvKAV6BlsDOCTWANOonfeoz/cIerLEg==
|
integrity sha512-EQ2tB6AqSZG9UDcKf6bmCzNe92ZwTXhddJfCK2yGZ5PdHADkVrQf05yEuMZjYt3cooSHjupj6hWO9InnPMIUfA==
|
||||||
|
|
||||||
levn@^0.4.1:
|
levn@^0.4.1:
|
||||||
version "0.4.1"
|
version "0.4.1"
|
||||||
|
|
Loading…
Reference in a new issue