diff --git a/src/Layout/Routes.js b/src/Layout/Routes.js index daf8a693..c7d9880d 100644 --- a/src/Layout/Routes.js +++ b/src/Layout/Routes.js @@ -17,6 +17,7 @@ import MapSelectedLanguages from "pages/DistanceMap/map"; import SelectedLanguages from "pages/DistanceMap/selectorLangGroup"; import Docx2Eaf from "pages/Docx2Eaf"; import Docx2Xlsx from "pages/Docx2Xlsx"; +import ListCognates from "pages/ListCognates"; import EditTranslations from "pages/EditTranslations"; import Files from "pages/Files"; import Grants from "pages/Grants"; @@ -79,6 +80,7 @@ const AppRoutes = () => ( } /> } /> } /> + } /> } /> ); diff --git a/src/pages/ListCognates/index.js b/src/pages/ListCognates/index.js new file mode 100644 index 00000000..b390da34 --- /dev/null +++ b/src/pages/ListCognates/index.js @@ -0,0 +1,141 @@ +import { connect } from "react-redux"; +import { Button, Checkbox, Dimmer, Icon, Input, Label, List, Loader, Message, Segment } from "semantic-ui-react"; +import { gql, useMutation } from "@apollo/client"; +import { compose } from "recompose"; +import React, { useContext, useState, useEffect } from "react"; + +import TranslationContext from "Layout/TranslationContext"; + +const cognatesSummaryMutation = gql` + mutation cognatesSummary ( + $onlyInToc: Boolean! + $languageOffset: Int + $languageLimit: Int + $debugFlag: Boolean + ) { + cognates_summary( + only_in_toc: $onlyInToc + offset: $languageOffset + limit: $languageLimit + debug_flag: $debugFlag + ) { + json_url + language_list + triumph + } + } +`; + +const ListCognates = ({user}) => { + + const [onlyInToc, setOnlyInToc] = useState(false); + const [cleanResult, setCleanResult] = useState(false); + const [languageOffset, setLanguageOffset] = useState(0); + const [languageLimit, setLanguageLimit] = useState(10); + const [getCognatesSummary, { data, error, loading }] = useMutation(cognatesSummaryMutation); + + useEffect(() => setCleanResult(false), [loading, data]); + const getTranslation = useContext(TranslationContext); + + const debugFlag = false; + + return ( +
+ {(user.id === undefined || user.id !== 1) && !loading ? ( + + {getTranslation("Please sign in")} +

{getTranslation("This page is available for administrator only")}

+
+ ) : loading ? ( + + + {getTranslation("Loading")}... + + + ) : ( + + + + { + setOnlyInToc(checked); + setCleanResult(!data); + }} + /> + + + { + setLanguageOffset(value); + setCleanResult(!data); + }} + className="lingvo-labeled-input" + /> + + + { + setLanguageLimit(value); + setCleanResult(!data); + }} + className="lingvo-labeled-input" + /> + + +
+ ); +} + +ListCognates.contextType = TranslationContext; + +export default compose( + connect(state => state.user) +)(ListCognates);