X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Fpages%2FTechniques.js;h=c2d7aec80627aaec51f6344d113ecbfccb55530d;hb=9e08a6086d2c982ec9a2b9b79e3441ac8347f695;hp=c206a31b6fbb9bd33252054e977369b008667a15;hpb=a655f476292d8081a23653fc1b9228f4fb64faa4;p=alttp.git
diff --git a/resources/js/components/pages/Techniques.js b/resources/js/components/pages/Techniques.js
index c206a31..c2d7aec 100644
--- a/resources/js/components/pages/Techniques.js
+++ b/resources/js/components/pages/Techniques.js
@@ -1,8 +1,11 @@
import axios from 'axios';
+import PropTypes from 'prop-types';
import React from 'react';
+import { Helmet } from 'react-helmet';
import { withTranslation } from 'react-i18next';
import NotFound from './NotFound';
+import CanonicalLinks from '../common/CanonicalLinks';
import ErrorBoundary from '../common/ErrorBoundary';
import ErrorMessage from '../common/ErrorMessage';
import Loading from '../common/Loading';
@@ -10,20 +13,34 @@ import Overview from '../techniques/Overview';
import { compareTranslation } from '../../helpers/Technique';
import i18n from '../../i18n';
-const Techniques = () => {
+const Techniques = ({ namespace, type }) => {
const [error, setError] = React.useState(null);
+ const [filter, setFilter] = React.useState({});
const [loading, setLoading] = React.useState(true);
const [techniques, setTechniques] = React.useState([]);
+ React.useEffect(() => {
+ const savedFilter = localStorage.getItem(`content.filter.${type}`);
+ if (savedFilter) {
+ setFilter(JSON.parse(savedFilter));
+ } else {
+ setFilter(filter => filter ? {} : filter);
+ }
+ }, [type]);
+
+ const updateFilter = React.useCallback(newFilter => {
+ localStorage.setItem(`content.filter.${type}`, JSON.stringify(newFilter));
+ setFilter(newFilter);
+ }, [type]);
+
React.useEffect(() => {
const ctrl = new AbortController();
- setLoading(true);
- window.document.title = i18n.t('techniques.heading');
+ if (!techniques.length) {
+ setLoading(true);
+ }
axios
- .get(`/api/tech`, {
- params: {
- type: 'tech',
- },
+ .get(`/api/pages/${type}`, {
+ params: filter,
signal: ctrl.signal
})
.then(response => {
@@ -32,19 +49,20 @@ const Techniques = () => {
setTechniques(response.data.sort(compareTranslation('title', i18n.language)));
})
.catch(error => {
- setError(error);
- setLoading(false);
- setTechniques([]);
+ if (!axios.isCancel(error)) {
+ setError(error);
+ setLoading(false);
+ setTechniques([]);
+ }
});
return () => {
ctrl.abort();
};
- }, []);
+ }, [filter, namespace, type]);
React.useEffect(() => {
- window.document.title = i18n.t('techniques.heading');
setTechniques(t => [...t].sort(compareTranslation('title', i18n.language)));
- }, [i18n.language]);
+ }, [namespace, i18n.language]);
if (loading) {
return ;
@@ -59,8 +77,24 @@ const Techniques = () => {
}
return
-
+
+ {i18n.t(`${namespace}.heading`)}
+
+
+
+
;
};
+Techniques.propTypes = {
+ namespace: PropTypes.string,
+ type: PropTypes.string,
+};
+
export default withTranslation()(Techniques);