Skip to content

Commit 2d29edf

Browse files
committed
refactor: simplifying with providerMap
Signed-off-by: nicolasschneider <[email protected]>
1 parent 281a904 commit 2d29edf

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

plugins/login-resources/src/components/Providers.svelte

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
2-
import { concatLink, type ProviderInfo } from '@hcengineering/core'
2+
import { concatLink } from '@hcengineering/core'
33
import { getMetadata } from '@hcengineering/platform'
4+
import { type ProviderInfo } from '@hcengineering/account-client'
45
import { AnySvelteComponent, Button, Grid, deviceOptionsStore, getCurrentLocation } from '@hcengineering/ui'
56
import { onMount } from 'svelte'
67
import login from '../plugin'
@@ -12,41 +13,27 @@
1213
interface Provider {
1314
name: string
1415
component: AnySvelteComponent
15-
displayName: null
16+
displayName?: string
1617
}
1718
18-
const providers: Provider[] = [
19-
{
20-
name: 'google',
21-
component: Google,
22-
displayName: null
23-
},
24-
{
25-
name: 'github',
26-
component: Github,
27-
displayName: null
28-
},
29-
{
30-
name: 'openid',
31-
component: OpenId,
32-
displayName: null
33-
}
34-
]
19+
const providerMap: Record<string, AnySvelteComponent> = {
20+
google: Google,
21+
github: Github,
22+
openid: OpenId
23+
}
3524
3625
let enabledProviders: Provider[] = []
3726
3827
onMount(() => {
3928
void getProviders().then((res: ProviderInfo[]) => {
40-
enabledProviders = providers
29+
enabledProviders = res
4130
.map((provider) => {
42-
const match = res.find((r) => r.name === provider.name)
43-
if (!match) return null
31+
const component = providerMap[provider.name]
4432
return {
4533
...provider,
46-
displayName: match.displayName
34+
component
4735
}
4836
})
49-
.filter((p): p is Provider & { displayName: string } => p !== null)
5037
})
5138
})
5239

0 commit comments

Comments
 (0)