Skip to content

Commit e50cbb5

Browse files
committed
Show team icon in app nav
1 parent a67b349 commit e50cbb5

File tree

6 files changed

+94
-5
lines changed

6 files changed

+94
-5
lines changed

src/components/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ const App = () => {
199199
id: team.id,
200200
name: team.name,
201201
domain: team.domain,
202+
iconUrl: team.iconUrl,
202203
}
203204
}),
204205
})

src/components/molecules/AppNavigatorBoostHubTeamItem.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const Container = styled.div`
1616
border-width: 3px;
1717
border-style: solid;
1818
border-color: transparent;
19+
&:hover {
20+
border-color: ${({ theme }) => theme.borderColor};
21+
}
1922
&.active {
2023
border-color: ${({ theme }) => theme.textColor};
2124
}
@@ -34,6 +37,11 @@ const MainButton = styled.button`
3437
border: 1px solid ${({ theme }) => theme.teamSwitcherBorderColor};
3538
color: ${({ theme }) => theme.teamSwitcherTextColor};
3639
font-size: 13px;
40+
& > .icon {
41+
width: 36px;
42+
height: 36px;
43+
border-radius: 8px;
44+
}
3745
3846
&:hover,
3947
&:active,
@@ -53,12 +61,14 @@ interface AppNavigatorBoostHubTeamItemProps {
5361
domain: string
5462
name: string
5563
active: boolean
64+
iconUrl?: string
5665
}
5766

5867
const AppNavigatorBoostHubTeamItem = ({
5968
active,
6069
domain,
6170
name,
71+
iconUrl,
6272
}: AppNavigatorBoostHubTeamItemProps) => {
6373
const { push } = useRouter()
6474

@@ -73,7 +83,11 @@ const AppNavigatorBoostHubTeamItem = ({
7383
onClick={navigateToTeam}
7484
>
7585
<MainButton className={active ? 'active' : ''} onClick={navigateToTeam}>
76-
{name.slice(0, 1)}
86+
{iconUrl == null ? (
87+
name.slice(0, 1)
88+
) : (
89+
<img className='icon' src={iconUrl} />
90+
)}
7791
</MainButton>
7892
</Container>
7993
)

src/components/organisms/AppNavigator.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const TopLevelNavigator = () => {
6565
active={activeBoostHubTeamDomain === boostHubTeam.domain}
6666
name={boostHubTeam.name}
6767
domain={boostHubTeam.domain}
68+
iconUrl={boostHubTeam.iconUrl}
6869
/>
6970
)
7071
})

src/components/organisms/BoostHubSignInForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const BoostHubSignInForm = () => {
8585
id: team.id,
8686
name: team.name,
8787
domain: team.domain,
88+
iconUrl: team.iconUrl,
8889
}
8990
}),
9091
})

src/lib/boosthub.tsx

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { WebviewTag } from 'electron'
66
import React, { useRef, useCallback, FC } from 'react'
77
import { createStoreContext } from './context'
88
import querystring from 'querystring'
9+
import { useEffectOnce } from 'react-use'
910

1011
export const boostHubBaseUrl = process.env.BOOST_HUB_BASE_URL as string
1112

@@ -25,6 +26,10 @@ export function getBoostHubTeamPageUrl(teamName: string) {
2526
return `${boostHubBaseUrl}/${teamName}`
2627
}
2728

29+
export function getBoostHubTeamIconUrl(location: string) {
30+
return `${boostHubBaseUrl}/api/files/icons/${location}`
31+
}
32+
2833
export const boostHubTeamsCreatePageUrl = `${boostHubBaseUrl}/cooperate`
2934

3035
export const boostHubIdlePageUrl = `${boostHubBaseUrl}/api/desktop/idle`
@@ -41,17 +46,49 @@ export const boostHubPreloadUrl = formatUrl({
4146
const boostHubDesktopLoginApiUrl = `${boostHubBaseUrl}/api/desktop/login`
4247
const boostHubDesktopGlobalDataUrl = `${boostHubBaseUrl}/api/desktop`
4348
const boostHubSignOutUrl = `${boostHubBaseUrl}/api/desktop/signout`
49+
let domReady = false
50+
const domReadyQueue = [] as { resolve?: () => void; reject?: () => void }[]
51+
52+
function waitDomReady() {
53+
const queue: { resolve?: () => void; reject?: () => void } = {}
54+
const promise = new Promise((resolve, reject) => {
55+
if (domReady) {
56+
console.log('dom ready no wait')
57+
resolve()
58+
return
59+
}
60+
queue.resolve = resolve
61+
queue.reject = reject
62+
domReadyQueue.push(queue)
63+
})
64+
65+
return promise
66+
}
4467

4568
function useBoostHubStore() {
4669
const webviewRef = useRef<WebviewTag>(null)
4770

71+
useEffectOnce(() => {
72+
webviewRef.current!.addEventListener('dom-ready', () => {
73+
domReady = true
74+
let queue = domReadyQueue.shift()
75+
while (queue != null) {
76+
if (queue.resolve != null) {
77+
queue.resolve()
78+
}
79+
queue = domReadyQueue.shift()
80+
}
81+
})
82+
})
83+
4884
const fetchJson = useCallback(
4985
async (
5086
url: string,
5187
options?: {
5288
method: string
5389
}
5490
) => {
91+
await waitDomReady()
5592
const { method } = {
5693
method: 'get',
5794
...options,
@@ -72,13 +109,30 @@ function useBoostHubStore() {
72109
const fetchDesktopGlobalData = useCallback(async () => {
73110
const data = await fetchJson(boostHubDesktopGlobalDataUrl)
74111

75-
return data as {
112+
return {
113+
user: {
114+
id: data.user.id,
115+
uniqueName: data.user.uniqueName,
116+
displayName: data.user.displayName,
117+
},
118+
teams: data.teams.map((team: any) => {
119+
return {
120+
id: team.id,
121+
name: team.name,
122+
domain: team.domain,
123+
iconUrl:
124+
team.icon != null
125+
? getBoostHubTeamIconUrl(team.icon.location)
126+
: undefined,
127+
}
128+
}),
129+
} as {
76130
user: {
77131
id: string
78132
uniqueName: string
79133
displayName: string
80134
}
81-
teams: { id: string; domain: string; name: string }[]
135+
teams: { id: string; name: string; domain: string; iconUrl?: string }[]
82136
}
83137
}, [fetchJson])
84138

@@ -88,13 +142,30 @@ function useBoostHubStore() {
88142
{ method: 'post' }
89143
)
90144

91-
return data as {
145+
return {
146+
user: {
147+
id: data.user.id,
148+
uniqueName: data.user.uniqueName,
149+
displayName: data.user.displayName,
150+
},
151+
teams: data.teams.map((team: any) => {
152+
return {
153+
id: team.id,
154+
name: team.name,
155+
domain: team.domain,
156+
iconUrl:
157+
team.icon != null
158+
? getBoostHubTeamIconUrl(team.icon.location)
159+
: undefined,
160+
}
161+
}),
162+
} as {
92163
user: {
93164
id: string
94165
uniqueName: string
95166
displayName: string
96167
}
97-
teams: { id: string; domain: string; name: string }[]
168+
teams: { id: string; name: string; domain: string; iconUrl?: string }[]
98169
}
99170
}
100171
const signOut = useCallback(async () => {

src/lib/generalStatus.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface GeneralStatus {
1717
id: string
1818
name: string
1919
domain: string
20+
iconUrl?: string
2021
}[]
2122
}
2223

0 commit comments

Comments
 (0)