diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 7a94b237..75814d59 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,55 +1,56 @@ -/** @type {import("eslint").Linter.Config} */ +/** @type {import('eslint').Linter.Config} */ const config = { - parser: "@typescript-eslint/parser", - parserOptions: { - project: true - }, - plugins: ["@typescript-eslint", "prettier"], - extends: [ - "next/core-web-vitals", - "plugin:@typescript-eslint/recommended-type-checked", - "plugin:@typescript-eslint/stylistic-type-checked", - "plugin:prettier/recommended", - "plugin:storybook/recommended" - ], - "ignorePatterns": ["/styled-system/*"], - rules: { - // These opinionated rules are enabled in stylistic-type-checked above. - // Feel free to reconfigure them to your own preference. - "@typescript-eslint/array-type": "off", - "@typescript-eslint/consistent-type-definitions": "off", + parser: '@typescript-eslint/parser', + parserOptions: { + project: true, + }, + plugins: ['@typescript-eslint', 'prettier'], + extends: [ + 'next/core-web-vitals', + 'plugin:@typescript-eslint/recommended-type-checked', + 'plugin:@typescript-eslint/stylistic-type-checked', + 'plugin:prettier/recommended', + 'plugin:storybook/recommended', + 'plugin:tailwindcss/recommended', + ], + 'ignorePatterns': ['/styled-system/*'], + rules: { + // These opinionated rules are enabled in stylistic-type-checked above. + // Feel free to reconfigure them to your own preference. + '@typescript-eslint/array-type': 'off', + '@typescript-eslint/consistent-type-definitions': 'off', - "@typescript-eslint/consistent-type-imports": [ - "warn", - { - prefer: "type-imports", - fixStyle: "inline-type-imports" - } - ], - "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], - "@typescript-eslint/no-misused-promises": [ - 2, - { - checksVoidReturn: { attributes: false } - } - ], + '@typescript-eslint/consistent-type-imports': [ + 'warn', + { + prefer: 'type-imports', + fixStyle: 'inline-type-imports', + }, + ], + '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], + '@typescript-eslint/no-misused-promises': [ + 2, + { + checksVoidReturn: { attributes: false }, + }, + ], - "react/jsx-curly-brace-presence": ["error", { props: "never", children: "never" }], - "prefer-arrow-callback": "error", - "arrow-body-style": "error", + 'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }], + 'prefer-arrow-callback': 'error', + 'arrow-body-style': 'error', - "prettier/prettier": [ - "warn", - {}, - { - "usePrettierrc": true - } - ], - "@typescript-eslint/ban-ts-comment": "warn", + 'prettier/prettier': [ + 'warn', + {}, + { + 'usePrettierrc': true, + }, + ], + '@typescript-eslint/ban-ts-comment': 'warn', - "no-console": ["error", { allow: ["warn", "error"] }], - "import/no-cycle": "error" - } -}; + 'no-console': ['warn', { allow: ['warn', 'error'] }], + 'import/no-cycle': 'error', + }, +} -module.exports = config; +module.exports = config diff --git a/package.json b/package.json index 9ea29437..4eb68581 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@t3-oss/env-nextjs": "^0.7.0", "@tailwindcss/forms": "^0.5.7", "cheerio": "1.0.0-rc.12", + "eslint-plugin-tailwindcss": "^3.13.0", "fast-xml-parser": "^4.3.2", "file-system-cache": "^2.4.4", "jotai": "^2.5.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 42342f0c..fa57603c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ dependencies: cheerio: specifier: 1.0.0-rc.12 version: 1.0.0-rc.12 + eslint-plugin-tailwindcss: + specifier: ^3.13.0 + version: 3.13.0(tailwindcss@3.3.5) fast-xml-parser: specifier: ^4.3.2 version: 4.3.2 @@ -6606,6 +6609,17 @@ packages: - typescript dev: true + /eslint-plugin-tailwindcss@3.13.0(tailwindcss@3.3.5): + resolution: {integrity: sha512-Fcep4KDRLWaK3KmkQbdyKHG0P4GdXFmXdDaweTIPcgOP60OOuWFbh1++dufRT28Q4zpKTKaHwTsXPJ4O/EjU2Q==} + engines: {node: '>=12.13.0'} + peerDependencies: + tailwindcss: ^3.3.2 + dependencies: + fast-glob: 3.3.1 + postcss: 8.4.31 + tailwindcss: 3.3.5 + dev: false + /eslint-scope@5.1.1: resolution: {integrity: sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==} engines: {node: '>=8.0.0'} diff --git a/src/_pages/ReaderPage/Reader.page.tsx b/src/_pages/ReaderPage/Reader.page.tsx index 188b6033..0359591e 100644 --- a/src/_pages/ReaderPage/Reader.page.tsx +++ b/src/_pages/ReaderPage/Reader.page.tsx @@ -1,12 +1,18 @@ -import { NavBar } from '~/_pages/ReaderPage/components/NavBar' -import { ReaderNavButtons } from '~/_pages/ReaderPage/components/ReaderNavButtons' +import { renderChapterContent } from '~/_pages/ReaderPage/chapterDataProcessing/renderChapterContent' import { getBookWithCache, getChapterWithCache } from '~/db' -import { getChapterObjectModel } from './chapterContentData/getChapterObjectModel' -import { ChapterContent } from './components/ChapterContent' +import { getChapterObjectModel } from './chapterDataProcessing/getChapterObjectModel' +import { ChapterContentContainer } from './components/ChapterContentContainer' +import { NavBar } from './components/NavBar' +import { ReaderNavButtons } from './components/ReaderNavButtons' import { ReaderPageContainer } from './components/ReaderPageContainer' import { READER_MODE, type ReaderPageParams } from './ReaderPage.types' -export const ReaderPage = async ({ params }: { params: ReaderPageParams }) => { +export const ReaderPage = async ({ + params, +}: { + params: ReaderPageParams + searchParams: { 'verse-start': string; 'verse-end': string } +}) => { const { bookCode, chapter, readerMode } = params const isStudyMode = readerMode === READER_MODE.Study @@ -20,7 +26,7 @@ export const ReaderPage = async ({ params }: { params: ReaderPageParams }) => { throw new Error('No chapter data') } - const chapterContentHtml = getChapterObjectModel(chapterData.content) + const chapterObjectModel = getChapterObjectModel(chapterData.content) const book = await getBookWithCache(bookCode.toUpperCase()) @@ -32,10 +38,9 @@ export const ReaderPage = async ({ params }: { params: ReaderPageParams }) => { <> - + + {renderChapterContent(chapterObjectModel, isStudyMode)} + + {renderChapterContent(item[NodeType], isStudyMode)} , ] diff --git a/src/_pages/ReaderPage/components/ChapterContent.tsx b/src/_pages/ReaderPage/components/ChapterContent.tsx deleted file mode 100644 index 559e40cd..00000000 --- a/src/_pages/ReaderPage/components/ChapterContent.tsx +++ /dev/null @@ -1,23 +0,0 @@ -'use client' - -import { twMerge } from 'tailwind-merge' -import { type ChapterOM } from '../chapterContentData/getChapterObjectModel' -import { renderChapterContent } from '../chapterContentData/renderChapterContent' -import './ChapterContent.css' - -export const ChapterContent = ({ - chapterContentHtml, - isStudyMode, -}: { - chapterContentHtml: ChapterOM - isStudyMode: boolean -}) => ( -
- {renderChapterContent(chapterContentHtml, isStudyMode)} -
-) diff --git a/src/_pages/ReaderPage/components/ChapterContentContainer.tsx b/src/_pages/ReaderPage/components/ChapterContentContainer.tsx new file mode 100644 index 00000000..1c3b7a81 --- /dev/null +++ b/src/_pages/ReaderPage/components/ChapterContentContainer.tsx @@ -0,0 +1,39 @@ +'use client' + +import { useSearchParams } from 'next/navigation' +import { type ReactNode, useEffect } from 'react' +import { twMerge } from 'tailwind-merge' +import './ChapterContent.css' + +export const ChapterContentContainer = ({ + children, +}: { + children: ReactNode +}) => { + const searchParams = useSearchParams() + const verseStart = parseInt(searchParams.get('verse-start')!) + + useEffect(() => { + const passageStartVerse = document.querySelector( + `.rc-verse[data-verse-order="${verseStart}"]`, + ) + const passageStartVerseQuote = + passageStartVerse?.parentElement?.classList?.contains('rc-quote') && + passageStartVerse.parentElement + if (passageStartVerseQuote) { + passageStartVerseQuote?.scrollIntoView() + } else { + passageStartVerse?.scrollIntoView() + } + }, [verseStart]) + return ( +
+ {children} +
+ ) +} diff --git a/src/_pages/ReaderPage/components/NavBar.tsx b/src/_pages/ReaderPage/components/NavBar.tsx index 7d446686..65c42b22 100644 --- a/src/_pages/ReaderPage/components/NavBar.tsx +++ b/src/_pages/ReaderPage/components/NavBar.tsx @@ -3,10 +3,10 @@ import { wChildren, wClassName, wName } from '~/component-helpers' import { setPageWidthCls } from '~/components/Page' const NavBarContainer = wChildren(({ children }) => ( -
+