]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/pages/Technique.js
add simple doors tracker
[alttp.git] / resources / js / components / pages / Technique.js
index aabb8d0780db86a73be7e50133fe66ac2a66d7c8..4004707895ad23dc18607e1af5a1758c2b01e3fa 100644 (file)
@@ -1,18 +1,20 @@
 import axios from 'axios';
+import PropTypes from 'prop-types';
 import React, { useEffect, useState } from 'react';
 import { Helmet } from 'react-helmet';
 import { withTranslation } from 'react-i18next';
 import { useParams } from 'react-router-dom';
 
+import CanonicalLinks from '../common/CanonicalLinks';
 import ErrorBoundary from '../common/ErrorBoundary';
 import ErrorMessage from '../common/ErrorMessage';
 import Loading from '../common/Loading';
 import NotFound from '../pages/NotFound';
 import Detail from '../techniques/Detail';
-import { getLanguages, getTranslation } from '../../helpers/Technique';
+import { getLanguages, getMatchedLocale, getTranslation } from '../../helpers/Technique';
 import i18n from '../../i18n';
 
-const Technique = () => {
+const Technique = ({ type }) => {
        const params = useParams();
        const { name } = params;
 
@@ -24,7 +26,7 @@ const Technique = () => {
                const ctrl = new AbortController();
                setLoading(true);
                axios
-                       .get(`/api/tech/${name}`, { signal: ctrl.signal })
+                       .get(`/api/pages/${type}/${name}`, { signal: ctrl.signal })
                        .then(response => {
                                setError(null);
                                setLoading(false);
@@ -38,7 +40,7 @@ const Technique = () => {
                return () => {
                        ctrl.abort();
                };
-       }, [name]);
+       }, [name, type]);
 
        if (loading) {
                return <Loading />;
@@ -56,22 +58,18 @@ const Technique = () => {
                <Helmet>
                        <title>{getTranslation(technique, 'title', i18n.language)}</title>
                        <meta name="description" content={getTranslation(technique, 'short', i18n.language)} />
-                       <link
-                               href={`https://alttp.localhorst.tv/tech/${technique.name}`}
-                               hrefLang="x-default"
-                               rel="alternate"
-                       />
-                       {getLanguages(technique).map(l =>
-                               <link
-                                       key={l}
-                                       href={`https://alttp.localhorst.tv/tech/${technique.name}?lng=${l}`}
-                                       hrefLang={l}
-                                       rel="alternate"
-                               />
-                       )}
                </Helmet>
+               <CanonicalLinks
+                       base={`/tech/${technique.name}`}
+                       lang={getMatchedLocale(technique, i18n.language)}
+                       langs={getLanguages(technique)}
+               />
                <Detail technique={technique} />
        </ErrorBoundary>;
 };
 
+Technique.propTypes = {
+       type: PropTypes.string,
+};
+
 export default withTranslation()(Technique);