Skip to content

Commit

Permalink
Add modified date field
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 10, 2024
1 parent 1feeea3 commit 1ade6e2
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 30 deletions.
28 changes: 20 additions & 8 deletions filesystem/dist/esm/web.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ body,
}

.dataviews-wrapper {
height: 100%;
min-height: 100%;
}

.dataviews-view-list__item-wrapper {
Expand Down
15 changes: 4 additions & 11 deletions src/get-data.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { Filesystem } from '@capacitor/filesystem';
import { getSelectedFolderURL } from './index';

export async function getPaths(path = '', selectedFolderURL) {
export async function getPaths(path = '', directory) {
const paths = [];
if (!selectedFolderURL) {
selectedFolderURL = await getSelectedFolderURL();
}
const dir = await Filesystem.readdir({
path,
directory: selectedFolderURL,
});
const dir = await Filesystem.readdir({ path, directory });

// Recursively read all files in the iCloud folder
for (const file of dir.files) {
Expand All @@ -19,9 +12,9 @@ export async function getPaths(path = '', selectedFolderURL) {
continue;
}
// paths.push(nestedPath)
paths.push(...(await getPaths(nestedPath, selectedFolderURL)));
paths.push(...(await getPaths(nestedPath, directory)));
} else if (file.name.endsWith('.html')) {
paths.push(nestedPath);
paths.push({ ...file, path: nestedPath });
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export default function Frame({ selectedFolderURL, setSelectedFolderURL }) {
setCurrentId();
getPaths('', selectedFolderURL)
.then((_paths) => {
const pathObjects = _paths.map((path) => ({
path,
const pathObjects = _paths.map((file) => ({
...file,
id: uuidv4(),
}));
if (!pathObjects.length) {
Expand Down
45 changes: 41 additions & 4 deletions src/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function SiderBar({ items, setItem, currentId, setCurrentId }) {
search: '',
filters: [],
sort: {
field: 'path',
field: 'mtime',
direction: 'desc',
},
hiddenFields: [],
Expand All @@ -31,6 +31,20 @@ export default function SiderBar({ items, setItem, currentId, setCurrentId }) {
);
}

if (view.sort) {
items = items.sort((a, b) => {
const aValue = a[view.sort.field];
const bValue = b[view.sort.field];
if (aValue < bValue) {
return view.sort.direction === 'asc' ? -1 : 1;
}
if (aValue > bValue) {
return view.sort.direction === 'asc' ? 1 : -1;
}
return 0;
});
}

// Temporary hack until we can control selection in data views.
useEffect(() => {
const button = document.getElementById('view-list-0-' + currentId);
Expand All @@ -50,11 +64,34 @@ export default function SiderBar({ items, setItem, currentId, setCurrentId }) {
{
id: 'path',
// To do: remove hidden text from rows.
header: ' ',
header: 'Text',
enableHiding: false,
enableSorting: false,
render({ item }) {
return <Title item={item} />;
return (
<span className="note-title">
<Title item={item} />
</span>
);
},
},
{
id: 'mtime',
header: 'Modified',
render({ item }) {
const time = item.mtime
? new Date(item.mtime).toLocaleString(undefined, {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
})
: 'now';
return (
<small style={{ opacity: 0.6 }}>
<time dateTime={item.mtime}>{time}</time>
</small>
);
},
},
]}
Expand Down
17 changes: 13 additions & 4 deletions tests/mock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ test.describe('Blocknotes', () => {

await page.getByRole('button', { name: 'Notes' }).click();

await expect(page.getByRole('grid').getByRole('row')).toHaveText([
await expect(page.getByRole('row').locator('.note-title')).toHaveText([
'Untitled',
]);

Expand All @@ -82,7 +82,9 @@ test.describe('Blocknotes', () => {
canvas(page).getByRole('document', { name: 'Block: Paragraph' })
).toBeFocused();

await expect(page.getByRole('row')).toHaveText(['aa']);
await expect(page.getByRole('row').locator('.note-title')).toHaveText([
'aa',
]);

// Nothing should have been saved yet because saving is debounced.
expect(await getPaths(page)).toEqual([]);
Expand Down Expand Up @@ -123,7 +125,10 @@ test.describe('Blocknotes', () => {

await page.keyboard.type('b');

await expect(page.getByRole('row')).toHaveText(['b', 'aaaa']);
await expect(page.getByRole('row').locator('.note-title')).toHaveText([
'b',
'aaaa',
]);

// Immediately switch back to note A.
await page.getByRole('button', { name: 'aaaa' }).click();
Expand Down Expand Up @@ -216,7 +221,11 @@ test.describe('Blocknotes', () => {
await page.keyboard.type('2');

await notesButton.click();
await page.getByRole('row', { name: 'a' }).nth(1).click();
await page
.getByRole('row')
.locator('.note-title:text("a")')
.nth(1)
.click();

await expect(
canvas(page)
Expand Down

0 comments on commit 1ade6e2

Please sign in to comment.