1
0
mirror of https://github.com/flarum/core.git synced 2025-07-10 11:26:24 +02:00
Files
php-flarum/js/src/forum/components/EventPost.js
David Wheatley d268894e61 chore: 1.2 JS clean-up (#3214)
* fix: `extend.ts` TS error

* docs: fix incorrect JS docblocks

* chore: simplify some code

* chore: remove usages of prefixed JS function

* chore: consistent empty return types

* chore: format

* fix: typing errors

* chore: remove unneeded `@public` docblock modifiers

* Apply suggestions from code review

* Update js/src/forum/utils/slidable.js

Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>
2021-12-27 18:58:18 +00:00

82 lines
1.9 KiB
JavaScript

import app from '../../forum/app';
import Post from './Post';
import { ucfirst } from '../../common/utils/string';
import usernameHelper from '../../common/helpers/username';
import icon from '../../common/helpers/icon';
import Link from '../../common/components/Link';
/**
* The `EventPost` component displays a post which indicating a discussion
* event, like a discussion being renamed or stickied. Subclasses must implement
* the `icon` and `description` methods.
*
* ### Attrs
*
* - All of the attrs for `Post`
*
* @abstract
*/
export default class EventPost extends Post {
elementAttrs() {
const attrs = super.elementAttrs();
attrs.className = (attrs.className || '') + ' EventPost ' + ucfirst(this.attrs.post.contentType()) + 'Post';
return attrs;
}
content() {
const user = this.attrs.post.user();
const username = usernameHelper(user);
const data = Object.assign(this.descriptionData(), {
user,
username: user ? (
<Link className="EventPost-user" href={app.route.user(user)}>
{username}
</Link>
) : (
username
),
});
return super.content().concat([icon(this.icon(), { className: 'EventPost-icon' }), <div class="EventPost-info">{this.description(data)}</div>]);
}
/**
* Get the name of the event icon.
*
* @return {string}
*/
icon() {
return '';
}
/**
* Get the description text for the event.
*
* @param {Record<string, unknown>} data
* @return {import('mithril').Children} The description to render in the DOM
*/
description(data) {
return app.translator.trans(this.descriptionKey(), data);
}
/**
* Get the translation key for the description of the event.
*
* @return {string}
*/
descriptionKey() {
return '';
}
/**
* Get the translation data for the description of the event.
*
* @return {Record<string, unknown>}
*/
descriptionData() {
return {};
}
}