From: Dessalines Date: Sat, 23 Jan 2021 23:07:02 +0000 (-0500) Subject: Add search field to communities page. Fixes #118 X-Git-Url: http://these/git/%7B%60%24%7Bdocument.location.origin%7D/feeds/%7Burl%7D?a=commitdiff_plain;h=94e36ad7573b4f186716abfaa264d2b22ce8dd52;p=lemmy-ui.git Add search field to communities page. Fixes #118 --- diff --git a/src/shared/components/communities.tsx b/src/shared/components/communities.tsx index 236f777..b3d288a 100644 --- a/src/shared/components/communities.tsx +++ b/src/shared/components/communities.tsx @@ -35,6 +35,7 @@ interface CommunitiesState { page: number; loading: boolean; site_view: SiteView; + searchText: string; } interface CommunitiesProps { @@ -49,6 +50,7 @@ export class Communities extends Component { loading: true, page: getPageFromProps(this.props), site_view: this.isoData.site_res.site_view, + searchText: '', }; constructor(props: any, context: any) { @@ -108,7 +110,15 @@ export class Communities extends Component { ) : (
-
{i18n.t('list_of_communities')}
+
+
+

{i18n.t('list_of_communities')}

+
+
+
{this.searchForm()}
+
+
+
@@ -174,6 +184,28 @@ export class Communities extends Component { ); } + searchForm() { + return ( +
+ + + + ); + } + paginator() { return (
@@ -229,6 +261,17 @@ export class Communities extends Component { WebSocketService.Instance.send(wsClient.followCommunity(form)); } + handleSearchChange(i: Communities, event: any) { + i.setState({ searchText: event.target.value }); + } + + handleSearchSubmit(i: Communities) { + const searchParamEncoded = encodeURIComponent(i.state.searchText); + i.context.router.history.push( + `/search/q/${searchParamEncoded}/type/Communities/sort/TopAll/page/1` + ); + } + refetch() { let listCommunitiesForm: ListCommunities = { sort: SortType.TopAll,