Skip to content

Commit

Permalink
Revert "perf: only load user state when showing full user data (#50)" (
Browse files Browse the repository at this point in the history
…#54)

This reverts commit 4be7499.
  • Loading branch information
imorland authored Jun 16, 2024
1 parent bb36014 commit 312c32f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 35 deletions.
29 changes: 1 addition & 28 deletions js/src/forum/components/UserPoliciesStateModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,23 @@ import app from 'flarum/forum/app';
import humanTime from 'flarum/common/helpers/humanTime';
import Modal from 'flarum/common/components/Modal';
import sortByAttribute from '../../common/helpers/sortByAttribute';
import LoadingIndicator from 'flarum/common/components/LoadingIndicator';

/* global m */

export default class UserPoliciesStateModal extends Modal {
user = null;
loading = false;

oninit(vnode) {
super.oninit(vnode);

if (this.attrs.user.fofTermsPoliciesState() === undefined) {
this.loading = true;
app.store.find('users', this.attrs.user.id()).then((user) => {
this.user = user;
this.loading = false;
m.redraw();
});
} else {
this.user = this.attrs.user;
}
}

title() {
return app.translator.trans('fof-terms.forum.state-modal.title', {
username: this.attrs.user.username(),
});
}

content() {
if (this.loading) {
return (
<div className="Modal-body">
<LoadingIndicator />
</div>
);
}

return m(
'.Modal-body',
m(
'ul',
sortByAttribute(app.store.all('fof-terms-policies')).map((policy) => {
const state = this.user.fofTermsPoliciesState()[policy.id()];
const state = this.attrs.user.fofTermsPoliciesState()[policy.id()];

return m('li', [
policy.name() + ': ',
Expand Down
8 changes: 1 addition & 7 deletions src/Extenders/UserPoliciesRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace FoF\Terms\Extenders;

use Flarum\Api\Serializer\BasicUserSerializer;
use Flarum\Api\Serializer\CurrentUserSerializer;
use Flarum\User\User;
use FoF\Terms\Repositories\PolicyRepository;

Expand All @@ -30,13 +29,8 @@ public function __construct(PolicyRepository $policies)

public function __invoke(BasicUserSerializer $serializer, User $user, array $attributes)
{
$request = $serializer->getRequest();

if ($request->getAttribute('routeName') === 'users.show' && $serializer->getActor()->can('seeFoFTermsPoliciesState', $user)) {
if ($serializer->getActor()->can('seeFoFTermsPoliciesState', $user)) {
$attributes['fofTermsPoliciesState'] = $this->policies->state($user);
}

if ($serializer instanceof CurrentUserSerializer) {
$attributes['fofTermsPoliciesHasUpdate'] = $this->policies->hasPoliciesUpdate($user);
$attributes['fofTermsPoliciesMustAccept'] = $this->policies->mustAcceptNewPolicies($user);
}
Expand Down

0 comments on commit 312c32f

Please sign in to comment.