Skip to content

Commit

Permalink
fix: frontend route was undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideIadeluca committed Nov 6, 2024
1 parent 62dbaf4 commit 53e6732
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
12 changes: 0 additions & 12 deletions js/src/forum/addProfilePane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,11 @@ import app from 'flarum/forum/app';
import { extend } from 'flarum/common/extend';
import LinkButton from 'flarum/common/components/LinkButton';
import UserPage from 'flarum/forum/components/UserPage';
import RootMasqueradePane from './panes/RootMasqueradePane';

import type ItemList from 'flarum/common/utils/ItemList';
import type Mithril from 'mithril';

export default function addProfilePane() {
app.routes['fof-masquerade'] = {
path: '/u/:username/masquerade',
resolver: {
onmatch() {
if (!app.forum.attribute('canViewMasquerade')) throw new Error();

return RootMasqueradePane;
},
},
};

extend(UserPage.prototype, 'navItems', function (items: ItemList<Mithril.Children>) {
if (app.forum.attribute<boolean>('canViewMasquerade') || this.user?.canEditMasqueradeProfile()) {
const edit = this.user?.canEditMasqueradeProfile();
Expand Down
4 changes: 4 additions & 0 deletions js/src/forum/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import Extend from 'flarum/common/extenders';
import User from 'flarum/common/models/User';
import Field from '../lib/models/Field';
import Answer from '../lib/models/Answer';
import RootMasqueradePane from './panes/RootMasqueradePane';

import { default as commonExtend } from '../common/extend';

export default [
...commonExtend,

new Extend.Routes() //
.add('fof-masquerade', '/u/:username/masquerade', RootMasqueradePane),

new Extend.Store() //
.add('masquerade-answer', Answer),

Expand Down
5 changes: 5 additions & 0 deletions js/src/forum/panes/RootMasqueradePane.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import app from 'flarum/forum/app';
import UserPage from 'flarum/forum/components/UserPage';
import LoadingIndicator from 'flarum/common/components/LoadingIndicator';
import ProfilePane from './ProfilePane';
Expand All @@ -12,6 +13,10 @@ export default class RootMasqueradePane extends UserPage {
oninit(vnode: Mithril.Vnode) {
super.oninit(vnode);

if (!app.forum.attribute('canViewMasquerade')) {
m.route.set(app.route('index'));
}

this.loadUser(m.route.param('username'));
}

Expand Down

0 comments on commit 53e6732

Please sign in to comment.