mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 13:34:04 +08:00
fix: hide WelcomeHero
when content is empty (#3219)
This commit is contained in:
parent
edde6be301
commit
7a27f494c6
|
@ -1,50 +0,0 @@
|
|||
import app from '../../forum/app';
|
||||
import Component from '../../common/Component';
|
||||
import Button from '../../common/components/Button';
|
||||
|
||||
/**
|
||||
* The `WelcomeHero` component displays a hero that welcomes the user to the
|
||||
* forum.
|
||||
*/
|
||||
export default class WelcomeHero extends Component {
|
||||
oninit(vnode) {
|
||||
super.oninit(vnode);
|
||||
|
||||
this.hidden = localStorage.getItem('welcomeHidden');
|
||||
}
|
||||
|
||||
view() {
|
||||
if (this.hidden) return <div />;
|
||||
|
||||
const slideUp = () => {
|
||||
this.$().slideUp(this.hide.bind(this));
|
||||
};
|
||||
|
||||
return (
|
||||
<header className="Hero WelcomeHero">
|
||||
<div class="container">
|
||||
{Button.component({
|
||||
icon: 'fas fa-times',
|
||||
onclick: slideUp,
|
||||
className: 'Hero-close Button Button--icon Button--link',
|
||||
'aria-label': app.translator.trans('core.forum.welcome_hero.hide'),
|
||||
})}
|
||||
|
||||
<div className="containerNarrow">
|
||||
<h2 className="Hero-title">{app.forum.attribute('welcomeTitle')}</h2>
|
||||
<div className="Hero-subtitle">{m.trust(app.forum.attribute('welcomeMessage'))}</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the welcome hero.
|
||||
*/
|
||||
hide() {
|
||||
localStorage.setItem('welcomeHidden', 'true');
|
||||
|
||||
this.hidden = true;
|
||||
}
|
||||
}
|
69
js/src/forum/components/WelcomeHero.tsx
Normal file
69
js/src/forum/components/WelcomeHero.tsx
Normal file
|
@ -0,0 +1,69 @@
|
|||
import app from '../app';
|
||||
import Component from '../../common/Component';
|
||||
import Button from '../../common/components/Button';
|
||||
import type Mithril from 'mithril';
|
||||
|
||||
export interface IWelcomeHeroAttrs {}
|
||||
|
||||
const LOCAL_STORAGE_KEY = 'welcomeHidden';
|
||||
|
||||
/**
|
||||
* The `WelcomeHero` component displays a hero that welcomes the user to the
|
||||
* forum.
|
||||
*/
|
||||
export default class WelcomeHero extends Component<IWelcomeHeroAttrs> {
|
||||
/**
|
||||
* @deprecated Extend the `isHidden` method instead.
|
||||
*/
|
||||
hidden: boolean = false;
|
||||
|
||||
oninit(vnode: Mithril.Vnode<IWelcomeHeroAttrs, this>) {
|
||||
super.oninit(vnode);
|
||||
}
|
||||
|
||||
view(vnode: Mithril.Vnode<IWelcomeHeroAttrs, this>) {
|
||||
if (this.isHidden()) return null;
|
||||
|
||||
const slideUp = () => {
|
||||
this.$().slideUp(this.hide.bind(this));
|
||||
};
|
||||
|
||||
return (
|
||||
<header class="Hero WelcomeHero">
|
||||
<div class="container">
|
||||
<Button
|
||||
icon="fas fa-times"
|
||||
onclick={slideUp}
|
||||
className="Hero-close Button Button--icon Button--link"
|
||||
aria-label={app.translator.trans('core.forum.welcome_hero.hide')}
|
||||
/>
|
||||
|
||||
<div class="containerNarrow">
|
||||
<h2 class="Hero-title">{app.forum.attribute('welcomeTitle')}</h2>
|
||||
<div class="Hero-subtitle">{m.trust(app.forum.attribute('welcomeMessage'))}</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the welcome hero.
|
||||
*/
|
||||
hide() {
|
||||
localStorage.setItem(LOCAL_STORAGE_KEY, 'true');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the welcome hero should be hidden.
|
||||
*
|
||||
* @returns if the welcome hero is hidden.
|
||||
*/
|
||||
isHidden(): boolean {
|
||||
if (!app.forum.attribute<string>('welcomeTitle')?.trim()) return true;
|
||||
if (localStorage.getItem(LOCAL_STORAGE_KEY)) return true;
|
||||
if (this.hidden) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user