|
| 1 | +package components |
| 2 | + |
| 3 | +import ( |
| 4 | + "code.gitea.io/gitea/models/user" |
| 5 | + "code.gitea.io/gitea/modules/setting" |
| 6 | + templates "code.gitea.io/gitea/modules/templates" |
| 7 | + "code.gitea.io/gitea/modules/translation" |
| 8 | + "code.gitea.io/gitea/services/context" |
| 9 | + g "maragu.dev/gomponents" |
| 10 | + gh "maragu.dev/gomponents/html" |
| 11 | +) |
| 12 | + |
| 13 | +type UserListProps struct { |
| 14 | + Users []*user.User |
| 15 | + // ContextUser *user.User |
| 16 | + IsSigned bool |
| 17 | + PageIsAdminUsers bool |
| 18 | + Locale translation.Locale |
| 19 | + Context *context.Context |
| 20 | +} |
| 21 | + |
| 22 | +func UserList(data UserListProps) g.Node { |
| 23 | + tr := func(key string, args ...any) string { |
| 24 | + return string(data.Locale.Tr(key, args...)) |
| 25 | + } |
| 26 | + |
| 27 | + if len(data.Users) == 0 { |
| 28 | + return gh.Div( |
| 29 | + gh.Class("flex-list"), |
| 30 | + gh.Div( |
| 31 | + gh.Class("flex-item"), |
| 32 | + g.Text(tr("search.no_results")), |
| 33 | + ), |
| 34 | + ) |
| 35 | + } |
| 36 | + |
| 37 | + return gh.Div( |
| 38 | + gh.Class("flex-list"), |
| 39 | + g.Group(g.Map(data.Users, func(u *user.User) g.Node { |
| 40 | + utils := templates.NewAvatarUtils(data.Context) |
| 41 | + |
| 42 | + return gh.Div( |
| 43 | + gh.Class("flex-item tw-items-center"), |
| 44 | + gh.Div( |
| 45 | + gh.Class("flex-item-leading"), |
| 46 | + g.Raw(string(utils.Avatar(u, 48))), |
| 47 | + ), |
| 48 | + gh.Div( |
| 49 | + gh.Class("flex-item-main"), |
| 50 | + gh.Div( |
| 51 | + gh.Class("flex-item-title"), |
| 52 | + UserName(UserNameProps{ |
| 53 | + Locale: data.Locale, |
| 54 | + User: u, |
| 55 | + }), |
| 56 | + If(u.Visibility.IsPrivate(), |
| 57 | + gh.Span( |
| 58 | + gh.Class("ui basic tiny label"), |
| 59 | + g.Text(tr("repo.desc.private")), |
| 60 | + ), |
| 61 | + ), |
| 62 | + ), |
| 63 | + gh.Div( |
| 64 | + gh.Class("flex-item-body"), |
| 65 | + If(u.Location != "", |
| 66 | + gh.Span( |
| 67 | + gh.Class("flex-text-inline"), |
| 68 | + SVG("octicon-location", 16), |
| 69 | + g.Text(u.Location), |
| 70 | + ), |
| 71 | + ), |
| 72 | + If(u.Email != "" && (data.PageIsAdminUsers || (setting.UI.ShowUserEmail && data.IsSigned && !u.KeepEmailPrivate)), |
| 73 | + gh.Span( |
| 74 | + gh.Class("flex-text-inline"), |
| 75 | + SVG("octicon-mail", 16), |
| 76 | + gh.A( |
| 77 | + gh.Href("mailto:"+u.Email), |
| 78 | + g.Text(u.Email), |
| 79 | + ), |
| 80 | + ), |
| 81 | + ), |
| 82 | + gh.Span( |
| 83 | + gh.Class("flex-text-inline"), |
| 84 | + SVG("octicon-calendar", 16), |
| 85 | + g.Raw(tr("user.joined_on", templates.NewDateUtils().AbsoluteShort(u.CreatedUnix))), |
| 86 | + ), |
| 87 | + ), |
| 88 | + ), |
| 89 | + ) |
| 90 | + })), |
| 91 | + ) |
| 92 | +} |
0 commit comments