-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add pin notes #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
katsyuta
wants to merge
67
commits into
DeepinkApp:master
Choose a base branch
from
katsyuta:90-add-pin-notes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add pin notes #276
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
2c1fa7a
feat: add pinned field to note
katsyuta 85a1253
feat: implement pin and unpin
katsyuta b5eda29
refactor: move text to local file
katsyuta 819eaeb
refactor: improve style
katsyuta 82a39fa
chore: rename
katsyuta 42a3fc2
refactor: handle toggle separate of open click
katsyuta 3fee3b6
refactor: use button instead icon
katsyuta 449775a
refactor: use visibility property
katsyuta 98c3916
fix: handle keyboard focus
katsyuta e2408d5
chore: add pin to menu, remove from note preview
katsyuta f1501ec
feat: add pin to note menu
katsyuta eb76718
refactor: scroll to pinned by if note pinned by context menu
katsyuta 0df3225
fix: scroll only after list ids was updated
katsyuta 915a954
refactor: not sort by pinned in bin and search mode
katsyuta 687d338
chore: return conditional sorting
katsyuta ea0aed3
chore: rename
katsyuta 90dd39b
feat: add style for pinned note
katsyuta e12bf96
refactor: remove command
katsyuta a69a3c9
chore: move style to theme file
katsyuta 217dbd8
chore: remove old
katsyuta 7101e06
feat: keep pin order
katsyuta 5354ad4
chore: not scroll if note visible
katsyuta f3c8f6c
chore: rename css atr
katsyuta 08e1981
chore: simplify sort
katsyuta 7fa9723
refactor: update sort api
katsyuta c3fd8e6
test: add
katsyuta e2680e8
chore: update css
katsyuta 5d6ab8b
chore: lift menu item
katsyuta 101b973
refactor: combine pin effects
katsyuta 8251acf
fix: do not wait before highliht note
katsyuta 9d28d03
chore: update comment
katsyuta e76c2df
test: rename
katsyuta 6833074
fix: filter by pin status have incorrect sql
katsyuta b6f5637
fix: old clear timeout can remove new timeout
katsyuta d98e917
refactor: do not scroll if element in viewport
katsyuta 9396ff0
fix: after rebase
katsyuta 733d255
refactor: pin action available only in note list context menu
katsyuta 4c6d90e
refactor: not scroll after pin and unpin
katsyuta 9bb4a22
refactor: remove higliting note after pin
katsyuta 65f10fb
refactor: do not scroll while note meta was updated
katsyuta ab5e313
chore: remove pin controller from note menu
katsyuta 915f7c1
chore: pin in preview is optional
katsyuta e3360e5
chore: typo
katsyuta f4ab7de
chore: do not pass payload
katsyuta 20fe675
test: update check
katsyuta df56790
chore: simplify
katsyuta b18602c
test: rename, add test case
katsyuta f12c315
chore: remove unnecessary text
katsyuta 107bd30
chore: fix typo
katsyuta 35ba6b4
fix: after unpin the pin icon is blink in note preview
katsyuta e91b7cf
fix: disable native auto scroll after update note meta
katsyuta 96c4591
chore: typo
katsyuta ea4a5f6
chore: simplify
katsyuta 5d576e1
chore: add type
katsyuta 21df539
chore: typo
katsyuta f9d7ed3
refactor: use index for pinned field
katsyuta e50d37a
fix: after rebase
katsyuta eba60ee
refactor: remove pin from note editor
katsyuta 2be4eb3
chore: simplify
katsyuta 69e3f49
test: rename
katsyuta 6043d94
refactor: rename slot in chakra recipe
katsyuta e283214
refactor: add event to distinguish event
katsyuta 31c5699
chore: rename
katsyuta 210c33e
chore: disable eslint rule
katsyuta 1caa3b7
chore: fix after rebase
katsyuta 18cea8d
chore: add comment
katsyuta 8fa741e
chore: docs
katsyuta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
packages/app/src/core/database/sqlite/migrations/sql/2_add_pinned_to_notes.sql
This file contains hidden or 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,7 @@ | ||
| ALTER TABLE notes | ||
| ADD COLUMN pinned_at INTEGER; | ||
|
|
||
| DROP INDEX idx_notes_workspace_status; | ||
|
|
||
| CREATE INDEX idx_notes_workspace_status | ||
| ON notes(workspace_id, deleted_at, archived, bookmarked, visible, pinned_at, updated_at DESC); |
This file contains hidden or 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 hidden or 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
79 changes: 79 additions & 0 deletions
79
packages/app/src/core/features/notes/controller/NotesController.sort.test.ts
This file contains hidden or 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,79 @@ | ||
| import { openSQLite } from '@core/database/sqlite/openSQLite'; | ||
| import { createWorkspaceId } from '@tests/utils/vaultContext'; | ||
| import { createFileControllerMock } from '@utils/mocks/fileControllerMock'; | ||
|
|
||
| import { NotesController } from './NotesController'; | ||
|
|
||
| test('updating a pinned note does not affect the order of pinned notes', async () => { | ||
| const db = await openSQLite(createFileControllerMock()); | ||
| onTestFinished(db.close); | ||
|
|
||
| const workspaceId = await createWorkspaceId(db.get()); | ||
| const registry = new NotesController(db.get(), workspaceId); | ||
|
|
||
| const note1 = await registry.add({ title: '2001', text: 'Dummy text' }); | ||
| const note2 = await registry.add({ title: '2002', text: 'Dummy text' }); | ||
| const note3 = await registry.add({ title: '2003', text: 'Dummy text' }); | ||
|
|
||
| // Pin | ||
| vi.setSystemTime('01/01/2010 12:00'); | ||
| await registry.updateMeta([note1], { isPinned: true }); | ||
| vi.setSystemTime('01/01/2011 12:00'); | ||
| await registry.updateMeta([note3], { isPinned: true }); | ||
|
|
||
| await expect( | ||
| registry.query({ sort: [{ by: 'pinnedAt', order: 'desc' }] }), | ||
| ).resolves.toStrictEqual([note3, note1, note2]); | ||
|
|
||
| // Updating note content in a pinned note should not affect the order | ||
| vi.setSystemTime('01/01/2015 12:00'); | ||
| await registry.update(note1, { title: '2015', text: 'Dummy text' }); | ||
|
|
||
| await expect( | ||
| registry.query({ sort: [{ by: 'pinnedAt', order: 'desc' }] }), | ||
| ).resolves.toStrictEqual([note3, note1, note2]); | ||
| }); | ||
|
|
||
| test('updating an unpinned note does not affect the order of pinned notes', async () => { | ||
| const db = await openSQLite(createFileControllerMock()); | ||
| onTestFinished(db.close); | ||
|
|
||
| const workspaceId = await createWorkspaceId(db.get()); | ||
| const registry = new NotesController(db.get(), workspaceId); | ||
|
|
||
| vi.setSystemTime('01/01/2000 12:00'); | ||
| const note1 = await registry.add({ title: '2001', text: 'Dummy text' }); | ||
|
|
||
| vi.setSystemTime('01/01/2002 12:00'); | ||
| const note2 = await registry.add({ title: '2002', text: 'Dummy text' }); | ||
|
|
||
| vi.setSystemTime('01/01/2004 12:00'); | ||
| const note3 = await registry.add({ title: '2004', text: 'Dummy text' }); | ||
|
|
||
| // Pin note1 | ||
| vi.setSystemTime('01/01/2010 12:00'); | ||
| await registry.updateMeta([note1], { isPinned: true }); | ||
|
|
||
| // Pinned notes come first, unpinned notes are sorted by update time | ||
| await expect( | ||
| registry.query({ | ||
| sort: [ | ||
| { by: 'pinnedAt', order: 'desc' }, | ||
| { by: 'updatedAt', order: 'desc' }, | ||
| ], | ||
| }), | ||
| ).resolves.toStrictEqual([note1, note3, note2]); | ||
|
|
||
| // Update an unpinned note2 | ||
| vi.setSystemTime('01/01/2015 12:00'); | ||
| await registry.update(note2, { title: '2015', text: 'Dummy text' }); | ||
|
|
||
| await expect( | ||
| registry.query({ | ||
| sort: [ | ||
| { by: 'pinnedAt', order: 'desc' }, | ||
| { by: 'updatedAt', order: 'desc' }, | ||
| ], | ||
| }), | ||
| ).resolves.toStrictEqual([note1, note2, note3]); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the
NOTE_UPDATEDevent is fired, we update the scroll position.The
NOTE_UPDATEDevent is triggered for any change to a note. However, when a user pins a note, we should not scroll the list. Doing so interrupts the user's workflow, because they then have to manually scroll back to the position they were viewing.We have no way to distinguish which note updates should trigger scrolling and which should not.
With new event when only a note's metadata changes (such as its pinned status), we can avoid scrolling the list.