Listen for Return in Settings page (#281)

Fixes #279
This commit is contained in:
Pierre Jacquier
2023-07-05 06:42:48 -04:00
committed by GitHub
parent e57319d6d4
commit 60181540e6
2 changed files with 14 additions and 0 deletions

View File

@ -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,

View File

@ -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>