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! - Now, the app calls like so:

dispatch(actions.queryContext.setFilterKeyword(qc, keyword, qc.filterSort))
await dispatch(actions.notes.reloadWithQueryContext())
  • Desktop:
  • Mobile:

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.




Get help

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