Skip to content

Commit

Permalink
Update own user suggestions in teambuilder (#21340)
Browse files Browse the repository at this point in the history
* feat: add special YouResult card for new chat results

* feat: ensure you are always the most interesting person

* chore: update stories with new searchresult field

* chore: fix alphabetical ordering in story
  • Loading branch information
cori-hudson committed Dec 3, 2019
1 parent 300b3b2 commit 266205f
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 13 deletions.
9 changes: 7 additions & 2 deletions go/service/user.go
Expand Up @@ -269,9 +269,7 @@ func (h *UserHandler) InterestingPeople(ctx context.Context, maxUsers int) (res
fallbackFn := func(uid keybase1.UID) (uids []keybase1.UID, err error) {
uids = []keybase1.UID{
libkb.GetUIDByNormalizedUsername(h.G(), "hellobot"),
h.G().GetEnv().GetUID(),
}

return uids, nil
}

Expand Down Expand Up @@ -303,6 +301,13 @@ func (h *UserHandler) InterestingPeople(ctx context.Context, maxUsers int) (res
serviceMaps := h.G().ServiceMapper.MapUIDsToServiceSummaries(ctx, h.G(), uids,
serviceMapFreshness, uidmap.DisallowNetworkBudget)

// The most interesting person of all... you
you := keybase1.InterestingPerson{
Uid: h.G().GetEnv().GetUID(),
Username: h.G().GetEnv().GetUsername().String(),
}
res = append(res, you)

for i, uid := range uids {
if packages[i].NormalizedUsername.IsNil() {
// We asked UIDMapper for cached data only, this username was missing.
Expand Down
2 changes: 2 additions & 0 deletions shared/team-building/__test__/team-building.test.tsx
Expand Up @@ -12,6 +12,7 @@ describe('team building list', () => {
followingState: 'NotFollowing',
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: '',
services: {},
userId: '',
Expand Down Expand Up @@ -139,6 +140,7 @@ describe('team building list', () => {
followingState: 'NotFollowing' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
key: '',
prettyName: '',
services: {},
Expand Down
1 change: 1 addition & 0 deletions shared/team-building/container.tsx
Expand Up @@ -88,6 +88,7 @@ const expensiveDeriveResults = (
followingState: Constants.followStateHelperWithId(myUsername, followingState, info.serviceMap.keybase),
inTeam: [...teamSoFar].some(u => u.id === info.id),
isPreExistingTeamMember: preExistingTeamMembers.has(info.id),
isYou: info.username === myUsername,
key: [info.id, info.prettyName, info.label, String(!!info.contact)].join('&'),
prettyName: formatAnyPhoneNumbers(info.prettyName),
services: info.serviceMap,
Expand Down
17 changes: 17 additions & 0 deletions shared/team-building/index.stories.tsx
Expand Up @@ -65,6 +65,7 @@ const makeUserResults = results =>
services={result.services}
followingState={result.followingState}
highlight={result.highlight}
isYou={result.isYou}
inTeam={result.inTeam}
isPreExistingTeamMember={result.isPreExistingTeamMember}
onAdd={Sb.action('onAdd')}
Expand All @@ -85,6 +86,7 @@ const makePeopleResults = results =>
highlight={result.highlight}
inTeam={result.inTeam}
isPreExistingTeamMember={result.isPreExistingTeamMember}
isYou={result.isYou}
onAdd={Sb.action('onAdd')}
onRemove={Sb.action('onRemove')}
/>
Expand Down Expand Up @@ -175,6 +177,7 @@ const load = () => {
followingState: 'Following' as const,
inTeam: true,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Coyne',
services: {
facebook: 'chriscoyne',
Expand All @@ -193,6 +196,7 @@ const load = () => {
followingState: 'NotFollowing' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Mikacle',
services: {
github: 'chrismikacle',
Expand All @@ -210,6 +214,7 @@ const load = () => {
followingState: 'Following' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Nojima',
services: {
github: 'cnojima',
Expand Down Expand Up @@ -272,6 +277,7 @@ const load = () => {
followingState: 'Following' as const,
inTeam: true,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Coyne',
services: {
facebook: 'chriscoyne',
Expand All @@ -290,6 +296,7 @@ const load = () => {
followingState: 'NotFollowing' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Mikacle',
services: {
github: 'chrismikacle',
Expand All @@ -307,6 +314,7 @@ const load = () => {
followingState: 'Following' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Nojima',
services: {
github: 'cnojima',
Expand Down Expand Up @@ -416,6 +424,7 @@ const load = () => {
followingState: 'Following' as const,
inTeam: true,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Coyne',
services: {
facebook: 'chriscoyne',
Expand All @@ -434,6 +443,7 @@ const load = () => {
followingState: 'NotFollowing' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Mikacle',
services: {
github: 'chrismikacle',
Expand All @@ -451,6 +461,7 @@ const load = () => {
followingState: 'Following' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Nojima',
services: {
github: 'cnojima',
Expand Down Expand Up @@ -494,6 +505,7 @@ const load = () => {
followingState: 'Following' as const,
inTeam: true,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Coyne',
services: {
facebook: 'chriscoyne',
Expand All @@ -512,6 +524,7 @@ const load = () => {
followingState: 'NotFollowing' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Mikacle',
services: {
github: 'chrismikacle',
Expand All @@ -529,6 +542,7 @@ const load = () => {
followingState: 'Following' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Nojima',
services: {
github: 'cnojima',
Expand Down Expand Up @@ -572,6 +586,7 @@ const load = () => {
followingState: 'Following' as const,
inTeam: true,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Coyne',
services: {
facebook: 'chriscoyne',
Expand All @@ -590,6 +605,7 @@ const load = () => {
followingState: 'NotFollowing' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Mikacle',
services: {
github: 'chrismikacle',
Expand All @@ -607,6 +623,7 @@ const load = () => {
followingState: 'Following' as const,
inTeam: false,
isPreExistingTeamMember: false,
isYou: false,
prettyName: 'Chris Nojima',
services: {
github: 'cnojima',
Expand Down
3 changes: 3 additions & 0 deletions shared/team-building/index.tsx
Expand Up @@ -42,6 +42,7 @@ export type SearchResult = {
services: {[K in ServiceIdWithContact]?: string}
inTeam: boolean
isPreExistingTeamMember: boolean
isYou: boolean
followingState: FollowingState
}

Expand Down Expand Up @@ -483,6 +484,7 @@ class TeamBuilding extends React.PureComponent<Props> {
services={result.services}
inTeam={result.inTeam}
isPreExistingTeamMember={result.isPreExistingTeamMember}
isYou={result.isYou}
followingState={result.followingState}
highlight={
!Styles.isMobile &&
Expand Down Expand Up @@ -530,6 +532,7 @@ class TeamBuilding extends React.PureComponent<Props> {
services={result.services}
inTeam={result.inTeam}
isPreExistingTeamMember={result.isPreExistingTeamMember}
isYou={result.isYou}
followingState={result.followingState}
highlight={!Styles.isMobile && index === this.props.highlightedIndex}
onAdd={() => this.props.onAdd(result.userId)}
Expand Down
26 changes: 15 additions & 11 deletions shared/team-building/search-result/common-result.tsx
Expand Up @@ -13,6 +13,7 @@ import {
export type ResultProps = {
// They are already a member in the actual team, not this temporary set.
isPreExistingTeamMember: boolean
isYou: boolean
resultForService: Types.ServiceIdWithContact
username: string
prettyName: string
Expand All @@ -24,6 +25,7 @@ export type ResultProps = {
onAdd: () => void
onRemove: () => void
rightButtons?: React.ReactNode
bottomRow?: React.ReactNode
}

export type CommonResultProps = ResultProps & {
Expand Down Expand Up @@ -80,16 +82,18 @@ const CommonResult = (props: CommonResultProps) => {
keybaseUsername={keybaseUsername}
username={serviceUsername || ''}
/>
<BottomRow
displayLabel={props.displayLabel}
followingState={props.followingState}
isKeybaseResult={isKeybaseResult}
isPreExistingTeamMember={props.isPreExistingTeamMember}
keybaseUsername={keybaseUsername}
prettyName={props.prettyName}
services={props.services}
username={serviceUsername || ''}
/>
{props.bottomRow ?? (
<BottomRow
displayLabel={props.displayLabel}
followingState={props.followingState}
isKeybaseResult={isKeybaseResult}
isPreExistingTeamMember={props.isPreExistingTeamMember}
keybaseUsername={keybaseUsername}
prettyName={props.prettyName}
services={props.services}
username={serviceUsername || ''}
/>
)}
</>
) : (
<>
Expand All @@ -112,7 +116,7 @@ const CommonResult = (props: CommonResultProps) => {
style={props.highlight ? styles.actionButtonsHighlighted : undefined}
>
{/* Renders checkbox for new-chat and team-building, and chat buttons + dropdown for people search */}
{props.rightButtons ? props.rightButtons : null}
{props.rightButtons ?? null}
</Kb.Box2>
</Kb.Box2>
</Kb.ClickableBox>
Expand Down
5 changes: 5 additions & 0 deletions shared/team-building/search-result/user-result.tsx
Expand Up @@ -2,8 +2,13 @@ import * as React from 'react'
import * as Kb from '../../common-adapters'
import * as Styles from '../../styles'
import CommonResult, {ResultProps} from './common-result'
import YouResult from './you-result'

const UserResult = React.memo((props: ResultProps) => {
if (props.isYou) {
return <YouResult {...props} />
}

return (
<CommonResult
{...props}
Expand Down
50 changes: 50 additions & 0 deletions shared/team-building/search-result/you-result.tsx
@@ -0,0 +1,50 @@
import * as React from 'react'
import * as Kb from '../../common-adapters'
import * as Styles from '../../styles'
import * as Container from '../../util/container'
import * as Chat2Gen from '../../actions/chat2-gen'
import * as TeamBuildingGen from '../../actions/team-building-gen'
import CommonResult, {ResultProps} from './common-result'

const YouResult = React.memo((props: ResultProps) => {
const dispatch = Container.useDispatch()
const onSelfChat = () => {
dispatch(TeamBuildingGen.createCancelTeamBuilding({namespace: 'chat2'}))
dispatch(Chat2Gen.createPreviewConversation({participants: [props.username], reason: 'search'}))
}
return (
<CommonResult
{...props}
onAdd={onSelfChat}
rowStyle={styles.rowContainer}
bottomRow={<Kb.Text type="BodySmall">Write secure notes to yourself</Kb.Text>}
/>
)
})

const styles = Styles.styleSheetCreate(() => ({
actionButton: Styles.platformStyles({
common: {
marginLeft: Styles.globalMargins.tiny,
},
isElectron: {
height: Styles.globalMargins.small,
width: Styles.globalMargins.small,
},
isMobile: {
height: Styles.globalMargins.large,
marginRight: Styles.globalMargins.tiny,
width: Styles.globalMargins.large,
},
}),
rowContainer: {
...Styles.padding(
Styles.globalMargins.tiny,
Styles.globalMargins.medium,
Styles.globalMargins.tiny,
Styles.globalMargins.xsmall
),
},
}))

export default YouResult

0 comments on commit 266205f

Please sign in to comment.