Skip to content

Commit

Permalink
Merge branch 'master' into wiki-page
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko authored Jul 5, 2023
2 parents b38e617 + e12724c commit 2a6c7b7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
4 changes: 2 additions & 2 deletions resources/js/chat/chat-state-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { clamp, maxBy } from 'lodash';
import { action, autorun, computed, makeObservable, observable, observe, runInAction } from 'mobx';
import Channel from 'models/chat/channel';
import CreateAnnouncement from 'models/chat/create-announcement';
import core from 'osu-core-singleton';
import ChannelStore from 'stores/channel-store';
import { onError } from 'utils/ajax';
import { setBrowserTitle } from 'utils/html';
import { trans } from 'utils/lang';
import { updateQueryString } from 'utils/url';
import ChannelJoinEvent from './channel-join-event';
Expand Down Expand Up @@ -184,7 +184,7 @@ export default class ChatStateStore implements DispatchListener {

Turbolinks.controller[mode](updateQueryString(null, params, ''));
}
setBrowserTitle(`${channel.name} · ${trans('page_title.main.chat_controller._')}`);
core.browserTitleWithNotificationCount.title = `${channel.name} · ${trans('page_title.main.chat_controller._')}`;
}

@action
Expand Down
43 changes: 43 additions & 0 deletions resources/js/core/browser-title-with-notification-count.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 { action, autorun, makeObservable, observable, runInAction } from 'mobx';
import OsuCore from 'osu-core';
import { formatNumber } from 'utils/html';

export default class BrowserTitleWithNotificationCount {
private disposer?: () => void;
@observable private origTitle = '';

set title(newTitle: string) {
runInAction(() => {
this.origTitle = `${newTitle} | osu!`;
});
}

constructor(private core: OsuCore) {
makeObservable(this);
document.addEventListener('turbolinks:load', this.setTitle);
document.addEventListener('turbolinks:before-cache', this.resetTitle);
}

@action
private readonly resetTitle = () => {
document.title = this.origTitle;
this.disposer?.();
};

@action
private readonly setTitle = () => {
this.origTitle = document.title;

this.disposer = autorun(() => {
const count = this.core.dataStore.notificationStore.unreadStacks.total;
const titlePrefix = count === 0
? ''
: `(${formatNumber(count)}) `;

document.title = `${titlePrefix}${this.origTitle}`;
});
};
}
3 changes: 3 additions & 0 deletions resources/js/osu-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { BeatmapsetSearchController } from 'beatmaps/beatmapset-search-controller';
import ChatWorker from 'chat/chat-worker';
import BrowserTitleWithNotificationCount from 'core/browser-title-with-notification-count';
import Captcha from 'core/captcha';
import ClickMenu from 'core/click-menu';
import Enchant from 'core/enchant';
Expand Down Expand Up @@ -36,6 +37,7 @@ import { parseJsonNullable } from 'utils/json';
// will this replace main.coffee eventually?
export default class OsuCore {
readonly beatmapsetSearchController;
readonly browserTitleWithNotificationCount;
readonly captcha;
readonly chatWorker;
readonly clickMenu;
Expand Down Expand Up @@ -94,6 +96,7 @@ export default class OsuCore {
this.forumPostReport = new ForumPostReport();
this.localtime = new Localtime();
this.mobileToggle = new MobileToggle();
this.browserTitleWithNotificationCount = new BrowserTitleWithNotificationCount(this);
this.referenceLinkTooltip = new ReferenceLinkTooltip();
this.scorePins = new ScorePins();
this.stickyHeader = new StickyHeader();
Expand Down
4 changes: 0 additions & 4 deletions resources/js/utils/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ export function make2x(url?: string) {
return url.replace(/(\.[^.]+)$/, '@2x$1');
}

export function setBrowserTitle(title: string) {
document.title = `${title} | osu!`;
}

export function stripTags(str: string) {
return str.replace(/<[^>]*>/g, '');
}

0 comments on commit 2a6c7b7

Please sign in to comment.