From ca0c1677dc87de62d52e201fd39649bdb7cf35c3 Mon Sep 17 00:00:00 2001 From: hans Date: Sun, 13 Feb 2022 14:43:02 -0800 Subject: [PATCH] added: improved party nav w/ react-table --- packages/react-app/package.json | 1 + packages/react-app/src/App.jsx | 2 +- packages/react-app/src/routes/home/Home.jsx | 5 +- .../src/routes/home/components/PartyTable.jsx | 122 ++++++++++++++++++ .../src/routes/home/components/index.js | 1 + yarn.lock | 5 + 6 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 packages/react-app/src/routes/home/components/PartyTable.jsx diff --git a/packages/react-app/package.json b/packages/react-app/package.json index 7cee234a..43f238d8 100644 --- a/packages/react-app/package.json +++ b/packages/react-app/package.json @@ -92,6 +92,7 @@ "react-qr-reader": "^2.2.1", "react-router-dom": "^5.2.0", "react-scripts": "4.0.0", + "react-table": "^7.7.0", "searchico": "^1.2.1", "uint8arrays": "^3.0.0", "walletlink": "^2.1.5", diff --git a/packages/react-app/src/App.jsx b/packages/react-app/src/App.jsx index 1768e405..5ba90aa8 100644 --- a/packages/react-app/src/App.jsx +++ b/packages/react-app/src/App.jsx @@ -204,7 +204,7 @@ function App(props) { let provider; useEffect(async () => { const onboard = Onboard({ - networkId: 5, + networkId: Number(process.env.REACT_APP_CHAINID), dappId: BLOCKNATIVE_DAPPID, walletSelect: { wallets: [ diff --git a/packages/react-app/src/routes/home/Home.jsx b/packages/react-app/src/routes/home/Home.jsx index 188cdd3a..32de7200 100644 --- a/packages/react-app/src/routes/home/Home.jsx +++ b/packages/react-app/src/routes/home/Home.jsx @@ -5,7 +5,7 @@ import { useColorModeValue } from "@chakra-ui/color-mode"; import { Wrap, WrapItem, Stack, Center } from "@chakra-ui/react"; import React, { useEffect, useState, useMemo } from "react"; import { useHistory, Link } from "react-router-dom"; -import { PartyCard, EmptyCard } from "./components"; +import { PartyCard, EmptyCard, PartyTable } from "./components"; function Home({ address, mainnetProvider, tx, readContracts, writeContracts, targetNetwork }) { /***** Load Data from db *****/ @@ -55,7 +55,8 @@ function Home({ address, mainnetProvider, tx, readContracts, writeContracts, tar
- {cards && cards.length > 0 ? cards : } + {/* {cards && cards.length > 0 ? cards : } */} +
); diff --git a/packages/react-app/src/routes/home/components/PartyTable.jsx b/packages/react-app/src/routes/home/components/PartyTable.jsx new file mode 100644 index 00000000..c4947118 --- /dev/null +++ b/packages/react-app/src/routes/home/components/PartyTable.jsx @@ -0,0 +1,122 @@ +import { Table, Thead, Tbody, Tr, Th, Td, chakra, Spinner, Box, Button, Text } from "@chakra-ui/react"; +import { TriangleDownIcon, TriangleUpIcon } from "@chakra-ui/icons"; +import { useTable, useSortBy, usePagination } from "react-table"; +import React, { useEffect, useState, useMemo } from "react"; +import { useHistory, Link } from "react-router-dom"; + +export const PartyTable = ({ parties }) => { + const routeHistory = useHistory(); + const [isLoading, setIsLoading] = useState(true); + const data = useMemo(() => { + console.log(parties); + if (parties) { + setIsLoading(false); + + return parties; + } else { + setIsLoading(true); + return []; + } + }, [parties]); + + const columns = useMemo( + () => [ + { + Header: "Name", + accessor: ({ name }) => ( + + {name} + + ), + }, + { + Header: "Description", + accessor: ({ description }) => ( + + {description} + + ), + }, + { + Header: " ", + accessor: ({ id }) => { + return ( + + ); + }, + }, + ], + [isLoading], + ); + + const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable( + { + columns, + data, + initialState: { + sortBy: [ + { + desc: false, + }, + ], + }, + }, + useSortBy, + usePagination, + ); + + return !isLoading ? ( + + + + + {headerGroups.map(headerGroup => ( + + {headerGroup.headers.map(column => ( + + ))} + + ))} + + + {rows.map(row => { + prepareRow(row); + return ( + + {row.cells.map(cell => { + return ( + + ); + })} + + ); + })} + +
+ {column.render("Header")} + + {column.isSorted ? ( + column.isSortedDesc ? ( + + ) : ( + + ) + ) : null} + +
+ {cell.render("Cell")} +
+
+
+ ) : ( + + ); +}; diff --git a/packages/react-app/src/routes/home/components/index.js b/packages/react-app/src/routes/home/components/index.js index 61883fc7..4c568a14 100644 --- a/packages/react-app/src/routes/home/components/index.js +++ b/packages/react-app/src/routes/home/components/index.js @@ -1,2 +1,3 @@ export { EmptyCard } from "./EmptyCard"; export { PartyCard } from "./PartyCard"; +export { PartyTable } from "./PartyTable"; diff --git a/yarn.lock b/yarn.lock index b2677299..27020358 100644 --- a/yarn.lock +++ b/yarn.lock @@ -21944,6 +21944,11 @@ react-syntax-highlighter@^13.5.3: prismjs "^1.21.0" refractor "^3.1.0" +react-table@^7.7.0: + version "7.7.0" + resolved "https://registry.yarnpkg.com/react-table/-/react-table-7.7.0.tgz#e2ce14d7fe3a559f7444e9ecfe8231ea8373f912" + integrity sha512-jBlj70iBwOTvvImsU9t01LjFjy4sXEtclBovl3mTiqjz23Reu0DKnRza4zlLtOPACx6j2/7MrQIthIK1Wi+LIA== + react-textarea-autosize@^8.3.0: version "8.3.3" resolved "https://registry.npmjs.org/react-textarea-autosize/-/react-textarea-autosize-8.3.3.tgz"