diff --git a/package-lock.json b/package-lock.json index 09d1cc0..ac1be3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -111,10 +111,15 @@ "@emotion/react": ">=11.11.4", "@emotion/styled": ">=11.11.0", "@mui/material": ">=5.15.10", + "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dropdown-menu": "^2.0.6", "@radix-ui/react-label": "^2.0.2", + "@radix-ui/react-select": "^2.0.0", + "@radix-ui/react-slider": "^1.2.0", "@radix-ui/react-slot": "^1.0.2", + "@radix-ui/react-switch": "^1.1.0", "@radix-ui/react-tabs": "^1.0.4", + "@tanstack/react-table": "^8.19.2", "autoprefixer": "^10.4.19", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", diff --git a/package.json b/package.json index 78e3335..42aaa4c 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,9 @@ "webpack-merge": "^5.10.0", "zip-folder-promise": "^1.2.0" }, - "workspaces": ["src/*"], + "workspaces": [ + "src/*" + ], "volta": { "node": "20.11.1" } diff --git a/src/paratext-bible-word-list/src/word-content-viewer.component.tsx b/src/paratext-bible-word-list/src/word-content-viewer.component.tsx index 3abefab..41db223 100644 --- a/src/paratext-bible-word-list/src/word-content-viewer.component.tsx +++ b/src/paratext-bible-word-list/src/word-content-viewer.component.tsx @@ -1,9 +1,16 @@ import { useState, useEffect } from 'react'; import { Canon } from '@sillsdev/scripture'; -import { Table } from 'platform-bible-react'; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from 'platform-bible-react'; import type { WordListEntry } from 'paratext-bible-word-list'; -type Row = { +type WordData = { reference: string; text: string; }; @@ -13,42 +20,42 @@ function generateTableData(selectedWord: WordListEntry) { Canon.bookNumberToId(selectedWord.scrRefs[0].bookNum), ); - const newRows: Row[] = []; + const newWordData: WordData[] = []; for (let id = 0; id < selectedWord.scrRefs.length; id++) { const { chapterNum } = selectedWord.scrRefs[id]; const { verseNum } = selectedWord.scrRefs[id]; const fullReference: string = `${bookName} ${chapterNum}:${verseNum}`; - newRows.push({ reference: fullReference, text: selectedWord.scriptureSnippets[id] }); + newWordData.push({ reference: fullReference, text: selectedWord.scriptureSnippets[id] }); } - return newRows; + return newWordData; } export default function WordContentViewer({ selectedWord }: { selectedWord: WordListEntry }) { - const [rows, setRows] = useState([]); + const [wordData, setWordData] = useState([]); useEffect(() => { - setRows([]); + setWordData([]); - setRows(generateTableData(selectedWord)); + setWordData(generateTableData(selectedWord)); }, [selectedWord]); return ( - - columns={[ - { - key: 'reference', - name: 'Reference', - width: 150, - }, - { - key: 'text', - name: 'Text', - }, - ]} - rows={rows} - rowHeight={30} - headerRowHeight={50} - /> + + + + Reference + Text + + + + {wordData.map((result) => ( + + {result.reference} + {result.text} + + ))} + +
); } diff --git a/src/paratext-bible-word-list/src/word-list.web-view.tsx b/src/paratext-bible-word-list/src/word-list.web-view.tsx index 2000007..2908005 100644 --- a/src/paratext-bible-word-list/src/word-list.web-view.tsx +++ b/src/paratext-bible-word-list/src/word-list.web-view.tsx @@ -1,7 +1,7 @@ import { useSetting, useData } from '@papi/frontend/react'; import { WebViewProps } from '@papi/core'; import { ChangeEvent, useEffect, useMemo, useState } from 'react'; -import { ComboBox, RefSelector, ScriptureReference, Switch, TextField } from 'platform-bible-react'; +import { ComboBox, ScriptureReference, Switch, TextField } from 'platform-bible-react'; import type { WordListEntry } from 'paratext-bible-word-list'; import WordContentViewer from './word-content-viewer.component'; import WordTable from './word-table.component'; @@ -59,7 +59,7 @@ globalThis.webViewComponent = function WordListWebView({ projectId, useWebViewState, }: WebViewProps) { - const [scrRef, setScrRef] = useSetting('platform.verseRef', defaultScrRef); + const [scrRef] = useSetting('platform.verseRef', defaultScrRef); const [scope, setScope] = useWebViewState('scope', Scope.Book); const [wordFilter, setWordFilter] = useState(''); const [selectedWord, setSelectedWord] = useState(); @@ -116,12 +116,6 @@ globalThis.webViewComponent = function WordListWebView({ return (
- { - setScrRef(newScrRef); - }} - />
void; }; -export default function WordTable({ wordList, fullWordCount, onWordClick }: WordTableProps) { - const [sortColumns, setSortColumns] = useState(defaultSortColumns); - const onSortColumnsChange = useCallback((changedSortColumns: TableSortColumn[]) => { - setSortColumns(changedSortColumns.slice(-1)); - }, []); +const getSortingIcon = (sortDirection: false | SortDirection): string => { + if (sortDirection === 'asc') { + return '↑'; + } + if (sortDirection === 'desc') { + return '↓'; + } + return '↕'; +}; - const rows = useMemo(() => { - const newRows: Row[] = []; +const columns = (wordColumnTitle: string): ColumnDef[] => [ + { + accessorKey: 'word', + header: ({ column }) => { + return ( + + ); + }, + }, + { + accessorKey: 'count', + header: ({ column }) => { + return ( + + ); + }, + }, +]; + +export default function WordTable({ wordList, fullWordCount, onWordClick }: WordTableProps) { + const wordData = useMemo(() => { + const newWordData: WordData[] = []; wordList.forEach((word) => { - newRows.push({ word: word.word, count: word.scrRefs.length }); + newWordData.push({ word: word.word, count: word.scrRefs.length }); }); - return newRows; + return newWordData; }, [wordList]); - const sortedRows = useMemo((): readonly Row[] => { - if (sortColumns.length === 0) return rows; - const { columnKey, direction } = sortColumns[0]; - - let sortedRowsLocal: Row[] = [...rows]; - - switch (columnKey) { - case 'word': - sortedRowsLocal = sortedRowsLocal.sort((a, b) => a[columnKey].localeCompare(b[columnKey])); - break; - case 'count': - sortedRowsLocal = sortedRowsLocal.sort((a, b) => a[columnKey] - b[columnKey]); - break; - default: - } - return direction === 'DESC' ? sortedRowsLocal.reverse() : sortedRowsLocal; - }, [rows, sortColumns]); - - useEffect(() => { - if (sortColumns.length === 0) { - setSortColumns(defaultSortColumns); - } - }, [sortColumns]); - - const onCellClick = (args: TableCellClickArgs) => { - onWordClick(args.row.word); + const onCellClick = (row: RowContents): void => { + onWordClick(row.getValue('word')); }; const wordColumnTitle = useMemo(() => { @@ -64,26 +66,12 @@ export default function WordTable({ wordList, fullWordCount, onWordClick }: Word }, [fullWordCount, wordList.length]); return ( - - columns={[ - { - key: 'word', - name: wordColumnTitle, - }, - { - key: 'count', - name: 'Count', - }, - ]} - rows={sortedRows} - rowKeyGetter={(row: Row) => { - return row.word; - }} - sortColumns={sortColumns} - onSortColumnsChange={onSortColumnsChange} - rowHeight={30} - headerRowHeight={50} - onCellClick={onCellClick} + ); }