mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-26 06:11:15 +00:00
Adding listing_type to search. #143
This commit is contained in:
parent
965a9d8d2f
commit
331861b247
11 changed files with 62 additions and 18 deletions
|
@ -68,7 +68,7 @@
|
||||||
"eslint-plugin-prettier": "^3.3.1",
|
"eslint-plugin-prettier": "^3.3.1",
|
||||||
"husky": "^6.0.0",
|
"husky": "^6.0.0",
|
||||||
"iso-639-1": "^2.1.9",
|
"iso-639-1": "^2.1.9",
|
||||||
"lemmy-js-client": "0.11.0-rc.6",
|
"lemmy-js-client": "0.11.0-rc.8",
|
||||||
"lint-staged": "^10.5.4",
|
"lint-staged": "^10.5.4",
|
||||||
"mini-css-extract-plugin": "^1.4.1",
|
"mini-css-extract-plugin": "^1.4.1",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
|
|
|
@ -273,7 +273,7 @@ export class Communities extends Component<any, CommunitiesState> {
|
||||||
handleSearchSubmit(i: Communities) {
|
handleSearchSubmit(i: Communities) {
|
||||||
const searchParamEncoded = encodeURIComponent(i.state.searchText);
|
const searchParamEncoded = encodeURIComponent(i.state.searchText);
|
||||||
i.context.router.history.push(
|
i.context.router.history.push(
|
||||||
`/search/q/${searchParamEncoded}/type/Communities/sort/TopAll/page/1`
|
`/search/q/${searchParamEncoded}/type/Communities/sort/TopAll/listing_type/All/page/1`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ import {
|
||||||
authField,
|
authField,
|
||||||
saveScrollPosition,
|
saveScrollPosition,
|
||||||
restoreScrollPosition,
|
restoreScrollPosition,
|
||||||
|
showLocal,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
import { i18n } from "../i18next";
|
import { i18n } from "../i18next";
|
||||||
import { T } from "inferno-i18next";
|
import { T } from "inferno-i18next";
|
||||||
|
@ -588,7 +589,7 @@ export class Main extends Component<any, MainState> {
|
||||||
<span class="mr-3">
|
<span class="mr-3">
|
||||||
<ListingTypeSelect
|
<ListingTypeSelect
|
||||||
type_={this.state.listingType}
|
type_={this.state.listingType}
|
||||||
showLocal={this.showLocal}
|
showLocal={showLocal(this.isoData)}
|
||||||
onChange={this.handleListingTypeChange}
|
onChange={this.handleListingTypeChange}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
@ -650,10 +651,6 @@ export class Main extends Component<any, MainState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get showLocal(): boolean {
|
|
||||||
return this.isoData.site_res.federated_instances?.linked.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
get canAdmin(): boolean {
|
get canAdmin(): boolean {
|
||||||
return (
|
return (
|
||||||
UserService.Instance.localUserView &&
|
UserService.Instance.localUserView &&
|
||||||
|
|
|
@ -134,7 +134,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
|
||||||
} else {
|
} else {
|
||||||
const searchParamEncoded = encodeURIComponent(searchParam);
|
const searchParamEncoded = encodeURIComponent(searchParam);
|
||||||
this.context.router.history.push(
|
this.context.router.history.push(
|
||||||
`/search/q/${searchParamEncoded}/type/All/sort/TopAll/page/1`
|
`/search/q/${searchParamEncoded}/type/All/sort/TopAll/listing_type/All/page/1`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ import {
|
||||||
setOptionalAuth,
|
setOptionalAuth,
|
||||||
saveScrollPosition,
|
saveScrollPosition,
|
||||||
restoreScrollPosition,
|
restoreScrollPosition,
|
||||||
|
showLocal,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
import { PersonListing } from "./person-listing";
|
import { PersonListing } from "./person-listing";
|
||||||
import { HtmlTags } from "./html-tags";
|
import { HtmlTags } from "./html-tags";
|
||||||
|
@ -655,9 +656,7 @@ export class Person extends Component<any, PersonState> {
|
||||||
this.state.saveUserSettingsForm.default_listing_type
|
this.state.saveUserSettingsForm.default_listing_type
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
showLocal={
|
showLocal={showLocal(this.isoData)}
|
||||||
this.state.siteRes.federated_instances?.linked.length > 0
|
|
||||||
}
|
|
||||||
onChange={this.handleUserSettingsListingTypeChange}
|
onChange={this.handleUserSettingsListingTypeChange}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
Search,
|
Search,
|
||||||
SearchType,
|
SearchType,
|
||||||
SearchResponse,
|
SearchResponse,
|
||||||
|
ListingType,
|
||||||
} from "lemmy-js-client";
|
} from "lemmy-js-client";
|
||||||
import { WebSocketService, UserService } from "../services";
|
import { WebSocketService, UserService } from "../services";
|
||||||
import { PostFormParams } from "../interfaces";
|
import { PostFormParams } from "../interfaces";
|
||||||
|
@ -406,6 +407,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
q: this.state.postForm.url,
|
q: this.state.postForm.url,
|
||||||
type_: SearchType.Url,
|
type_: SearchType.Url,
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
|
listing_type: ListingType.All,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 6,
|
limit: 6,
|
||||||
auth: authField(false),
|
auth: authField(false),
|
||||||
|
@ -435,6 +437,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
q: this.state.postForm.name,
|
q: this.state.postForm.name,
|
||||||
type_: SearchType.Posts,
|
type_: SearchType.Posts,
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
|
listing_type: ListingType.All,
|
||||||
community_id: this.state.postForm.community_id,
|
community_id: this.state.postForm.community_id,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 6,
|
limit: 6,
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
SearchResponse,
|
SearchResponse,
|
||||||
GetSiteResponse,
|
GetSiteResponse,
|
||||||
GetCommunityResponse,
|
GetCommunityResponse,
|
||||||
|
ListingType,
|
||||||
} from "lemmy-js-client";
|
} from "lemmy-js-client";
|
||||||
import {
|
import {
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
|
@ -132,6 +133,7 @@ export class Post extends Component<any, PostState> {
|
||||||
q: this.state.postRes.post_view.post.url,
|
q: this.state.postRes.post_view.post.url,
|
||||||
type_: SearchType.Url,
|
type_: SearchType.Url,
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
|
listing_type: ListingType.All,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 6,
|
limit: 6,
|
||||||
auth: authField(false),
|
auth: authField(false),
|
||||||
|
|
|
@ -13,6 +13,7 @@ import {
|
||||||
PostResponse,
|
PostResponse,
|
||||||
CommentResponse,
|
CommentResponse,
|
||||||
Site,
|
Site,
|
||||||
|
ListingType,
|
||||||
} from "lemmy-js-client";
|
} from "lemmy-js-client";
|
||||||
import { WebSocketService } from "../services";
|
import { WebSocketService } from "../services";
|
||||||
import {
|
import {
|
||||||
|
@ -32,6 +33,8 @@ import {
|
||||||
setOptionalAuth,
|
setOptionalAuth,
|
||||||
saveScrollPosition,
|
saveScrollPosition,
|
||||||
restoreScrollPosition,
|
restoreScrollPosition,
|
||||||
|
routeListingTypeToEnum,
|
||||||
|
showLocal,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
import { PostListing } from "./post-listing";
|
import { PostListing } from "./post-listing";
|
||||||
import { HtmlTags } from "./html-tags";
|
import { HtmlTags } from "./html-tags";
|
||||||
|
@ -39,6 +42,7 @@ import { Spinner } from "./icon";
|
||||||
import { PersonListing } from "./person-listing";
|
import { PersonListing } from "./person-listing";
|
||||||
import { CommunityLink } from "./community-link";
|
import { CommunityLink } from "./community-link";
|
||||||
import { SortSelect } from "./sort-select";
|
import { SortSelect } from "./sort-select";
|
||||||
|
import { ListingTypeSelect } from "./listing-type-select";
|
||||||
import { CommentNodes } from "./comment-nodes";
|
import { CommentNodes } from "./comment-nodes";
|
||||||
import { i18n } from "../i18next";
|
import { i18n } from "../i18next";
|
||||||
import { InitialFetchRequest } from "shared/interfaces";
|
import { InitialFetchRequest } from "shared/interfaces";
|
||||||
|
@ -47,6 +51,7 @@ interface SearchProps {
|
||||||
q: string;
|
q: string;
|
||||||
type_: SearchType;
|
type_: SearchType;
|
||||||
sort: SortType;
|
sort: SortType;
|
||||||
|
listingType: ListingType;
|
||||||
page: number;
|
page: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +59,7 @@ interface SearchState {
|
||||||
q: string;
|
q: string;
|
||||||
type_: SearchType;
|
type_: SearchType;
|
||||||
sort: SortType;
|
sort: SortType;
|
||||||
|
listingType: ListingType;
|
||||||
page: number;
|
page: number;
|
||||||
searchResponse: SearchResponse;
|
searchResponse: SearchResponse;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
@ -65,6 +71,7 @@ interface UrlParams {
|
||||||
q?: string;
|
q?: string;
|
||||||
type_?: SearchType;
|
type_?: SearchType;
|
||||||
sort?: SortType;
|
sort?: SortType;
|
||||||
|
listingType?: ListingType;
|
||||||
page?: number;
|
page?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +82,9 @@ export class Search extends Component<any, SearchState> {
|
||||||
q: Search.getSearchQueryFromProps(this.props.match.params.q),
|
q: Search.getSearchQueryFromProps(this.props.match.params.q),
|
||||||
type_: Search.getSearchTypeFromProps(this.props.match.params.type),
|
type_: Search.getSearchTypeFromProps(this.props.match.params.type),
|
||||||
sort: Search.getSortTypeFromProps(this.props.match.params.sort),
|
sort: Search.getSortTypeFromProps(this.props.match.params.sort),
|
||||||
|
listingType: Search.getListingTypeFromProps(
|
||||||
|
this.props.match.params.listing_type
|
||||||
|
),
|
||||||
page: Search.getPageFromProps(this.props.match.params.page),
|
page: Search.getPageFromProps(this.props.match.params.page),
|
||||||
searchText: Search.getSearchQueryFromProps(this.props.match.params.q),
|
searchText: Search.getSearchQueryFromProps(this.props.match.params.q),
|
||||||
searchResponse: {
|
searchResponse: {
|
||||||
|
@ -100,6 +110,10 @@ export class Search extends Component<any, SearchState> {
|
||||||
return sort ? routeSortTypeToEnum(sort) : SortType.TopAll;
|
return sort ? routeSortTypeToEnum(sort) : SortType.TopAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getListingTypeFromProps(listingType: string): ListingType {
|
||||||
|
return listingType ? routeListingTypeToEnum(listingType) : ListingType.All;
|
||||||
|
}
|
||||||
|
|
||||||
static getPageFromProps(page: string): number {
|
static getPageFromProps(page: string): number {
|
||||||
return page ? Number(page) : 1;
|
return page ? Number(page) : 1;
|
||||||
}
|
}
|
||||||
|
@ -109,6 +123,7 @@ export class Search extends Component<any, SearchState> {
|
||||||
|
|
||||||
this.state = this.emptyState;
|
this.state = this.emptyState;
|
||||||
this.handleSortChange = this.handleSortChange.bind(this);
|
this.handleSortChange = this.handleSortChange.bind(this);
|
||||||
|
this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
|
||||||
|
|
||||||
this.parseMessage = this.parseMessage.bind(this);
|
this.parseMessage = this.parseMessage.bind(this);
|
||||||
this.subscription = wsSubscribe(this.parseMessage);
|
this.subscription = wsSubscribe(this.parseMessage);
|
||||||
|
@ -134,6 +149,9 @@ export class Search extends Component<any, SearchState> {
|
||||||
q: Search.getSearchQueryFromProps(props.match.params.q),
|
q: Search.getSearchQueryFromProps(props.match.params.q),
|
||||||
type_: Search.getSearchTypeFromProps(props.match.params.type),
|
type_: Search.getSearchTypeFromProps(props.match.params.type),
|
||||||
sort: Search.getSortTypeFromProps(props.match.params.sort),
|
sort: Search.getSortTypeFromProps(props.match.params.sort),
|
||||||
|
listingType: Search.getListingTypeFromProps(
|
||||||
|
props.match.params.listing_type
|
||||||
|
),
|
||||||
page: Search.getPageFromProps(props.match.params.page),
|
page: Search.getPageFromProps(props.match.params.page),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -146,7 +164,8 @@ export class Search extends Component<any, SearchState> {
|
||||||
q: this.getSearchQueryFromProps(pathSplit[3]),
|
q: this.getSearchQueryFromProps(pathSplit[3]),
|
||||||
type_: this.getSearchTypeFromProps(pathSplit[5]),
|
type_: this.getSearchTypeFromProps(pathSplit[5]),
|
||||||
sort: this.getSortTypeFromProps(pathSplit[7]),
|
sort: this.getSortTypeFromProps(pathSplit[7]),
|
||||||
page: this.getPageFromProps(pathSplit[9]),
|
listing_type: this.getListingTypeFromProps(pathSplit[9]),
|
||||||
|
page: this.getPageFromProps(pathSplit[11]),
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
};
|
};
|
||||||
setOptionalAuth(form, req.auth);
|
setOptionalAuth(form, req.auth);
|
||||||
|
@ -163,6 +182,7 @@ export class Search extends Component<any, SearchState> {
|
||||||
lastState.q !== this.state.q ||
|
lastState.q !== this.state.q ||
|
||||||
lastState.type_ !== this.state.type_ ||
|
lastState.type_ !== this.state.type_ ||
|
||||||
lastState.sort !== this.state.sort ||
|
lastState.sort !== this.state.sort ||
|
||||||
|
lastState.listingType !== this.state.listingType ||
|
||||||
lastState.page !== this.state.page
|
lastState.page !== this.state.page
|
||||||
) {
|
) {
|
||||||
this.setState({ loading: true, searchText: this.state.q });
|
this.setState({ loading: true, searchText: this.state.q });
|
||||||
|
@ -242,6 +262,13 @@ export class Search extends Component<any, SearchState> {
|
||||||
</option>
|
</option>
|
||||||
<option value={SearchType.Users}>{i18n.t("users")}</option>
|
<option value={SearchType.Users}>{i18n.t("users")}</option>
|
||||||
</select>
|
</select>
|
||||||
|
<span class="ml-2">
|
||||||
|
<ListingTypeSelect
|
||||||
|
type_={this.state.listingType}
|
||||||
|
showLocal={showLocal(this.isoData)}
|
||||||
|
onChange={this.handleListingTypeChange}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
<span class="ml-2">
|
<span class="ml-2">
|
||||||
<SortSelect
|
<SortSelect
|
||||||
sort={this.state.sort}
|
sort={this.state.sort}
|
||||||
|
@ -460,6 +487,7 @@ export class Search extends Component<any, SearchState> {
|
||||||
q: this.state.q,
|
q: this.state.q,
|
||||||
type_: this.state.type_,
|
type_: this.state.type_,
|
||||||
sort: this.state.sort,
|
sort: this.state.sort,
|
||||||
|
listing_type: this.state.listingType,
|
||||||
page: this.state.page,
|
page: this.state.page,
|
||||||
limit: fetchLimit,
|
limit: fetchLimit,
|
||||||
auth: authField(false),
|
auth: authField(false),
|
||||||
|
@ -481,11 +509,19 @@ export class Search extends Component<any, SearchState> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleListingTypeChange(val: ListingType) {
|
||||||
|
this.updateUrl({
|
||||||
|
listingType: val,
|
||||||
|
page: 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
handleSearchSubmit(i: Search, event: any) {
|
handleSearchSubmit(i: Search, event: any) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
i.updateUrl({
|
i.updateUrl({
|
||||||
q: i.state.searchText,
|
q: i.state.searchText,
|
||||||
type_: i.state.type_,
|
type_: i.state.type_,
|
||||||
|
listingType: i.state.listingType,
|
||||||
sort: i.state.sort,
|
sort: i.state.sort,
|
||||||
page: i.state.page,
|
page: i.state.page,
|
||||||
});
|
});
|
||||||
|
@ -499,10 +535,11 @@ export class Search extends Component<any, SearchState> {
|
||||||
const qStr = paramUpdates.q || this.state.q;
|
const qStr = paramUpdates.q || this.state.q;
|
||||||
const qStrEncoded = encodeURIComponent(qStr);
|
const qStrEncoded = encodeURIComponent(qStr);
|
||||||
const typeStr = paramUpdates.type_ || this.state.type_;
|
const typeStr = paramUpdates.type_ || this.state.type_;
|
||||||
|
const listingTypeStr = paramUpdates.listingType || this.state.listingType;
|
||||||
const sortStr = paramUpdates.sort || this.state.sort;
|
const sortStr = paramUpdates.sort || this.state.sort;
|
||||||
const page = paramUpdates.page || this.state.page;
|
const page = paramUpdates.page || this.state.page;
|
||||||
this.props.history.push(
|
this.props.history.push(
|
||||||
`/search/q/${qStrEncoded}/type/${typeStr}/sort/${sortStr}/page/${page}`
|
`/search/q/${qStrEncoded}/type/${typeStr}/sort/${sortStr}/listing_type/${listingTypeStr}/page/${page}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ export const routes: IRoutePropsWithFetch[] = [
|
||||||
fetchInitialData: req => AdminSettings.fetchInitialData(req),
|
fetchInitialData: req => AdminSettings.fetchInitialData(req),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: `/search/q/:q/type/:type/sort/:sort/page/:page`,
|
path: `/search/q/:q/type/:type/sort/:sort/listing_type/:listing_type/page/:page`,
|
||||||
component: Search,
|
component: Search,
|
||||||
fetchInitialData: req => Search.fetchInitialData(req),
|
fetchInitialData: req => Search.fetchInitialData(req),
|
||||||
},
|
},
|
||||||
|
|
|
@ -747,6 +747,7 @@ function personSearch(text: string, cb: (persons: PersonTribute[]) => any) {
|
||||||
q: text,
|
q: text,
|
||||||
type_: SearchType.Users,
|
type_: SearchType.Users,
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
|
listing_type: ListingType.All,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: mentionDropdownFetchLimit,
|
limit: mentionDropdownFetchLimit,
|
||||||
auth: authField(false),
|
auth: authField(false),
|
||||||
|
@ -792,6 +793,7 @@ function communitySearch(
|
||||||
q: text,
|
q: text,
|
||||||
type_: SearchType.Communities,
|
type_: SearchType.Communities,
|
||||||
sort: SortType.TopAll,
|
sort: SortType.TopAll,
|
||||||
|
listing_type: ListingType.All,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: mentionDropdownFetchLimit,
|
limit: mentionDropdownFetchLimit,
|
||||||
auth: authField(false),
|
auth: authField(false),
|
||||||
|
@ -1226,3 +1228,7 @@ export function restoreScrollPosition(context: any) {
|
||||||
let y = Number(sessionStorage.getItem(`scrollPosition_${path}`));
|
let y = Number(sessionStorage.getItem(`scrollPosition_${path}`));
|
||||||
window.scrollTo(0, y);
|
window.scrollTo(0, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function showLocal(isoData: IsoData): boolean {
|
||||||
|
return isoData.site_res.federated_instances?.linked.length > 0;
|
||||||
|
}
|
||||||
|
|
|
@ -5125,10 +5125,10 @@ lcid@^1.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
invert-kv "^1.0.0"
|
invert-kv "^1.0.0"
|
||||||
|
|
||||||
lemmy-js-client@0.11.0-rc.6:
|
lemmy-js-client@0.11.0-rc.8:
|
||||||
version "0.11.0-rc.6"
|
version "0.11.0-rc.8"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.0-rc.6.tgz#897671c8e24be8ba2a6074efc63264c421969380"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.0-rc.8.tgz#d3b15b7233cf0cd493c5d8a3c8a588b9ce0c2663"
|
||||||
integrity sha512-/AIws5bidcNIi8wSzJx7mwo5Ip2u78s4/bMdEyfEqWKWqdNwEKV/6eYnyThA3j9gYXjd8ty731s0l0kSs/vmhA==
|
integrity sha512-YlG0bkJuWEkBdCoS5RROxz7RyE0zgsTt0emiNTYdE8vFLr3DBPha/19Rzccx8Ewc7ohH35w8gg3XDejcrK0tqw==
|
||||||
|
|
||||||
levn@^0.4.1:
|
levn@^0.4.1:
|
||||||
version "0.4.1"
|
version "0.4.1"
|
||||||
|
|
Loading…
Reference in a new issue