Skip to content

Commit

Permalink
Merge branch 'master' into member-remove
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko authored Dec 16, 2024
2 parents 4765697 + 49bf979 commit 70d7931
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 45 deletions.
39 changes: 0 additions & 39 deletions resources/js/core-legacy/post-preview.coffee

This file was deleted.

59 changes: 59 additions & 0 deletions resources/js/core/bbcode-auto-preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import { route } from 'laroute';
import { debounce } from 'lodash';
import { fail } from 'utils/fail';
import { htmlElementOrNull } from 'utils/html';

export default class BbcodeAutoPreview {
private readonly debouncedLoadPreview;
private readonly xhr = new Map<HTMLElement, JQuery.jqXHR<string>>();

constructor() {
this.debouncedLoadPreview = debounce(this.loadPreview, 500);
document.addEventListener('input', this.onInput);
}

private readonly loadPreview = (target: HTMLTextAreaElement) => {
const form = target.closest('form') ?? fail('form element is missing');
const body = target.value;
const preview = htmlElementOrNull(form.querySelector('.js-post-preview--preview'));
const previewBox = form.querySelector('.js-post-preview--box');

if (preview == null) {
return;
}

this.xhr.get(preview)?.abort();

if (body === '') {
preview.dataset.raw = '';
preview.innerHTML = '';
previewBox?.classList.add('hidden');
return;
}

if (preview.dataset.raw === body) {
previewBox?.classList.remove('hidden');
return;
}

const xhr = $.post(route('bbcode-preview'), { text: body }) as JQuery.jqXHR<string>;
xhr.done((data) => {
preview.dataset.raw = body;
preview.innerHTML = data;
previewBox?.classList.remove('hidden');
}).always(() => {
this.xhr.delete(preview);
});
};

private readonly onInput = (e: InputEvent) => {
const target = htmlElementOrNull(e.target)?.closest('.js-post-preview--auto');

if (target instanceof HTMLTextAreaElement) {
this.debouncedLoadPreview(target);
}
};
}
6 changes: 2 additions & 4 deletions resources/js/forum/post-box.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ insert = (event, tagOpen, tagClose = '') ->
box.selectionStart = startPos
box.selectionEnd = texts[0].length + texts[1].length + tagClose.length

$box
.trigger 'bbcode:inserted' # for react
.trigger 'input' # ignored by react
.focus()
box.dispatchEvent(new InputEvent('input', bubbles: true))
box.focus()

[
['bold', '[b]', '[/b]']
Expand Down
2 changes: 0 additions & 2 deletions resources/js/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import LandingGraph from 'core-legacy/landing-graph'
import Menu from 'core-legacy/menu'
import NavButton from 'core-legacy/nav-button'
import Nav2 from 'core-legacy/nav2'
import PostPreview from 'core-legacy/post-preview'
import Search from 'core-legacy/search'
import { StoreCheckout } from 'core-legacy/store-checkout'
import TooltipDefault from 'core-legacy/tooltip-default'
Expand Down Expand Up @@ -60,7 +59,6 @@ window.globalDrag ?= new GlobalDrag
window.landingGraph ?= new LandingGraph
window.menu ?= new Menu
window.navButton ?= new NavButton
window.postPreview ?= new PostPreview
window.search ?= new Search
window.tooltipDefault ?= new TooltipDefault

Expand Down
3 changes: 3 additions & 0 deletions resources/js/osu-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import AccountEdit from 'core/account-edit';
import AccountEditAvatar from 'core/account-edit-avatar';
import AccountEditBlocklist from 'core/account-edit-blocklist';
import AnimateNav from 'core/animate-nav';
import BbcodeAutoPreview from 'core/bbcode-auto-preview';
import BrowserTitleWithNotificationCount from 'core/browser-title-with-notification-count';
import Captcha from 'core/captcha';
import ClickMenu from 'core/click-menu';
Expand Down Expand Up @@ -49,6 +50,7 @@ export default class OsuCore {
readonly accountEditAvatar;
readonly accountEditBlocklist;
readonly animateNav;
readonly bbcodeAutoPreview;
readonly beatmapsetSearchController;
readonly browserTitleWithNotificationCount;
readonly captcha;
Expand Down Expand Up @@ -102,6 +104,7 @@ export default class OsuCore {
$.subscribe('user:update', this.onCurrentUserUpdate);

this.animateNav = new AnimateNav();
this.bbcodeAutoPreview = new BbcodeAutoPreview();
this.captcha = new Captcha();
this.chatWorker = new ChatWorker();
this.clickMenu = new ClickMenu();
Expand Down
1 change: 1 addition & 0 deletions resources/views/admin/contests/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<form
action="{{ route('admin.contests.get-zip', $contest->id) }}"
data-loading-overlay="0"
data-turbo="false"
method="POST"
>
@csrf
Expand Down

0 comments on commit 70d7931

Please sign in to comment.