Skip to content

Commit 589ea90

Browse files
committed
chore: remove unused code
- arknights.ts (replaced by level.ts) - account activation - fetcher
1 parent 61694a9 commit 589ea90

File tree

9 files changed

+4
-490
lines changed

9 files changed

+4
-490
lines changed

src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { TokenManager } from 'utils/token-manager'
77

88
import { GlobalErrorBoundary } from './components/GlobalErrorBoundary'
99
import { FCC } from './types'
10-
import { request } from './utils/fetcher'
1110

1211
// jotai 在没有 Provider 时会使用默认的 store
1312
TokenManager.setAuthGetter(() => getDefaultStore().get(authAtom))
@@ -18,7 +17,6 @@ export const App: FCC = ({ children }) => {
1817
<>
1918
<SWRConfig
2019
value={{
21-
fetcher: request,
2220
focusThrottleInterval: 1000 * 60,
2321
errorRetryInterval: 1000 * 3,
2422
errorRetryCount: 3,

src/apis/arknights.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/apis/auth.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Response } from 'models/network'
2-
import { jsonRequest } from 'utils/fetcher'
31
import { UserApi } from 'utils/maa-copilot-client'
42

53
export async function sendRegistrationEmail(req: { email: string }) {
@@ -72,26 +70,3 @@ export function resetPassword(req: {
7270
passwordResetDTO: req,
7371
})
7472
}
75-
76-
export interface ActivationResponse {}
77-
78-
export const requestActivation = (code: string) => {
79-
return jsonRequest<Response<ActivationResponse>>('/user/activate', {
80-
method: 'POST',
81-
json: {
82-
token: code,
83-
},
84-
})
85-
}
86-
87-
export interface ActivationCodeResponse {}
88-
89-
export const requestActivationCode = () => {
90-
return jsonRequest<Response<ActivationCodeResponse>>(
91-
'/user/activate/request',
92-
{
93-
method: 'POST',
94-
json: {},
95-
},
96-
)
97-
}

src/components/AccountManager.tsx

Lines changed: 3 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
Dialog,
55
H4,
66
Icon,
7-
InputGroup,
87
Menu,
98
MenuDivider,
109
MenuItem,
@@ -15,20 +14,13 @@ import {
1514
} from '@blueprintjs/core'
1615
import { Popover2 } from '@blueprintjs/popover2'
1716

18-
import { requestActivation, requestActivationCode } from 'apis/auth'
19-
import { useAtom } from 'jotai'
20-
import { ComponentType, FC, useMemo, useRef, useState } from 'react'
21-
import { FieldValues, useController, useForm } from 'react-hook-form'
17+
import { useAtom, useSetAtom } from 'jotai'
18+
import { ComponentType, FC, useState } from 'react'
2219

2320
import { LoginPanel } from 'components/account/LoginPanel'
24-
import { EditorFieldProps } from 'components/editor/EditorFieldProps'
2521
import { authAtom } from 'store/auth'
26-
import { NetworkError } from 'utils/error'
2722
import { useCurrentSize } from 'utils/useCurrenSize'
28-
import { useNetworkState } from 'utils/useNetworkState'
29-
import { wrapErrorMessage } from 'utils/wrapErrorMessage'
3023

31-
import { FormField2 } from './FormField'
3224
import {
3325
GlobalErrorBoundary,
3426
withGlobalErrorBoundary,
@@ -37,139 +29,9 @@ import { AppToaster } from './Toaster'
3729
import { EditDialog } from './account/EditDialog'
3830
import { RegisterPanel } from './account/RegisterPanel'
3931

40-
interface ActivationFormValues {
41-
code: string
42-
}
43-
44-
const ActivationDialog: FC<{
45-
isOpen?: boolean
46-
onClose: () => void
47-
}> = ({ isOpen, onClose }) => {
48-
const {
49-
control,
50-
handleSubmit,
51-
formState: { errors, isValid, isDirty, isSubmitting },
52-
} = useForm<ActivationFormValues>()
53-
54-
const [authState, setAuthState] = useAtom(authAtom)
55-
const latestAuthState = useRef(authState)
56-
latestAuthState.current = authState
57-
58-
const onSubmit = async ({ code }) => {
59-
await wrapErrorMessage(
60-
(e: NetworkError) => `激活失败:${e.message}`,
61-
requestActivation(code),
62-
)
63-
64-
setAuthState({
65-
...latestAuthState.current,
66-
activated: true,
67-
})
68-
69-
AppToaster.show({
70-
message: '激活成功',
71-
intent: 'success',
72-
})
73-
74-
onClose()
75-
}
76-
77-
return (
78-
<Dialog
79-
className="w-full max-w-xl"
80-
isOpen={isOpen}
81-
title="激活 MAA Copilot 账户"
82-
icon="key"
83-
onClose={onClose}
84-
>
85-
<form onSubmit={handleSubmit(onSubmit)}>
86-
<div className="flex flex-col px-4 pt-4">
87-
<FormField2
88-
field="code"
89-
label="激活码"
90-
description="激活码可在您注册时使用的邮箱中找到"
91-
error={errors.code}
92-
>
93-
<ActivationInputGroup name="code" control={control} />
94-
</FormField2>
95-
96-
<Button
97-
disabled={(!isValid && !isDirty) || isSubmitting}
98-
intent="primary"
99-
loading={isSubmitting}
100-
type="submit"
101-
icon="envelope"
102-
large
103-
>
104-
激活
105-
</Button>
106-
</div>
107-
</form>
108-
</Dialog>
109-
)
110-
}
111-
112-
const ActivationInputGroup = <T extends FieldValues>({
113-
name,
114-
control,
115-
}: EditorFieldProps<T>) => {
116-
const {
117-
field: { onChange, onBlur, ref },
118-
} = useController({
119-
name,
120-
control,
121-
rules: { required: '请输入激活码' },
122-
})
123-
124-
return (
125-
<div className="flex">
126-
<InputGroup
127-
large
128-
leftIcon="lock"
129-
onChange={onChange}
130-
onBlur={onBlur}
131-
placeholder="请输入您的激活码"
132-
ref={ref}
133-
className="flex-grow font-mono"
134-
autoComplete="off"
135-
// eslint-disable-next-line jsx-a11y/no-autofocus
136-
autoFocus
137-
/>
138-
<ActivationCodeRequestButton />
139-
</div>
140-
)
141-
}
142-
143-
const ActivationCodeRequestButton: FC = () => {
144-
const { networkState, start, finish } = useNetworkState()
145-
146-
const handleClick = () => {
147-
start()
148-
wrapErrorMessage(
149-
(e: NetworkError) => `获取激活码失败:${e.message}`,
150-
requestActivationCode(),
151-
)
152-
.then(() => {
153-
finish(null)
154-
AppToaster.show({
155-
message: '激活码已发送至您的邮箱',
156-
intent: 'success',
157-
})
158-
})
159-
.catch((e) => finish(e))
160-
}
161-
162-
return (
163-
<Button icon="reset" onClick={handleClick} loading={networkState.loading}>
164-
重新发送
165-
</Button>
166-
)
167-
}
168-
16932
const AccountMenu: FC = () => {
170-
const [authState, setAuthState] = useAtom(authAtom)
33+
const setAuthState = useSetAtom(authAtom)
17134
const [logoutDialogOpen, setLogoutDialogOpen] = useState(false)
172-
const [activationDialogOpen, setActivationDialogOpen] = useState(false)
17335
const [editDialogOpen, setEditDialogOpen] = useState(false)
17436

17537
const handleLogout = () => {
@@ -180,21 +42,6 @@ const AccountMenu: FC = () => {
18042
})
18143
}
18244

183-
const menuItems = useMemo(() => {
184-
const items: JSX.Element[] = []
185-
if (!authState.activated) {
186-
items.push(
187-
<MenuItem
188-
shouldDismissPopover={false}
189-
icon="key"
190-
text="激活账户..."
191-
onClick={() => setActivationDialogOpen(true)}
192-
/>,
193-
)
194-
}
195-
return items
196-
}, [authState])
197-
19845
return (
19946
<>
20047
<Alert
@@ -211,11 +58,6 @@ const AccountMenu: FC = () => {
21158
<p>确定要退出登录吗?</p>
21259
</Alert>
21360

214-
<ActivationDialog
215-
isOpen={activationDialogOpen}
216-
onClose={() => setActivationDialogOpen(false)}
217-
/>
218-
21961
<EditDialog
22062
isOpen={editDialogOpen}
22163
onClose={() => setEditDialogOpen(false)}
@@ -229,9 +71,6 @@ const AccountMenu: FC = () => {
22971
onClick={() => setEditDialogOpen(true)}
23072
/>
23173
<MenuDivider />
232-
{menuItems}
233-
234-
{menuItems.length > 0 && <MenuDivider />}
23574

23675
<MenuItem
23776
shouldDismissPopover={false}

src/components/account/AccountActivator.tsx

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)