-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.jsx
105 lines (95 loc) · 3.09 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React from 'react'
import * as u from 'patchkit-util'
import t from 'patchwork-translations'
export class UserLink extends React.Component {
static contextTypes = {
users: React.PropTypes.object,
toUrl: React.PropTypes.func
}
render() {
const name = this.context.users.names[this.props.id] || u.shortString(this.props.id, 6)
const label = (this.props.shorten) ? name.slice(0, 3) : name
return <a href={this.context.toUrl(this.props.id)} className={this.props.className||"user-link"} title={name}>{label}</a>
}
}
export class MsgLink extends React.Component {
static contextTypes = {
toUrl: React.PropTypes.func
}
render() {
return <a href={this.context.toUrl(this.props.id)} className={this.props.className}>{this.props.children||this.props.name||this.props.id}</a>
}
}
export class BlobLink extends React.Component {
static contextTypes = {
toUrl: React.PropTypes.func
}
render() {
return <a href={this.context.toUrl(this.props.id)} className={this.props.className}>{this.props.children||this.props.name||this.props.id}</a>
}
}
export class UserLinks extends React.Component {
static contextTypes = {
users: React.PropTypes.object
}
render() {
let ids = this.props.ids
let n = this.props.ids.length
// apply limit
const limit = this.props.limit
let overLimitNames = false
let nOver = 0
if (n > limit) {
overLimitNames = ids.slice(limit).map(id => u.getName(this.context.users, id)).join(', ')
nOver = n - limit
ids = ids.slice(0, limit)
n = limit
}
return <span>
{ids.map((id, i) => {
let isLast = (i === n-1)
return <span key={id} ><UserLink id={id} shorten={this.props.shorten} />{isLast ? '' : ', '}</span>
})}
{overLimitNames
? <span className="hint--top" data-hint={overLimitNames}> {t('namesAndOthers', nOver)}</span>
: '' }
</span>
}
}
export class UserPic extends React.Component {
static contextTypes = {
users: React.PropTypes.object,
toUrl: React.PropTypes.func
}
render() {
const name = this.context.users.names[this.props.id] || u.shortString(this.props.id, 6)
return <a href={this.context.toUrl(this.props.id)} className="user-pic hint--top" data-hint={name}>
<img src={u.getProfilePicUrl(this.context.users, this.props.id, this.context.toUrl)} />
</a>
}
}
export class UserPics extends React.Component {
static contextTypes = {
users: React.PropTypes.object
}
render() {
let ids = this.props.ids
let n = this.props.ids.length
// apply limit
const limit = this.props.limit
let overLimitNames = false
let nOver = 0
if (n > limit) {
overLimitNames = ids.slice(limit).map(id => u.getName(this.context.users, id)).join(', ')
nOver = n - limit
ids = ids.slice(0, limit)
n = limit
}
return <span>
{ids.map((id, i) => <UserPic id={id} key={`pic-${i}`} hovertips={this.props.hovertips} />)}
{overLimitNames
? <span className="hint--top" data-hint={overLimitNames}> {t('namesAndOthers', nOver)}</span>
: '' }
</span>
}
}