Skip to content

feat: remember sorting per folder - #356

Open
jimaek wants to merge 2 commits into
nxzai:mainfrom
jimaek:sorting
Open

feat: remember sorting per folder#356
jimaek wants to merge 2 commits into
nxzai:mainfrom
jimaek:sorting

Conversation

@jimaek

@jimaek jimaek commented Aug 4, 2026

Copy link
Copy Markdown

Fixes #355

@cerede2000

Copy link
Copy Markdown

I tested this against my branch — it merges with a single trivial conflict in fileStore.js (an unrelated line next to the restoreSortForFolder call), and the feature itself works. Three things I would change before it lands, one of which I think is blocking.

The sort is shared between accounts on the same browser. useStorage('settings:folderSorts', {}) writes to localStorage, which is scoped to the origin and not to the user. On a multi-account instance, one person's per-folder sorts become everyone's on that machine, and nothing is cleared at logout. The project already has a place for per-user preferences — user_settings, reached through /api/settings — which is where showHiddenFiles, showThumbnails and the rest live, and it follows the user between devices instead of staying on one browser.

The map grows without bound. One entry per folder ever sorted, never expired or trimmed. It won't hit the quota in normal use, but nothing stops it either — a cap on the most recently used entries would.

Dynamically created sort options are lost on reload. setSort pushes a new option into sortOptions when the requested by/order pair isn't one of the eight built-ins, and applySort persists it — but sortOptions itself isn't persisted. After a reload, getSortOption(saved.by, saved.order) finds nothing and falls back to the default, so a sort by any column outside the built-in list silently doesn't survive. That's the case the feature is meant to cover, so it's worth either persisting the created option or building it back from the stored by/order.

Worth mentioning since it's adjacent: #360 asks for a configurable default view, and its author believes per-folder view preferences already exist — probably having assumed the sorting behaviour this PR introduces. If per-folder state is going to be a pattern here, it's better if sorting and view use the same storage and the same scoping rules rather than diverging.

cerede2000 pushed a commit to cerede2000/NextExplorer that referenced this pull request Aug 27, 2026
Sorting is remembered per folder, so a folder opened again comes back the
way it was left. Contributed by @jimaek, for nxzai#355.

Taken as it stands, with its shortcomings noted on the pull request: the
map is stored in localStorage and so is shared between accounts on one
browser, it grows without bound, and a sort by a column outside the eight
built-ins does not survive a reload. The first of those is the same flaw
the default-view work has to solve anyway, and both are better fixed once,
together, than separately here.

# Conflicts:
#	frontend/src/stores/fileStore.js
cerede2000 pushed a commit to cerede2000/NextExplorer that referenced this pull request Aug 27, 2026
Sorting is remembered per folder, so a folder opened again comes back the
way it was left. Contributed by @jimaek, for nxzai#355.

# Conflicts:
#	frontend/src/stores/fileStore.js
@jimaek

jimaek commented Aug 27, 2026

Copy link
Copy Markdown
Author

Please check now

cerede2000 pushed a commit to cerede2000/NextExplorer that referenced this pull request Aug 27, 2026
@jimaek reworked this after review, and it now answers all three points:
sorts are stored per user through `user_settings` rather than in
localStorage shared by every account on a browser, the map is capped at
100 entries by recency, and a sort on a column outside the built-in list
is rebuilt on load instead of silently falling back.

Two things changed while resolving the merge:

The new `upsertUserSetting` went through `db.prepare` on every write. It
now goes through `prepared`, which caches the statement — the rest of
this file already avoids recompiling the same SQL, and these run on every
preference change.

The store's factory for default system settings predated `uploads` and
`folderSize`, so switching user would have reset the store to a shape the
rest of the app no longer expects. It builds the full shape now, and the
duplicate declaration that the merge left behind is gone.

His local generateId is dropped in favour of the one this file already
imports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remember sorting in folders

2 participants