Skip to content

Commit

Permalink
feat: private discussion indexpage hero (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland authored Feb 14, 2025
1 parent efaa40d commit f32e816
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
57 changes: 57 additions & 0 deletions js/src/forum/components/PrivateHero.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import app from 'flarum/forum/app';
import Component from 'flarum/common/Component';
import icon from 'flarum/common/helpers/icon';
import textContrastClass from 'flarum/common/helpers/textContrastClass';
import classList from 'flarum/common/utils/classList';
import ItemList from 'flarum/common/utils/ItemList';
import type Mithril from 'mithril';

export default class PrivateHero extends Component {
view() {
const color = this.heroColor();

return (
<header
className={classList('Hero', 'PrivateHero', { 'PrivateHero--colored': color, [textContrastClass(color)]: color })}
style={color ? { '--hero-bg': color } : undefined}
>
<div className="container">{this.viewItems().toArray()}</div>
</header>
);
}

viewItems(): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();

items.add('content', <div className="containerNarrow">{this.contentItems().toArray()}</div>, 80);

return items;
}

contentItems(): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();

items.add(
'private-discussions-title',
<h1 className="Hero-title">
{icon(this.heroIcon())} {app.translator.trans('fof-byobu.forum.hero.title')}
</h1>,
100
);

// Don't think a subtitle is necessary, but can be added if needed.
//items.add('private-discussions-subtitle', <div className="Hero-subtitle">{app.translator.trans('fof-byobu.forum.hero.subtitle')}</div>, 90);

return items;
}

heroColor(): string | null {
// Example return a color string to display a colored hero
//return app.forum.attribute<string>('themeSecondaryColor');
return null;
}

heroIcon(): string {
return app.forum.data.attributes?.['byobu.icon-badge'] as string;
}
}
7 changes: 7 additions & 0 deletions js/src/forum/components/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import PrivateComposerPage from './PrivateComposerPage';
import PrivateHero from './PrivateHero';

export const components = {
PrivateHero,
PrivateComposerPage,
};
1 change: 1 addition & 0 deletions js/src/forum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './modals';
export * from './pages/discussions';
export * from './events';
export * from './helpers';
export * from './components';

export { default as extend } from './extend';

Expand Down
15 changes: 12 additions & 3 deletions js/src/forum/pages/PrivateDiscussionsPage.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import app from 'flarum/forum/app';
import { extend } from 'flarum/common/extend';
import { extend, override } from 'flarum/common/extend';
import LinkButton from 'flarum/common/components/LinkButton';
import IndexPage from 'flarum/forum/components/IndexPage';
import DiscussionListState from 'flarum/forum/states/DiscussionListState';
import PrivateComposing from './PrivateComposing';
import PrivateHero from '../components/PrivateHero';

export default () => {
export default function PrivateDiscussionsPage() {
extend(IndexPage.prototype, 'navItems', (items) => {
const user = app.session.user;

Expand Down Expand Up @@ -46,4 +47,12 @@ export default () => {
items.setContent('newDiscussion', compose.component());
}
});
};

override(IndexPage.prototype, 'hero', function (original) {
if (app.current.get('routeName') === 'byobuPrivate') {
return <PrivateHero />;
}

return original();
});
}
3 changes: 3 additions & 0 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ fof-byobu:
confirm:
make_public: Are you sure you want to remove the recipients and make this discussion visible to anyone who can view the assigned tag?

hero:
title: => fof-byobu.forum.nav.nav_item

labels:
recipients: "{count, plural, one {{count} Recipient} other {{count} Recipients}}"

Expand Down

0 comments on commit f32e816

Please sign in to comment.