+import axios from 'axios';
+import React from 'react';
+import { withTranslation } from 'react-i18next';
+
+import NotFound from './NotFound';
+import ErrorBoundary from '../common/ErrorBoundary';
+import ErrorMessage from '../common/ErrorMessage';
+import Loading from '../common/Loading';
+import Overview from '../techniques/Overview';
+import { compareTranslation } from '../../helpers/Technique';
+import i18n from '../../i18n';
+
+const Techniques = () => {
+ const [error, setError] = React.useState(null);
+ const [loading, setLoading] = React.useState(true);
+ const [techniques, setTechniques] = React.useState([]);
+
+ React.useEffect(() => {
+ const ctrl = new AbortController();
+ setLoading(true);
+ window.document.title = i18n.t('techniques.heading');
+ axios
+ .get(`/api/tech`, { signal: ctrl.signal })
+ .then(response => {
+ setError(null);
+ setLoading(false);
+ setTechniques(response.data.sort(compareTranslation('title', i18n.language)));
+ })
+ .catch(error => {
+ setError(error);
+ setLoading(false);
+ setTechniques([]);
+ });
+ return () => {
+ ctrl.abort();
+ };
+ }, []);
+
+ React.useEffect(() => {
+ window.document.title = i18n.t('techniques.heading');
+ setTechniques(t => [...t].sort(compareTranslation('title', i18n.language)));
+ }, [i18n.language]);
+
+ if (loading) {
+ return <Loading />;
+ }
+
+ if (error) {
+ return <ErrorMessage error={error} />;
+ }
+
+ if (!techniques || !techniques.length) {
+ return <NotFound />;
+ }
+
+ return <ErrorBoundary>
+ <Overview techniques={techniques} />
+ </ErrorBoundary>;
+};
+
+export default withTranslation()(Techniques);