]> Untitled Git - lemmy.git/blobdiff - ui/src/components/sort-select.tsx
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / ui / src / components / sort-select.tsx
index 5515f746c7dcfed3364fccf070601c599ca6f40a..1f0fb055716a0d2202c24a2345ee9e014355875a 100644 (file)
@@ -1,5 +1,6 @@
 import { Component, linkEvent } from 'inferno';
-import { SortType } from '../interfaces';
+import { SortType } from 'lemmy-js-client';
+import { sortingHelpUrl, randomStr } from '../utils';
 import { i18n } from '../i18next';
 
 interface SortSelectProps {
@@ -13,6 +14,7 @@ interface SortSelectState {
 }
 
 export class SortSelect extends Component<SortSelectProps, SortSelectState> {
+  private id = `sort-select-${randomStr()}`;
   private emptyState: SortSelectState = {
     sort: this.props.sort,
   };
@@ -22,31 +24,53 @@ export class SortSelect extends Component<SortSelectProps, SortSelectState> {
     this.state = this.emptyState;
   }
 
+  static getDerivedStateFromProps(props: any): SortSelectState {
+    return {
+      sort: props.sort,
+    };
+  }
+
   render() {
     return (
-      <select
-        value={this.state.sort}
-        onChange={linkEvent(this, this.handleSortChange)}
-        class="custom-select custom-select-sm w-auto"
-      >
-        <option disabled>{i18n.t('sort_type')}</option>
-        {!this.props.hideHot && (
-          <option value={SortType.Hot}>{i18n.t('hot')}</option>
-        )}
-        <option value={SortType.New}>{i18n.t('new')}</option>
-        <option disabled>─────</option>
-        <option value={SortType.TopDay}>{i18n.t('top_day')}</option>
-        <option value={SortType.TopWeek}>{i18n.t('week')}</option>
-        <option value={SortType.TopMonth}>{i18n.t('month')}</option>
-        <option value={SortType.TopYear}>{i18n.t('year')}</option>
-        <option value={SortType.TopAll}>{i18n.t('all')}</option>
-      </select>
+      <>
+        <select
+          id={this.id}
+          name={this.id}
+          value={this.state.sort}
+          onChange={linkEvent(this, this.handleSortChange)}
+          class="custom-select w-auto mr-2 mb-2"
+        >
+          <option disabled>{i18n.t('sort_type')}</option>
+          {!this.props.hideHot && (
+            <>
+              <option value={SortType.Active}>{i18n.t('active')}</option>
+              <option value={SortType.Hot}>{i18n.t('hot')}</option>
+            </>
+          )}
+          <option value={SortType.New}>{i18n.t('new')}</option>
+          <option disabled>─────</option>
+          <option value={SortType.TopDay}>{i18n.t('top_day')}</option>
+          <option value={SortType.TopWeek}>{i18n.t('week')}</option>
+          <option value={SortType.TopMonth}>{i18n.t('month')}</option>
+          <option value={SortType.TopYear}>{i18n.t('year')}</option>
+          <option value={SortType.TopAll}>{i18n.t('all')}</option>
+        </select>
+        <a
+          className="text-muted"
+          href={sortingHelpUrl}
+          target="_blank"
+          rel="noopener"
+          title={i18n.t('sorting_help')}
+        >
+          <svg class={`icon icon-inline`}>
+            <use xlinkHref="#icon-help-circle"></use>
+          </svg>
+        </a>
+      </>
     );
   }
 
   handleSortChange(i: SortSelect, event: any) {
-    i.state.sort = Number(event.target.value);
-    i.setState(i.state);
-    i.props.onChange(i.state.sort);
+    i.props.onChange(event.target.value);
   }
 }