From 4b820ba231e71717c6158dbf924a3b1e308226cc Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sat, 18 Sep 2021 00:43:00 -0400 Subject: [PATCH] try with context --- package.json | 4 +- src/{App.js => App.tsx} | 19 ++- src/UserContext.tsx | 6 + ...tionCarousel.js => InflectionCarousel.tsx} | 18 +-- src/content/{index.js => index.ts} | 41 +++++- .../inflection/feminine-inflection.mdx | 2 +- src/content/inflection/inflection-intro.mdx | 4 - src/content/intro.mdx | 2 +- src/content/nouns/nouns-gender.mdx | 8 +- src/content/nouns/nouns-unisex.mdx | 5 +- src/content/verbs/future-verbs.mdx | 6 +- src/content/verbs/imperative-verbs.mdx | 4 +- src/content/verbs/present-verbs.mdx | 4 +- src/content/verbs/roots-and-stems.mdx | 4 +- src/content/verbs/subjunctive-verbs.mdx | 4 +- src/games/{Game.tsx => GameCore.tsx} | 30 +++- src/games/GameDisplay.tsx | 10 ++ src/games/games.tsx | 40 ++++++ src/games/{ => sub-cores}/GenderGame.tsx | 16 +-- src/games/{ => sub-cores}/UnisexNounGame.tsx | 35 +++-- src/index.js | 5 +- src/types.d.ts | 13 +- src/user-context.tsx | 24 ++++ yarn.lock | 130 +++++++++++++++++- 24 files changed, 355 insertions(+), 79 deletions(-) rename src/{App.js => App.tsx} (74%) create mode 100644 src/UserContext.tsx rename src/components/{InflectionCarousel.js => InflectionCarousel.tsx} (58%) rename src/content/{index.js => index.ts} (93%) rename src/games/{Game.tsx => GameCore.tsx} (87%) create mode 100644 src/games/GameDisplay.tsx create mode 100644 src/games/games.tsx rename src/games/{ => sub-cores}/GenderGame.tsx (91%) rename src/games/{ => sub-cores}/UnisexNounGame.tsx (80%) create mode 100644 src/user-context.tsx diff --git a/package.json b/package.json index 991bd66..251c87c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "private": true, "dependencies": { "@fortawesome/fontawesome-free": "^5.15.2", - "@lingdocs/pashto-inflector": "^0.9.3", + "@lingdocs/lingdocs-main": "^0.0.4", + "@lingdocs/pashto-inflector": "^1.0.5", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", @@ -12,6 +13,7 @@ "@types/node": "^14.14.35", "@types/react": "^17.0.3", "@types/react-dom": "^17.0.2", + "@types/react-router-dom": "^5.1.9", "bootstrap": "4.5.3", "classnames": "^2.2.6", "markdown-to-jsx": "^7.1.3", diff --git a/src/App.js b/src/App.tsx similarity index 74% rename from src/App.js rename to src/App.tsx index 57904c9..5660e3e 100644 --- a/src/App.js +++ b/src/App.tsx @@ -8,7 +8,7 @@ import React, { useState } from "react"; // eslint-disable-next-line -import { BrowserRouter as Router, Route, withRouter, Switch } from "react-router-dom"; +import { BrowserRouter as Router, Route, withRouter, Switch, RouteComponentProps } from "react-router-dom"; import "./App.css"; import Page404 from "./pages/404"; import Chapter from "./components/Chapter"; @@ -17,6 +17,8 @@ import Sidebar from "./components/Sidebar"; import Header from "./components/Header"; import TableOfContentsPage from "./pages/TableOfContentsPage"; import { useEffect } from "react"; +import { useUser } from "./user-context"; +import { AT } from "@lingdocs/lingdocs-main"; import ReactGA from "react-ga"; const chapters = content.reduce((chapters, item) => ( item.content @@ -31,10 +33,21 @@ if (prod) { ReactGA.set({ anonymizeIp: true }); } -function App(props) { +function App(props: RouteComponentProps) { const [navOpen, setNavOpen] = useState(false); + const { setUser } = useUser(); useEffect(() => { ReactGA.pageview(window.location.pathname); + fetch("https://account.lingdocs.com/api/user").then((res) => res.json()).then((res) => { + console.log("fetched user info"); + if (res.user) { + const user = res.user as AT.LingdocsUser + setUser(user); + } else { + setUser(undefined); + } + }).catch(console.error); + // eslint-disable-next-line }, []); useEffect(() => { window.scroll(0, 0); @@ -57,7 +70,7 @@ function App(props) { - {chapters.map((chapter) => ( + {chapters.map((chapter: any) => ( {chapter} diff --git a/src/UserContext.tsx b/src/UserContext.tsx new file mode 100644 index 0000000..310684d --- /dev/null +++ b/src/UserContext.tsx @@ -0,0 +1,6 @@ +import React from "react"; +import { AT } from "@lingdocs/lingdocs-main"; + +const UserContext = React.createContext(undefined); + +export default UserContext; \ No newline at end of file diff --git a/src/components/InflectionCarousel.js b/src/components/InflectionCarousel.tsx similarity index 58% rename from src/components/InflectionCarousel.js rename to src/components/InflectionCarousel.tsx index 980bccb..943743b 100644 --- a/src/components/InflectionCarousel.js +++ b/src/components/InflectionCarousel.tsx @@ -2,29 +2,31 @@ import React from "react"; import Carousel from "./Carousel"; import { InlinePs, - removeFVariants, + removeFVarients, InflectionsTable, inflectWord, defaultTextOptions as opts, } from "@lingdocs/pashto-inflector"; -function InflectionCarousel({ items }) { +function InflectionCarousel({ items }: any) { return (
- { - const inf = inflectWord(item.entry); - if (!inf) { + { + const infOut = inflectWord(item.entry); + if (!infOut || !infOut.inflections) { return ( -
Oops! No inflections for
+ // @ts-ignore +
Oops! No inflections for {item.entry}
); } return { + // @ts-ignore title: , body: , }; diff --git a/src/content/index.js b/src/content/index.ts similarity index 93% rename from src/content/index.js rename to src/content/index.ts index ac63590..41a13c4 100644 --- a/src/content/index.js +++ b/src/content/index.ts @@ -7,39 +7,66 @@ */ /* eslint-disable import/no-webpack-loader-syntax */ +// @ts-ignore import * as intro from "!babel-loader!mdx-loader!./intro.mdx"; +// @ts-ignore import * as presentEquative from "!babel-loader!mdx-loader!./equatives/present-equative.mdx" +// @ts-ignore import * as subjunctiveHabitualEquative from "!babel-loader!mdx-loader!./equatives/subjunctive-habitual-equative.mdx"; +// @ts-ignore import * as otherEquatives from "!babel-loader!mdx-loader!./equatives/other-equatives.mdx"; +// @ts-ignore import * as nounsGender from "!babel-loader!mdx-loader!./nouns/nouns-gender.mdx"; +// @ts-ignore import * as nounsUnisex from "!babel-loader!mdx-loader!./nouns/nouns-unisex.mdx"; +// @ts-ignore import * as nounsPlural from "!babel-loader!mdx-loader!./nouns/nouns-plural.mdx"; +// @ts-ignore import * as arabicPlurals from "!babel-loader!mdx-loader!./nouns/arabic-plurals.mdx"; +// @ts-ignore import * as bundledPlurals from "!babel-loader!mdx-loader!./nouns/bundled-plurals.mdx"; +// @ts-ignore import * as verbAspect from "!babel-loader!mdx-loader!./verbs/verb-aspect.mdx"; +// @ts-ignore import * as verbsIntro from "!babel-loader!mdx-loader!./verbs/verbs-intro.mdx"; +// @ts-ignore import * as presentVerbs from "!babel-loader!mdx-loader!./verbs/present-verbs.mdx"; +// @ts-ignore import * as subjunctiveVerbs from "!babel-loader!mdx-loader!./verbs/subjunctive-verbs.mdx"; +// @ts-ignore import * as futureVerbs from "!babel-loader!mdx-loader!./verbs/future-verbs.mdx"; +// @ts-ignore import * as imperativeVerbs from "!babel-loader!mdx-loader!./verbs/imperative-verbs.mdx"; +// @ts-ignore import * as verbEndings from "!babel-loader!mdx-loader!./verbs/verb-endings.mdx"; +// @ts-ignore import * as rootsAndStems from "!babel-loader!mdx-loader!./verbs/roots-and-stems.mdx"; +// @ts-ignore import * as sentenceStructure from "!babel-loader!mdx-loader!./verbs/sentence-structure.mdx"; +// @ts-ignore import * as pronounsBasic from "!babel-loader!mdx-loader!./pronouns/pronouns-basic.mdx"; +// @ts-ignore import * as pronounsMini from "!babel-loader!mdx-loader!./pronouns/pronouns-mini.mdx"; +// @ts-ignore import * as directionalPronouns from "!babel-loader!mdx-loader!./pronouns/pronouns-directional.mdx"; +// @ts-ignore import * as inflectionIntro from "!babel-loader!mdx-loader!./inflection/inflection-intro.mdx"; +// @ts-ignore import * as inflectionPatterns from "!babel-loader!mdx-loader!./inflection/inflection-patterns.mdx"; +// @ts-ignore import * as feminineInflection from "!babel-loader!mdx-loader!./inflection/feminine-inflection.mdx"; +// @ts-ignore import * as sandwiches from "!babel-loader!mdx-loader!./sandwiches/sandwiches.mdx"; +// @ts-ignore import * as theFiveYeys from "!babel-loader!mdx-loader!./writing/the-five-yeys.mdx"; +// @ts-ignore import * as typingIssues from "!babel-loader!mdx-loader!./writing/typing-issues.mdx"; const contentTree = [ @@ -196,7 +223,7 @@ const contentTree = [ ]; export const content = contentTree.map((item) => { - function prepareChapter(chp, subdir) { + function prepareChapter(chp: any, subdir?: any) { return { path: subdir ? `/${subdir}/${chp.slug}/` : `/${chp.slug}/`, slug: chp.slug, @@ -209,30 +236,34 @@ export const content = contentTree.map((item) => { ? prepareChapter(item) : { ...item, - chapters: item.chapters.map((c) => { + chapters: item.chapters?.map((c) => { return prepareChapter(c, item.subdirectory); }), }; }).map((item, i, items) => { // make the next and previous page information for each chapter - function withNextPrev(current, index, arr) { - function getInfo(x) { + function withNextPrev(current: any, index: any, arr: any) { + function getInfo(x: any) { return x.content ? { frontMatter: x.frontMatter, path: x.path } : { frontMatter: x.chapters[0].frontMatter, path: x.chapters[0].path }; // TODO: KILL THIS? } function getNextOutsideItem() { + // @ts-ignore return items[i+1].content // if it's a single chapter section, get that chapter ? items[i+1] // if it's a section with multiple chapters, get the first chapter + // @ts-ignore : items[i+1].chapters[0]; } function getPrevOutsideItem() { + // @ts-ignore return items[i-1].content // if it's a single chapter section, get that chapter ? items[i-1] // if it's a section with multiple chapters, get the last chapter + // @ts-ignore : items[i-1].chapters[items[i-1].chapters.length - 1]; } const next = index < arr.length - 1 @@ -259,11 +290,13 @@ export const content = contentTree.map((item) => { } : {}, }; } + // @ts-ignore if (item.content) { return withNextPrev(item, i, items); } return { ...item, + // @ts-ignore chapters: item.chapters.map((chapter, j, chapters) => ( withNextPrev(chapter, j, chapters) )), diff --git a/src/content/inflection/feminine-inflection.mdx b/src/content/inflection/feminine-inflection.mdx index 09ebc2e..ed3ac94 100644 --- a/src/content/inflection/feminine-inflection.mdx +++ b/src/content/inflection/feminine-inflection.mdx @@ -19,7 +19,7 @@ import { Examples, InlinePs, grammarUnits, - removeFVariants, + removeFVarients, InflectionsTable, inflectWord, } from "@lingdocs/pashto-inflector"; diff --git a/src/content/inflection/inflection-intro.mdx b/src/content/inflection/inflection-intro.mdx index f63e18f..67ea743 100644 --- a/src/content/inflection/inflection-intro.mdx +++ b/src/content/inflection/inflection-intro.mdx @@ -17,10 +17,6 @@ import { defaultTextOptions as opts, Examples, InlinePs, - grammarUnits, - removeFVariants, - InflectionsTable, - inflectWord, } from "@lingdocs/pashto-inflector"; import Carousel from "../../components/Carousel"; import Table from "../../components/Table"; diff --git a/src/content/intro.mdx b/src/content/intro.mdx index e7de707..1343321 100644 --- a/src/content/intro.mdx +++ b/src/content/intro.mdx @@ -33,4 +33,4 @@ This is very much a work in progress. 🏗👷‍♂️ I am slowly adding more > "Part of the task of the grammarian is ... to unravel the complexities of languages, and, as far as possible, simplify them." Frank Palmer - [Grammar](https://www.amazon.com/gp/product/B000S5VSAS) -I hope this grammar helps to show that **Pashto isn't difficult... it's rich and beautiful**. +I hope this grammar helps to show that **Pashto isn't difficult... it's rich and beautiful**. \ No newline at end of file diff --git a/src/content/nouns/nouns-gender.mdx b/src/content/nouns/nouns-gender.mdx index 19564eb..5610f8f 100644 --- a/src/content/nouns/nouns-gender.mdx +++ b/src/content/nouns/nouns-gender.mdx @@ -8,13 +8,15 @@ import { Examples, } from "@lingdocs/pashto-inflector"; import genderColors from "../../lib/gender-colors"; -import GenderGame from "../../games/GenderGame"; import { firstVariation } from "../../lib/text-tools"; import GenderTable from "../../components/GenderTable"; import Link from "../../components/Link"; import words from "../../words/nouns-adjs"; export const femColor = genderColors.f; export const mascColor = genderColors.m; +import nounGenderGame1 from "../../games/games"; +import nounGenderGame2 from "../../games/games"; +import GameDisplay from "../../games/GameDisplay"; export const femEndingWConsonant = words.filter((w) => w.category === "consonant-fem"); @@ -109,7 +111,7 @@ All nouns in Pashto are either or . Thankfully, you can pretty m - Words ending in can be either or . - Words ending in can also be plural, as in - + ## Exceptions @@ -164,4 +166,4 @@ Some words are used to describe people who obviously have a gender and they *tot }, ]} /> - + diff --git a/src/content/nouns/nouns-unisex.mdx b/src/content/nouns/nouns-unisex.mdx index b5d72a2..5512bf6 100644 --- a/src/content/nouns/nouns-unisex.mdx +++ b/src/content/nouns/nouns-unisex.mdx @@ -10,7 +10,8 @@ import { import Table from "../../components/Table"; import Link from "../../components/Link"; import GenderTable from "../../components/GenderTable"; -import UnisexNounGame from "../../games/UnisexNounGame"; +import { unisexNounGame } from "../../games/games"; +import GameDisplay from "../../games/GameDisplay"; There are many words for people and animals in Pashto that can be used in both masculine and feminine forms. @@ -209,7 +210,7 @@ If the accent comes on the end of the word, the femine form is a little differen } ]} /> - +