Key note categories and examples for tech issues

Remember the sort option for search results

This is an example note

I took this note when I tried to improve the existing feature for remembering the sort option for search results.

First, I tried to understand the current implementation and which part should be refactored because I didn't remember them. Then, I found the parts that need to be updated and refactored them.

Query Context should store the sort order

Currently, it doesn't store the sort order param but it directly refers to the config.

  • getSortOrderForQueryPath in redux-store/src/utils/notes.ts.

It is called in note-list-header-sort-dropdown.tsx, for example. So, if you want to refer to the current sort order, you should call getSortOrderForQueryPath in redux-store/src/utils/notes.ts instead of reading the redux state, which is not good.

In QueryContextState, some modes have a property filterSort. The search mode has searchSort property. It'd be nice to merge them into just the one prooperty sort.

Why are there two states: queryContext and notes?

It is not intuitive to have two separate states for managing queries. ...It is mainly for getting fast UI responsibility.

But eventually the notes actions call getQueryContextPathgetQueryOptionsgetSortOrderForQueryPath, which looks redundant. The app should always call notes.loadWithQueryContext after calling queryContext actions.

Remove some notes.load* actions

The following actions should be removed:

  • loadAll
  • loadPinned
  • loadInBook
  • loadWithTag
  • loadWithStatus
  • loadInTrash
  • loadWithKeyword
  • filterWithKeyword

No! loadWithQueryContext calls them internally 😂 ...well, the app should stop calling load** directly, then.

Okay, cleaned up! - https://github.com/inkdropapp/desktop/commit/7e1bcd0159a8ce265e67258ac093db9a1ff5efb7 Now, the app calls like so:

dispatch(actions.queryContext.setFilterKeyword(qc, keyword, qc.filterSort))
await dispatch(actions.notes.reloadWithQueryContext())
  • Desktop: https://github.com/inkdropapp/desktop/commit/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  • Mobile: https://github.com/inkdropapp/mobile/commit/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Refer to queryContext.sort for loading notes

Now, it should be ready to rename filterSort and searchSort to just sort in queryContext. The queryContext actions should set this value by checking getSortOrderForQueryPath. And the notes actions should refer to queryContext.sort instead of calling getSortOrderForQueryPath.

PR

Desktop

Mobile

Get help

Got any questions about this page? Feel free to ask them on the user forum here.