Skip to content

Commit

Permalink
#11 Prevent delete/download of pages if none selected
Browse files Browse the repository at this point in the history
Remove daily notes filter in table, react-table filtering is too dumb
and I don't have the energy right now.
  • Loading branch information
cofinley committed Feb 20, 2021
1 parent b20c5d5 commit ad0189b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
7 changes: 1 addition & 6 deletions src/features/all-pages/AllPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const getData = (blocks, linksToBlocks) => {
blockId: block.id,
created: block.created,
updated: block.updated,
mentions: linksToBlocks[block.id] || [],
dailyNote: !!block.dailyNote
mentions: linksToBlocks[block.id] || []
}))
}

Expand Down Expand Up @@ -58,10 +57,6 @@ const AllPages = props => {
accessor: 'created',
className: 'text-right',
Cell: ({ value }) => value ? dayjs(value).format(DAILY_NOTE_DISPLAY_FORMAT) : null
}, {
Header: 'Daily Note?',
accessor: 'dailyNote',
show: false
}
],
[onMentionClick]
Expand Down
21 changes: 16 additions & 5 deletions src/features/all-pages/PagesTable.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { useTable, useSortBy, useRowSelect } from 'react-table'
import { ChevronDown, ChevronUp, Trash, Download, Calendar3 } from 'react-bootstrap-icons'
import { ChevronDown, ChevronUp, Trash, Download } from 'react-bootstrap-icons'

import { save } from '../io/io'
import { serialize, flattenTreeIds } from '../block/blockModel'
Expand Down Expand Up @@ -33,6 +33,9 @@ const PagesTable = ({ columns, data }) => {
const linksToBlocks = useSelector(state => state.links.to)

const downloadRows = rows => {
if (!rows.length) {
return
}
const files = rows
.map(row => row.original.blockId)
.map(blockId => {
Expand All @@ -51,6 +54,9 @@ const PagesTable = ({ columns, data }) => {
* @param {object} rows - table rows
*/
const deleteRows = rows => {
if (!rows.length) {
return
}
rows
.map(row => row.original.blockId)
.map(blockId => {
Expand Down Expand Up @@ -82,7 +88,7 @@ const PagesTable = ({ columns, data }) => {
rows,
prepareRow,
selectedFlatRows,
state: { selectedRowIds },
state: { selectedRowIds }
} = useTable(
{
columns,
Expand Down Expand Up @@ -112,10 +118,15 @@ const PagesTable = ({ columns, data }) => {
return (
<>
<div className="all-pages__toolbar">
<Trash onClick={() => deleteRows(selectedFlatRows)} className="mr-3" color={Object.keys(selectedRowIds).length ? 'white' : 'gray'} />
<Download onClick={() => downloadRows(selectedFlatRows)} color={Object.keys(selectedRowIds).length ? 'white' : 'gray'} />
<Trash
onClick={() => deleteRows(selectedFlatRows)}
className={`mr-3 all-pages__button${Object.keys(selectedRowIds).length ? ' active': ''}`}
/>
<Download
onClick={() => downloadRows(selectedFlatRows)}
className={`all-pages__button${Object.keys(selectedRowIds).length ? ' active': ''}`}
/>
<div className="flex-grow-1" />
<Calendar3 color="lightgray" />
</div>
<table className="table table-dark" {...getTableProps()}>
<thead className="thead-dark">
Expand Down
10 changes: 10 additions & 0 deletions src/features/all-pages/all-pages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
padding: 10px
}

.all-pages__button {
cursor: not-allowed;
fill: gray;

&.active {
cursor: pointer;
fill: white;
}
}

.mentions-bubble {
position: relative;
width: 37px;
Expand Down
1 change: 1 addition & 0 deletions src/features/links/linksSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const linksSlice = createSlice({
.map(destinationBlockId => {
state.to[destinationBlockId] = state.to[destinationBlockId]
.filter(sourceBlockId => sourceBlockId !== blockId)
return true
})
}
delete state.from[blockId]
Expand Down

0 comments on commit ad0189b

Please sign in to comment.