Skip to content

Commit

Permalink
Merge pull request #3 from blomstra/sm/fix-default-sort-pref
Browse files Browse the repository at this point in the history
fix: default sort not saved
  • Loading branch information
luceos authored Jul 9, 2024
2 parents 94e29ed + 89a058f commit a004e90
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 45 deletions.
3 changes: 0 additions & 3 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
return [
new Extend\Locales(__DIR__.'/locale'),

(new Extend\Routes('api'))
->get('/sorting-preference', 'sorting-preferences.show', ShowUserPreferredSortingController::class),

(new Extend\Middleware('forum'))->add(ApplyUserSortingMiddleware::class),

(new Extend\Middleware('api'))->add(ApplyUserSortingMiddleware::class),
Expand Down
17 changes: 5 additions & 12 deletions js/src/forum/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@ app.initializers.add('blomstra/save-sorting-preferences', () => {
return;
}

if (!sort) {
m.request({
method: 'GET',
url: '/api/sorting-preference',
}).then((response) => {
sort = response.data.attributes.sort;

m.redraw();
});
}

override(IndexPage.prototype, 'viewItems', function (this, user) {
const items = new ItemList();
const sortMap = app.discussions.sortMap();

if (!sort) {
sort = app.session.user?.preferences()?.['discussion_sort'];
}

const sortOptions = Object.keys(sortMap).reduce((acc: any, sortId) => {
acc[sortId] = app.translator.trans(`core.forum.index_sort.${sortId}_button`);
return acc;
Expand All @@ -45,8 +38,8 @@ app.initializers.add('blomstra/save-sorting-preferences', () => {

function handleClick() {
app.search.changeSort.bind(app.search, value)();

sort = value;
app.session.user?.savePreferences({ discussion_sort: value });
}

return (
Expand Down
5 changes: 0 additions & 5 deletions src/ApplyUserSortingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$sort = Arr::get($request->getQueryParams(), 'sort');
$lastSelectedSort = $actor->getPreference('discussion_sort');

if ($sort && $sort !== $lastSelectedSort) {
$actor->setPreference('discussion_sort', $sort);
$actor->save();
}

return $handler->handle($request->withQueryParams([
'sort' => $sort ?? $lastSelectedSort,
]));
Expand Down
25 changes: 0 additions & 25 deletions src/ShowUserPreferredSortingController.php

This file was deleted.

0 comments on commit a004e90

Please # to comment.