Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
@import "bem/beatmap-discussions";
@import "bem/beatmap-discussions-header-bottom";
@import "bem/beatmap-discussions-header-top";
@import "bem/beatmap-user-tag-picker";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just call it beatmap-tag-picker instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this would make it too ambiguous whether it concerns mapper tags or user tags. not sure how those are generally named throughout the project

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. except the mapper tag is attached to beatmapset, not beatmap. and I think user tag is referred as beatmap tag everywhere

@import "bem/beatmap-icon";
@import "bem/beatmap-list";
@import "bem/beatmap-list-item";
Expand Down Expand Up @@ -441,7 +442,6 @@
@import "bem/user-search-card";
@import "bem/user-session-list";
@import "bem/user-session-list-session";
@import "bem/user-tag-picker";
@import "bem/user-verification";
@import "bem/user-verification-popup";
@import "bem/username-change";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.user-tag-picker {
.beatmap-user-tag-picker {
@padding: 20px;

@search-container-offset: 46px; // 45px search icon width + 1px search container border
Expand Down
9 changes: 7 additions & 2 deletions resources/js/beatmaps/search-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

import { FilterKey } from 'beatmapset-search-filters';
import BeatmapUserTagPicker from 'components/beatmap-user-tag-picker';
import BeatmapsetCover from 'components/beatmapset-cover';
import PopupMenu from 'components/popup-menu';
import PopupMenuState from 'components/popup-menu-state';
Expand All @@ -16,7 +17,6 @@ import { htmlElementOrNull } from 'utils/html';
import { trans } from 'utils/lang';
import AvailableFilters, { FilterOption } from './available-filters';
import { SearchFilter } from './search-filter';
import UserTagPicker from './user-tag-picker';

interface Props {
availableFilters: AvailableFilters;
Expand Down Expand Up @@ -217,7 +217,12 @@ export class SearchPanel extends React.Component<Props> {
<i className='fas fa-tag' />
</button>
<PopupMenu direction='left' skipButton state={this.tagPopupMenuState}>
{() => <UserTagPicker />}
{() => (<BeatmapUserTagPicker
isTagEnabled={this.controller.filters.tagEnabled}
onDisabled={this.controller.filters.tagRemove}
onEnabled={this.controller.filters.tagAdd}
showAllRulesets={this.controller.filters.mode === null}
/>)}
</PopupMenu>
<div className='beatmapsets-search__icon'>
<i className='fas fa-search' />
Expand Down
77 changes: 0 additions & 77 deletions resources/js/beatmaps/user-tag-picker.tsx

This file was deleted.

11 changes: 7 additions & 4 deletions resources/js/beatmapset-search-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class BeatmapsetSearchFilters {
}

@action
tagAdd(tag: BeatmapTag) {
tagAdd = (tag: BeatmapTag) => {
const currentQuery = this.query;
const tagString = tag.toQuery();

Expand All @@ -144,10 +144,13 @@ export class BeatmapsetSearchFilters {
: `${tagString} `;

this.update('query', newQuery);
}
};

tagEnabled = (tag: BeatmapTag) =>
(this.query ?? '').toLowerCase().includes(tag.toQuery().toLowerCase());

@action
tagRemove(tag: BeatmapTag) {
tagRemove = (tag: BeatmapTag) => {
const currentQuery = this.query;

if (currentQuery === null) {
Expand All @@ -159,7 +162,7 @@ export class BeatmapsetSearchFilters {
.replace(' ', ' ')
.trim();
this.update('query', newQuery);
}
};

toKeyString() {
return keyNames.map((key) => `${key}=${this.selectedValue(key)}`).join('&');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface TagGroup {
tags: BeatmapTag[];
}

export default class UserTagPickerController {
export default class BeatmapUserTagPickerController {
@observable query: string = '';
@observable tags: BeatmapTag[] = [];

Expand Down
77 changes: 77 additions & 0 deletions resources/js/components/beatmap-user-tag-picker.tsx

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do a two steps commit - one renaming the file, and another one updating the file. Otherwise the history won't get carried over to the new file

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import { rulesetNames, rulesets } from 'interfaces/ruleset';
import { action } from 'mobx';
import { observer } from 'mobx-react';
import BeatmapTag from 'models/beatmap-tag';
import core from 'osu-core-singleton';
import React, { useCallback, useEffect, useRef } from 'react';
import { classWithModifiers } from 'utils/css';
import { trans } from 'utils/lang';

const controller = core.beatmapTagPickerController;

const onChange = action((e: React.ChangeEvent<HTMLInputElement>) => controller.query = e.target.value);

interface Props {
isTagEnabled: (tag: BeatmapTag) => boolean;
onDisabled: (tag: BeatmapTag) => void;
onEnabled: (tag: BeatmapTag) => void;
showAllRulesets: boolean;
}

export default observer(function BeatmapUserTagPicker(props: Props) {
const inputRef = useRef<HTMLInputElement>(null);

useEffect(() => {
inputRef.current?.focus();
}, []);

return (
<div className='beatmap-user-tag-picker'>
<input
ref={inputRef}
className='beatmap-user-tag-picker__search'
name='tag-search'
onChange={onChange}
placeholder={trans('beatmaps.listing.search.tag_picker.prompt')}
value={controller.query}
/>
<div className='beatmap-user-tag-picker__scroll-area u-fancy-scrollbar'>
<div className='beatmap-user-tag-picker__list'>
{controller.groups.map((group) => (
<React.Fragment key={group.name}>
<span className='beatmap-user-tag-picker__category'>{group.name}</span>
{group.tags.map((tag) => <UserTag key={tag.id} props={props} tag={tag} />)}
</React.Fragment>
))}
</div>
</div>
</div>
);
});

const UserTag = observer(function UserTag({ tag, props }: { props: Props; tag: BeatmapTag }) {
const active = props.isTagEnabled(tag);

const onClick = useCallback(() => {
if (!active) {
props.onEnabled(tag);
} else {
props.onDisabled(tag);
}
}, [tag, active, props]);

const hasAllRulesets = tag.rulesetIds.length === rulesets.length;

return (<div className={classWithModifiers('beatmap-user-tag-picker__tag', { active })} onClick={onClick}>
<span className='beatmap-user-tag-picker__tag-info beatmap-user-tag-picker__tag-info--name'>{tag.tagName}</span>
<span className='beatmap-user-tag-picker__tag-info beatmap-user-tag-picker__tag-info--description'>
{props.showAllRulesets && !hasAllRulesets && tag.rulesetIds.map((rulesetId) => (<React.Fragment key={rulesetId}>
<span className={`fal fa-extra-mode-${rulesetNames[rulesetId]}`} />{' '}
</React.Fragment>))}
{tag.description}
</span>
</div>);
});
4 changes: 2 additions & 2 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 BeatmapUserTagPickerController from 'components/beatmap-user-tag-picker-controller';
import AccountEdit from 'core/account-edit';
import AccountEditAvatar from 'core/account-edit-avatar';
import AccountEditBlocklist from 'core/account-edit-blocklist';
Expand Down Expand Up @@ -46,7 +47,6 @@ import NotificationsWorker from 'notifications/worker';
import SocketWorker from 'socket-worker';
import RootDataStore from 'stores/root-data-store';
import { parseJsonNullable } from 'utils/json';
import UserTagPickerController from './beatmaps/user-tag-picker-controller';

// will this replace main.coffee eventually?
export default class OsuCore {
Expand Down Expand Up @@ -156,7 +156,7 @@ export default class OsuCore {
this.windowFocusObserver = new WindowFocusObserver();

this.beatmapsetSearchController = new BeatmapsetSearchController(this.dataStore.beatmapsetSearch);
this.beatmapTagPickerController = new UserTagPickerController();
this.beatmapTagPickerController = new BeatmapUserTagPickerController();

this.socketWorker = new SocketWorker();
this.notificationsWorker = new NotificationsWorker(this.socketWorker);
Expand Down