@ -70,31 +70,39 @@ function KittycadHelper() {
|
||||
export function Settings() {
|
||||
const [githubUser, setGithubUser] = useState<User>()
|
||||
const [kittycadUser, setKittycadUser] = useState<KittycadUser>()
|
||||
const [githubLoading, setGithubLoading] = useState(false)
|
||||
const [kittycadLoading, setKittycadLoading] = useState(false)
|
||||
const [firstInitDone, setFirstInitDone] = useState(false)
|
||||
|
||||
async function fetchGithubUser() {
|
||||
try {
|
||||
setGithubLoading(true)
|
||||
const response = await chrome.runtime.sendMessage({
|
||||
id: MessageIds.GetGithubUser,
|
||||
})
|
||||
if ('error' in response) throw response.error
|
||||
setGithubUser(response as User)
|
||||
setGithubLoading(false)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
setGithubUser(undefined)
|
||||
setGithubLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchKittycadUser() {
|
||||
try {
|
||||
setKittycadLoading(true)
|
||||
const response = await chrome.runtime.sendMessage({
|
||||
id: MessageIds.GetKittycadUser,
|
||||
})
|
||||
if ('error' in response) throw response.error
|
||||
setKittycadUser(response as KittycadUser)
|
||||
setKittycadLoading(false)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
setKittycadUser(undefined)
|
||||
setKittycadLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,6 +148,7 @@ export function Settings() {
|
||||
) : (
|
||||
<TokenForm
|
||||
service="GitHub"
|
||||
loading={githubLoading}
|
||||
onToken={async (token: string) => {
|
||||
await onToken(
|
||||
MessageIds.SaveGithubToken,
|
||||
@ -174,6 +183,7 @@ export function Settings() {
|
||||
) : (
|
||||
<TokenForm
|
||||
service="KittyCAD"
|
||||
loading={kittycadLoading}
|
||||
onToken={async (token: string) => {
|
||||
await onToken(
|
||||
MessageIds.SaveKittycadToken,
|
||||
|
||||
@ -3,11 +3,13 @@ import { useState, PropsWithChildren } from 'react'
|
||||
|
||||
export type TokenFormProps = {
|
||||
service: string
|
||||
loading: boolean
|
||||
onToken: (token: string) => void
|
||||
}
|
||||
|
||||
export function TokenForm({
|
||||
service,
|
||||
loading,
|
||||
onToken,
|
||||
children,
|
||||
}: PropsWithChildren<TokenFormProps>) {
|
||||
@ -20,7 +22,9 @@ export function TokenForm({
|
||||
<TextInput
|
||||
alt="Text input for token"
|
||||
value={token}
|
||||
loading={loading}
|
||||
onChange={e => setToken(e.target.value)}
|
||||
onKeyDown={e => e.key === 'Enter' && onToken(token)}
|
||||
/>
|
||||
{children}
|
||||
</FormControl>
|
||||
|
||||
Reference in New Issue
Block a user