X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=resources%2Fjs%2Fcomponents%2Fpages%2FTechnique.js;h=a24b8797ae560ae8d845ecf46dc279d435d6db37;hb=d8ca13d8ccb5efe181198d0e5243a26c9f807aa1;hp=8c202ed44ad1fce81a80e4b1f89e16481eff8944;hpb=a94dda65a823a1f191ffbc3981448adfae270fcc;p=alttp.git
diff --git a/resources/js/components/pages/Technique.js b/resources/js/components/pages/Technique.js
index 8c202ed..a24b879 100644
--- a/resources/js/components/pages/Technique.js
+++ b/resources/js/components/pages/Technique.js
@@ -1,29 +1,63 @@
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 toastr from 'toastr';
+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 { getTranslation } from '../../helpers/Technique';
+import Dialog from '../techniques/Dialog';
+import {
+ mayEditContent,
+} from '../../helpers/permissions';
+import { getLanguages, getMatchedLocale, getTranslation } from '../../helpers/Technique';
+import { useUser } from '../../helpers/UserContext';
import i18n from '../../i18n';
-const Technique = () => {
+const Technique = ({ basepath, type }) => {
const params = useParams();
const { name } = params;
+ const user = useUser();
const [error, setError] = useState(null);
const [loading, setLoading] = useState(true);
const [technique, setTechnique] = useState(null);
+ const [editContent, setEditContent] = useState(null);
+ const [showContentDialog, setShowContentDialog] = useState(false);
+
+ const actions = React.useMemo(() => ({
+ editContent: mayEditContent(user) ? content => {
+ setEditContent(content);
+ setShowContentDialog(true);
+ } : null,
+ }), [user]);
+
+ const saveContent = React.useCallback(async values => {
+ try {
+ const response = await axios.put(`/api/content/${values.id}`, {
+ parent_id: technique.id,
+ ...values,
+ });
+ toastr.success(i18n.t('content.saveSuccess'));
+ setTechnique(response.data);
+ setShowContentDialog(false);
+ } catch (e) {
+ toastr.error(i18n.t('content.saveError'));
+ }
+ }, [technique && technique.id]);
+
useEffect(() => {
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);
@@ -37,13 +71,7 @@ const Technique = () => {
return () => {
ctrl.abort();
};
- }, [name]);
-
- useEffect(() => {
- if (technique) {
- window.document.title = getTranslation(technique, 'title', i18n.language);
- }
- }, [technique, i18n.language]);
+ }, [name, type]);
if (loading) {
return ;
@@ -58,8 +86,37 @@ const Technique = () => {
}
return
-
+
+ {getTranslation(technique, 'title', i18n.language)}
+
+
+ {technique.image ?
+
+
+ : null}
+ {!technique.image && technique.gif ?
+
+
+ : null}
+
+
+ ;
};
+Technique.propTypes = {
+ basepath: PropTypes.string,
+ type: PropTypes.string,
+};
+
export default withTranslation()(Technique);