Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: frontend route was undefined #90

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading