feature: support new GitHub token format

This commit is contained in:
EnixCoda 2021-04-13 22:23:36 +08:00
parent 48d2053851
commit 70981ed72a
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD

View file

@ -8,7 +8,7 @@ import * as React from 'react'
import { useStateIO } from 'utils/hooks/useStateIO'
import { SettingsSection } from './SettingsSection'
const ACCESS_TOKEN_REGEXP = /^[0-9a-f]+$/
const ACCESS_TOKEN_REGEXP = /^([0-9a-fA-F]+|gh[pousr]_[A-Za-z0-9_]+)$/
type Props = {}
@ -37,30 +37,33 @@ export function AccessTokenSettings(props: React.PropsWithChildren<Props>) {
[],
)
const onPressAccessToken = React.useCallback(({ key }: React.KeyboardEvent) => {
if (key === 'Enter') saveToken()
}, [])
const saveToken = React.useCallback(
async (hint?: typeof useAccessTokenHint.value) => {
async (
hint: typeof useAccessTokenHint.value = (
<span>
<a href="#" onClick={() => window.location.reload()}>
Reload
</a>{' '}
to activate!
</span>
),
) => {
if (accessToken) {
configContext.onChange({ accessToken })
useAccessToken.onChange('')
useAccessTokenHint.onChange(
hint || (
<span>
<a href="#" onClick={() => window.location.reload()}>
Reload
</a>{' '}
to activate!
</span>
),
)
useAccessTokenHint.onChange(hint)
}
},
[accessToken],
)
const onPressAccessToken = React.useCallback(
({ key }: React.KeyboardEvent) => {
if (key === 'Enter') saveToken()
},
[saveToken],
)
return (
<SettingsSection
title={
@ -121,7 +124,7 @@ export function AccessTokenSettings(props: React.PropsWithChildren<Props>) {
</div>
</div>
)}
{accessTokenHint && !focusInput.value && <span className={'hint'}>{accessTokenHint}</span>}
{accessTokenHint && <span className={'hint'}>{accessTokenHint}</span>}
</SettingsSection>
)
}