-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Still need to link to mentions and page select actions
- Loading branch information
Showing
9 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react' | ||
import { useSelector } from 'react-redux' | ||
import dayjs from 'dayjs' | ||
import advancedFormat from 'dayjs/plugin/advancedFormat' | ||
|
||
import PagesTable from './PagesTable' | ||
import { DAILY_NOTE_DISPLAY_FORMAT } from '../block/blockModel' | ||
import PageLink from '../links/PageLink' | ||
|
||
dayjs.extend(advancedFormat) | ||
|
||
const getData = (blocks, linksToBlocks) => { | ||
return Object.values(blocks) | ||
.filter(block => !block.parentId) | ||
.map(block => ({ | ||
text: block.text, | ||
blockId: block.id, | ||
created: block.created, | ||
updated: block.updated, | ||
mentions: linksToBlocks[block.id] || [] | ||
})) | ||
} | ||
|
||
|
||
const AllPages = props => { | ||
const blocks = useSelector(state => state.blocks) | ||
const linksToBlocks = useSelector(state => state.links.to) | ||
|
||
const columns = React.useMemo( | ||
() => [ | ||
{ | ||
Header: 'Title', | ||
accessor: (row) => <PageLink key={row.blockId} pageBlockId={row.blockId}>{row.text}</PageLink>, | ||
sortType: (rowA, rowB, id, desc) => rowA.original.text.localeCompare(rowB.original.text) | ||
}, { | ||
Header: 'Mentions', | ||
accessor: 'mentions', | ||
Cell: ({ value }) => value.length, | ||
sortType: (rowA, rowB, id, desc) => rowA.original.mentions.length - rowB.original.mentions.length | ||
}, { | ||
Header: 'Updated', | ||
accessor: 'updated', | ||
Cell: ({ value }) => value ? dayjs(value).format(DAILY_NOTE_DISPLAY_FORMAT) : null | ||
}, { | ||
Header: 'Created', | ||
accessor: 'created', | ||
Cell: ({ value }) => value ? dayjs(value).format(DAILY_NOTE_DISPLAY_FORMAT) : null | ||
} | ||
], | ||
[] | ||
) | ||
|
||
const data = React.useMemo(() => getData(blocks, linksToBlocks), [blocks, linksToBlocks]) | ||
|
||
return ( | ||
<div className="all-pages"> | ||
<PagesTable columns={columns} data={data} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default AllPages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react' | ||
import { useTable, useSortBy } from 'react-table' | ||
import { ChevronDown, ChevronUp } from 'react-bootstrap-icons' | ||
|
||
const PagesTable = ({ columns, data }) => { | ||
const { | ||
getTableProps, | ||
getTableBodyProps, | ||
headerGroups, | ||
rows, | ||
prepareRow, | ||
} = useTable( | ||
{ | ||
columns, | ||
data, | ||
}, | ||
useSortBy | ||
) | ||
return ( | ||
<> | ||
<table className="table table-dark" {...getTableProps()}> | ||
<thead className="thead-dark"> | ||
{headerGroups.map(headerGroup => ( | ||
<tr {...headerGroup.getHeaderGroupProps()}> | ||
{headerGroup.headers.map(column => ( | ||
// Add the sorting props to control sorting. For this example | ||
// we can add them into the header props | ||
<th scope="col" {...column.getHeaderProps(column.getSortByToggleProps())}> | ||
{column.render('Header')} | ||
{/* Add a sort direction indicator */} | ||
<span> | ||
{column.isSorted | ||
? column.isSortedDesc | ||
? <ChevronDown color="white" /> | ||
: <ChevronUp color="white" /> | ||
: ''} | ||
</span> | ||
</th> | ||
))} | ||
</tr> | ||
))} | ||
</thead> | ||
<tbody {...getTableBodyProps()}> | ||
{rows.map( | ||
(row, i) => { | ||
prepareRow(row) | ||
return ( | ||
<tr {...row.getRowProps()}> | ||
{row.cells.map(cell => { | ||
return ( | ||
<td {...cell.getCellProps()}>{cell.render('Cell')}</td> | ||
) | ||
})} | ||
</tr> | ||
)} | ||
)} | ||
</tbody> | ||
</table> | ||
</> | ||
) | ||
} | ||
|
||
export default PagesTable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters