tangled
alpha
login
or
join now
keii.dev
/
osu-web
0
fork
atom
the browser-facing portion of osu!
0
fork
atom
overview
issues
pulls
pipelines
convert osu.groupColour to typescript
bakaneko
3 years ago
6ef65bc7
14ec0f8f
+56
-49
11 changed files
expand all
collapse all
unified
split
resources
assets
coffee
osu_common.coffee
lib
beatmap-discussions
discussion.coffee
user-card.tsx
user-filter.coffee
components
user-card-brick.tsx
user-group-badge.tsx
globals.d.ts
modding-profile
votes.coffee
utils
css.ts
tests
karma
osu_common.spec.ts
utils
css.spec.ts
-4
resources/assets/coffee/osu_common.coffee
reviewed
···
5
5
import { currentUrl } from 'utils/turbolinks'
6
6
7
7
window.osu =
8
8
-
groupColour: (group) ->
9
9
-
'--group-colour': group?.colour ? 'initial'
10
10
-
11
11
-
12
8
formatBytes: (bytes, decimals=2) ->
13
9
suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
14
10
k = 1000
+2
-2
resources/assets/lib/beatmap-discussions/discussion.coffee
reviewed
···
8
8
import { button, div, i, span, a } from 'react-dom-factories'
9
9
import { onError } from 'utils/ajax'
10
10
import { badgeGroup, canModeratePosts, formatTimestamp } from 'utils/beatmapset-discussion-helper'
11
11
-
import { classWithModifiers } from 'utils/css'
11
11
+
import { classWithModifiers, groupColour } from 'utils/css'
12
12
import { hideLoadingOverlay, showLoadingOverlay } from 'utils/loading-overlay'
13
13
import { discussionTypeIcons } from './discussion-type'
14
14
import { NewReply } from './new-reply'
···
76
76
div className: "#{bn}__discussion",
77
77
div
78
78
className: "#{bn}__top"
79
79
-
style: osu.groupColour(group)
79
79
+
style: groupColour(group)
80
80
div className: "#{bn}__top-user",
81
81
el UserCard,
82
82
user: user
+2
-1
resources/assets/lib/beatmap-discussions/user-card.tsx
reviewed
···
7
7
import UserJson from 'interfaces/user-json';
8
8
import { route } from 'laroute';
9
9
import * as React from 'react';
10
10
+
import { groupColour } from 'utils/css';
10
11
11
12
const bn = 'beatmap-discussion-user-card';
12
13
···
23
24
24
25
render() {
25
26
return (
26
26
-
<div className={bn} style={osu.groupColour(this.props.group)}>
27
27
+
<div className={bn} style={groupColour(this.props.group)}>
27
28
<div className={`${bn}__avatar`}>
28
29
{this.props.user.is_deleted ? (
29
30
<span className={`${bn}__user-link`}>
+2
-1
resources/assets/lib/beatmap-discussions/user-filter.coffee
reviewed
···
5
5
import { SelectOptions } from 'components/select-options'
6
6
import * as React from 'react'
7
7
import { a } from 'react-dom-factories'
8
8
+
import { groupColour } from 'utils/css'
8
9
9
10
el = React.createElement
10
11
···
47
48
48
49
renderOption: ({ cssClasses, children, onClick, option }) =>
49
50
group = if @isOwner(option) then mapperGroup else option.groups?[0]
50
50
-
style = osu.groupColour(group)
51
51
+
style = groupColour(group)
51
52
52
53
a
53
54
className: cssClasses
+2
-2
resources/assets/lib/components/user-card-brick.tsx
reviewed
···
9
9
import core from 'osu-core-singleton';
10
10
import * as React from 'react';
11
11
import UserCardTypeContext from 'user-card-type-context';
12
12
-
import { classWithModifiers, Modifiers } from 'utils/css';
12
12
+
import { classWithModifiers, groupColour, Modifiers } from 'utils/css';
13
13
14
14
interface Props {
15
15
modifiers?: Modifiers;
···
67
67
>
68
68
<div
69
69
className='user-card-brick__group-bar'
70
70
-
style={osu.groupColour(group)}
70
70
+
style={groupColour(group)}
71
71
title={group?.name}
72
72
/>
73
73
+2
-2
resources/assets/lib/components/user-group-badge.tsx
reviewed
···
4
4
import UserGroupJson from 'interfaces/user-group-json';
5
5
import { route } from 'laroute';
6
6
import * as React from 'react';
7
7
-
import { classWithModifiers, Modifiers } from 'utils/css';
7
7
+
import { classWithModifiers, groupColour, Modifiers } from 'utils/css';
8
8
9
9
interface Props {
10
10
group?: UserGroupJson | null;
···
44
44
modifiers,
45
45
),
46
46
'data-label': group.short_name,
47
47
-
style: osu.groupColour(group),
47
47
+
style: groupColour(group),
48
48
title,
49
49
};
50
50
-2
resources/assets/lib/globals.d.ts
reviewed
···
11
11
// There interfaces are only used in this file.
12
12
declare module 'legacy-modules' {
13
13
type BeatmapsetDiscussionJson = import('interfaces/beatmapset-discussion-json').default;
14
14
-
type GroupJson = import('interfaces/group-json').default;
15
14
16
15
interface BeatmapDiscussionHelperClass {
17
16
url(options: any, useCurrent?: boolean): string;
···
28
27
29
28
interface OsuCommon {
30
29
formatBytes: (bytes: number, decimals?: number) => string;
31
31
-
groupColour: (group?: GroupJson | null) => React.CSSProperties;
32
30
navigate: (url: string, keepScroll?: boolean, action?: Partial<Record<string, unknown>>) => void;
33
31
popup: (message: string, type: string) => void;
34
32
presence: (str?: string | null) => string | null;
+2
-1
resources/assets/lib/modding-profile/votes.coffee
reviewed
···
7
7
import { route } from 'laroute'
8
8
import * as React from 'react'
9
9
import { a, div, h1, h2, span } from 'react-dom-factories'
10
10
+
import { groupColour } from 'utils/css'
10
11
11
12
el = React.createElement
12
13
···
34
35
bn = 'modding-profile-vote-card'
35
36
userBadge = user.groups?[0]
36
37
topClasses = bn
37
37
-
style = osu.groupColour(userBadge)
38
38
+
style = groupColour(userBadge)
38
39
39
40
div
40
41
key: user.id
+11
resources/assets/lib/utils/css.ts
reviewed
···
1
1
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
2
2
// See the LICENCE file in the repository root for full licence text.
3
3
4
4
+
import GroupJson from 'interfaces/group-json';
4
5
import { forEach } from 'lodash';
6
6
+
7
7
+
declare module 'react' {
8
8
+
export interface CSSProperties {
9
9
+
'--group-colour'?: string;
10
10
+
}
11
11
+
}
5
12
6
13
export type Modifiers = (string | null | undefined)[] | Partial<Record<string, boolean | null | undefined>> | string | null | undefined;
7
14
···
31
38
eachModifier(modifiersArray, (m) => ret += ` ${className}--${m}`);
32
39
33
40
return ret;
41
41
+
}
42
42
+
43
43
+
export function groupColour(group?: GroupJson | null) {
44
44
+
return { '--group-colour': group?.colour ?? 'initial' };
34
45
}
35
46
36
47
export function mergeModifiers(...modifiersArray: Modifiers[]) {
-33
tests/karma/osu_common.spec.ts
reviewed
···
1
1
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
2
2
// See the LICENCE file in the repository root for full licence text.
3
3
4
4
-
import GroupJson from 'interfaces/group-json';
5
5
-
import * as React from 'react';
6
4
describe('osu_common', () => {
7
5
describe('locale file loaded in test runner', () => {
8
6
it('should be loaded', () => {
9
7
expect(window.Lang.has('common.confirmation')).toBe(true);
10
10
-
});
11
11
-
});
12
12
-
13
13
-
describe('groupColour', () => {
14
14
-
const group: GroupJson = {
15
15
-
colour: '#abcdef',
16
16
-
has_listing: true,
17
17
-
has_playmodes: true,
18
18
-
id: 1,
19
19
-
identifier: 'abc',
20
20
-
is_probationary: false,
21
21
-
name: 'ABC',
22
22
-
short_name: 'abc',
23
23
-
};
24
24
-
25
25
-
it('get CSS object with correct colour', () => {
26
26
-
expect(osu.groupColour(group)).toEqual({
27
27
-
'--group-colour': '#abcdef',
28
28
-
} as React.CSSProperties);
29
29
-
});
30
30
-
31
31
-
it('get CSS object with initial value when null', () => {
32
32
-
expect(osu.groupColour({ ...group, colour: null })).toEqual({
33
33
-
'--group-colour': 'initial',
34
34
-
} as React.CSSProperties);
35
35
-
});
36
36
-
37
37
-
it('get CSS object with initial value when undefined', () => {
38
38
-
expect(osu.groupColour()).toEqual({
39
39
-
'--group-colour': 'initial',
40
40
-
} as React.CSSProperties);
41
8
});
42
9
});
43
10
+33
-1
tests/karma/utils/css.spec.ts
reviewed
···
1
1
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
2
2
// See the LICENCE file in the repository root for full licence text.
3
3
4
4
-
import { urlPresence } from 'utils/css';
4
4
+
import GroupJson from 'interfaces/group-json';
5
5
+
import { groupColour, urlPresence } from 'utils/css';
5
6
6
7
describe('utils/css', () => {
8
8
+
describe('.groupColour', () => {
9
9
+
const group: GroupJson = {
10
10
+
colour: '#abcdef',
11
11
+
has_listing: true,
12
12
+
has_playmodes: true,
13
13
+
id: 1,
14
14
+
identifier: 'abc',
15
15
+
is_probationary: false,
16
16
+
name: 'ABC',
17
17
+
short_name: 'abc',
18
18
+
};
19
19
+
20
20
+
it('get CSS object with correct colour', () => {
21
21
+
expect(groupColour(group)).toEqual({
22
22
+
'--group-colour': '#abcdef',
23
23
+
});
24
24
+
});
25
25
+
26
26
+
it('get CSS object with initial value when null', () => {
27
27
+
expect(groupColour({ ...group, colour: null })).toEqual({
28
28
+
'--group-colour': 'initial',
29
29
+
});
30
30
+
});
31
31
+
32
32
+
it('get CSS object with initial value when undefined', () => {
33
33
+
expect(groupColour()).toEqual({
34
34
+
'--group-colour': 'initial',
35
35
+
});
36
36
+
});
37
37
+
});
38
38
+
7
39
describe('.urlPresence', () => {
8
40
describe('when url is empty', () => {
9
41
const cases = [