mirror of
https://github.com/abort-retry-ignore/joplock.git
synced 2026-04-28 01:49:30 +00:00
Fix All Notes showing empty: normalize __all_notes__ to __all__ in folder-notes endpoint
This commit is contained in:
parent
540ec1fd32
commit
909484b1ae
2 changed files with 23 additions and 7 deletions
|
|
@ -924,12 +924,13 @@ Code block example
|
|||
const folderId = url.searchParams.get('folderId') || '__all__';
|
||||
const offset = Math.max(0, Number(url.searchParams.get('offset') || 0));
|
||||
const selectedNoteId = url.searchParams.get('selectedNoteId') || '';
|
||||
const notes = await itemService.noteHeadersByFolder(auth.user.id, folderId, NOTE_PAGE_SIZE, offset);
|
||||
const normalizedFolderId = (folderId === ALL_NOTES_FOLDER_ID) ? VIRTUAL_ALL_NOTES_ID : folderId;
|
||||
const notes = await itemService.noteHeadersByFolder(auth.user.id, normalizedFolderId, NOTE_PAGE_SIZE, offset);
|
||||
const counts = await itemService.folderNoteCountsByUserId(auth.user.id);
|
||||
const virtualId = folderId === '__all__' ? VIRTUAL_ALL_NOTES_ID : (folderId === '__trash__' ? VIRTUAL_TRASH_ID : folderId);
|
||||
const totalCount = counts.get(virtualId) || counts.get(folderId) || 0;
|
||||
const virtualId = normalizedFolderId === VIRTUAL_ALL_NOTES_ID ? VIRTUAL_ALL_NOTES_ID : (normalizedFolderId === VIRTUAL_TRASH_ID ? VIRTUAL_TRASH_ID : normalizedFolderId);
|
||||
const totalCount = counts.get(virtualId) || counts.get(normalizedFolderId) || 0;
|
||||
const hasMore = offset + notes.length < totalCount;
|
||||
const contextFolderId = folderId === '__all__' ? VIRTUAL_ALL_NOTES_ID : folderId;
|
||||
const contextFolderId = normalizedFolderId === VIRTUAL_ALL_NOTES_ID ? VIRTUAL_ALL_NOTES_ID : normalizedFolderId;
|
||||
sendHtml(response, 200, templates.folderNotesPageFragment(notes, contextFolderId, selectedNoteId, hasMore, offset + notes.length, totalCount));
|
||||
} catch (error) {
|
||||
sendHtml(response, 500, `<div class="empty-hint">Error: ${templates.escapeHtml(error.message || `${error}`)}</div>`);
|
||||
|
|
|
|||
|
|
@ -28,9 +28,8 @@ const request = (port, options = {}) => {
|
|||
res.on('end', () => {
|
||||
const buf = Buffer.concat(chunks);
|
||||
resolve({ statusCode: res.statusCode, body: buf.toString('utf8'), rawBody: buf, headers: res.headers });
|
||||
});
|
||||
});
|
||||
req.on('error', reject);
|
||||
});
|
||||
});
|
||||
if (rawBody) {
|
||||
req.write(rawBody);
|
||||
} else if (body) {
|
||||
|
|
@ -1361,3 +1360,19 @@ test('POST /settings/profile updates profile', async () => {
|
|||
assert.ok(dbUpdated);
|
||||
});
|
||||
});
|
||||
|
||||
test('GET /fragments/folder-notes with __all_notes__ returns all notes', async () => {
|
||||
await withServer({
|
||||
itemService: {
|
||||
noteHeadersByFolder: async (_uid, folderId) => folderId === '__all__' ? [
|
||||
{ id: 'n1', title: 'Note 1', parentId: 'f1', updatedTime: 0 },
|
||||
{ id: 'n2', title: 'Note 2', parentId: 'f2', updatedTime: 0 },
|
||||
] : [],
|
||||
},
|
||||
}, async port => {
|
||||
const res = await request(port, { path: '/fragments/folder-notes?folderId=__all_notes__' });
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.ok(res.body.includes('Note 1'));
|
||||
assert.ok(res.body.includes('Note 2'));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue