1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 21:20:24 +02:00

Minor refactors in frontend JS (#69)

* Add Prettier

* Update dependencies; add typescript setup

* Add tsconfig

* Rewrite some mentions frontend into TS

* Fix use of username instead of display name

* Change back to JS

* Remove commented code

* Update function name to match filename

* Update getMentionText.js

* Simplify condition

* Bump packages to stable versions; use prettier package

* Make functions use camel case

* Update js/package.json

Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>

* Don't access data directly

* Update js/src/forum/addComposerAutocomplete.js

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

* Update tsconfig.json

Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>
This commit is contained in:
David Wheatley
2021-09-20 18:42:38 +01:00
committed by GitHub
parent 6a5d7e9864
commit 6173c3d612
11 changed files with 4346 additions and 2725 deletions

View File

@@ -1,10 +1,10 @@
import DiscussionControls from 'flarum/utils/DiscussionControls';
import EditPostComposer from 'flarum/components/EditPostComposer';
import cleanDisplayName from './cleanDisplayName';
import DiscussionControls from 'flarum/forum/utils/DiscussionControls';
import EditPostComposer from 'flarum/forum/components/EditPostComposer';
import getMentionText from './getMentionText';
function insertMention(post, composer, quote) {
const user = post.user();
const mention = `@"${(user && cleanDisplayName(user)) || app.translator.trans('core.lib.username.deleted_text')}"#p${post.id()} `;
const mention = getMentionText(user, post.id());
// If the composer is empty, then assume we're starting a new reply.
// In which case we don't want the user to have to confirm if they
@@ -19,9 +19,7 @@ function insertMention(post, composer, quote) {
composer.editor.insertAtCursor(
Array(precedingNewlines).join('\n') + // Insert up to two newlines, depending on preceding whitespace
(quote
? '> ' + mention + quote.trim().replace(/\n/g, '\n> ') + '\n\n'
: mention),
(quote ? '> ' + mention + quote.trim().replace(/\n/g, '\n> ') + '\n\n' : mention),
false
);
}
@@ -35,7 +33,6 @@ export default function reply(post, quote) {
// The default "Reply" action behavior will only open a new composer if
// necessary, but it will always be a ReplyComposer, hence the exceptional
// case above.
DiscussionControls.replyAction.call(post.discussion())
.then(composer => insertMention(post, composer, quote));
DiscussionControls.replyAction.call(post.discussion()).then((composer) => insertMention(post, composer, quote));
}
}