Skip to content

Commit 2533d6e

Browse files
authored
Merge pull request #123 from MaaAssistantArknights/dev
feat: API changes & announcement
2 parents a0bfb0c + 93eff83 commit 2533d6e

28 files changed

+1272
-177
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
<body>
3232
<main id="root"></main>
3333
<script type="module" src="/src/main.tsx"></script>
34+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown-light.min.css" integrity="sha512-zb2pp+R+czM7GAemdSUQt6jFmr3qCo6ikvBgVU6F5GvwEDR0C2sefFiPEJ9QUpmAKdD5EqDUdNRtbOYnbF/eyQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
3435
</body>
3536
</html>

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"scripts:update-operator-avatars": "yarn install && esno scripts/update-operator-avatars.ts"
2020
},
2121
"dependencies": {
22-
"@blueprintjs/core": "^4.5.1",
23-
"@blueprintjs/popover2": "^1.4.1",
24-
"@blueprintjs/select": "^4.4.1",
22+
"@blueprintjs/core": "^4.15.1",
23+
"@blueprintjs/popover2": "^1.12.1",
24+
"@blueprintjs/select": "^4.8.18",
2525
"@dnd-kit/core": "^6.0.5",
2626
"@dnd-kit/sortable": "^7.0.1",
2727
"@dnd-kit/utilities": "^3.2.0",
@@ -46,11 +46,13 @@
4646
"react": "^18.0.0",
4747
"react-dom": "^18.0.0",
4848
"react-hook-form": "^7.33.1",
49+
"react-markdown": "^8.0.5",
4950
"react-rating": "^2.0.5",
5051
"react-rnd": "^10.4.1",
5152
"react-router-dom": "6",
5253
"react-spring": "^9.4.5",
5354
"react-use": "^17.4.0",
55+
"remark-gfm": "^3.0.1",
5456
"snakecase-keys": "^5.4.4",
5557
"swr": "^2.0.0-rc.3",
5658
"type-fest": "^2.16.0",

src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const App: FCC = ({ children }) => {
1616
value={{
1717
fetcher: request,
1818
provider: localStorageProvider,
19-
suspense: true,
2019
focusThrottleInterval: 1000 * 60,
2120
errorRetryInterval: 1000 * 3,
2221
errorRetryCount: 3,

src/apis/announcement.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import useSWR from 'swr'
2+
3+
import mockFile from './mock/announcements.md?url'
4+
5+
const isMock = process.env.NODE_ENV === 'development'
6+
7+
const announcementURL = isMock
8+
? mockFile
9+
: 'https://ota.maa.plus/MaaAssistantArknights/api/announcements/copilot.md'
10+
11+
export const announcementBaseURL = isMock
12+
? location.href
13+
: announcementURL.slice(0, announcementURL.lastIndexOf('/') + 1)
14+
15+
export function useAnnouncement() {
16+
return useSWR<string>(
17+
announcementURL,
18+
(url) =>
19+
fetch(url)
20+
.then((res) => res.text())
21+
.catch((e) => {
22+
if ((e as Error).message === 'Failed to fetch') {
23+
console.warn(e)
24+
throw new Error('网络错误')
25+
}
26+
27+
throw e
28+
}),
29+
{
30+
refreshInterval: 1000 * 60 * 60,
31+
},
32+
)
33+
}

src/apis/arknights.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const useVersion = () => {
1616
})
1717
}
1818

19-
export const useLevels = ({ suspense = true }: { suspense?: boolean } = {}) => {
19+
export const useLevels = ({ suspense }: { suspense?: boolean } = {}) => {
2020
const url = '/arknights/level'
2121
type LevelResponse = Response<Level[]>
2222

src/apis/copilotOperation.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface OperationUploadResponse {
77
id: string
88
}
99

10-
export const requestGetOperation = (id: string) => {
10+
export const requestGetOperation = (id: Operation['id']) => {
1111
return jsonRequest<Response<Operation>>('/copilot/get/' + id)
1212
}
1313

@@ -20,7 +20,10 @@ export const requestOperationUpload = (content: string) => {
2020
})
2121
}
2222

23-
export const requestOperationUpdate = (id: string, content: string) => {
23+
export const requestOperationUpdate = (
24+
id: Operation['id'],
25+
content: string,
26+
) => {
2427
return jsonRequest<Response<OperationUploadResponse>>('/copilot/update', {
2528
method: 'POST',
2629
json: {
@@ -30,7 +33,7 @@ export const requestOperationUpdate = (id: string, content: string) => {
3033
})
3134
}
3235

33-
export const requestDeleteOperation = (id: string) => {
36+
export const requestDeleteOperation = (id: Operation['id']) => {
3437
return jsonRequest<Response<OperationUploadResponse>>(`/copilot/delete`, {
3538
method: 'POST',
3639
json: {

src/apis/mock/announcements.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!--
2+
可以写注释,会过滤掉
3+
TODO: 支持 HTML 标签
4+
-->
5+
6+
## 格式说明
7+
8+
```json
9+
{
10+
"time": "2023-02-09T11:07:56.620Z"
11+
}
12+
```
13+
14+
每个标题对应一则公告,# 号数量任意
15+
16+
每个标题下面紧跟着的 json code block 会被隐藏,并解析为该则公告的 meta 信息
17+
18+
公告内就不能再写副标题了,不然会解析为一则新的公告
19+
20+
![](android-chrome-512x512.png)
21+
22+
## JSON 内容
23+
24+
```json
25+
{
26+
"time": "2023-02-09T11:07:56.620Z"
27+
}
28+
```
29+
30+
**time**
31+
32+
发布时间,如果用户在该时间之前没有打开过网页,则会以弹窗的形式显示该公告
33+
34+
> 可以打开浏览器控制台运行 `new Date().toISOString()` 以生成
35+
36+
**level**
37+
38+
- verbose: 一般公告,永远不会弹窗显示
39+
- info: 默认值
40+
- warning: 警告,暂时和 info 没区别
41+
42+
## 历史公告
43+
44+
```json
45+
{
46+
"time": "1970-02-09T11:07:56.620Z"
47+
}
48+
```
49+
50+
文件内的所有公告都会显示在列表中,如果不想显示某则公告,可以注释掉或者直接删掉

src/apis/query.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
PaginatedResponse,
1010
} from 'models/operation'
1111

12-
import { parseShortCode, shortCodeProtocol } from '../models/shortCode'
12+
import { parseShortCode, shortCodeScheme } from '../models/shortCode'
1313

1414
export type OrderBy = 'views' | 'hot' | 'id'
1515

@@ -19,6 +19,7 @@ export interface UseOperationsParams {
1919
levelKeyword?: string
2020
operator?: string
2121
byMyself?: boolean
22+
suspense?: boolean
2223
}
2324

2425
export const useOperations = ({
@@ -27,16 +28,17 @@ export const useOperations = ({
2728
levelKeyword,
2829
operator,
2930
byMyself,
31+
suspense,
3032
}: UseOperationsParams) => {
31-
const isIdQuery = document?.startsWith(shortCodeProtocol)
33+
const isIdQuery = document?.startsWith(shortCodeScheme)
3234

3335
const {
3436
data: listData,
3537
size,
3638
setSize,
3739
isValidating,
3840
} = useSWRInfinite<Response<PaginatedResponse<OperationListItem>>>(
39-
(_pageIndex, previousPageData) => {
41+
(pageIndex, previousPageData) => {
4042
if (isIdQuery) {
4143
return null
4244
}
@@ -45,10 +47,7 @@ export const useOperations = ({
4547
return null // reached the end
4648
}
4749
const searchParams = new URLSearchParams('?desc=true&limit=50')
48-
searchParams.set(
49-
'page',
50-
((previousPageData?.data?.page || 0) + 1).toString(),
51-
)
50+
searchParams.set('page', (pageIndex + 1).toString())
5251
searchParams.set('order_by', orderBy)
5352
if (document) {
5453
searchParams.set('document', document)
@@ -65,6 +64,10 @@ export const useOperations = ({
6564

6665
return `/copilot/query?${searchParams.toString()}`
6766
},
67+
{
68+
suspense,
69+
focusThrottleInterval: 1000 * 60 * 30,
70+
},
6871
)
6972

7073
const { data: singleData } = useSWR<Response<Operation>>(
@@ -80,11 +83,18 @@ export const useOperations = ({
8083

8184
useEffect(() => {
8285
setSize(1)
83-
}, [orderBy, document, levelKeyword, operator])
86+
}, [orderBy, document, levelKeyword, operator, isIdQuery])
8487

8588
return { operations, size, setSize, isValidating, isReachingEnd }
8689
}
8790

88-
export const useOperation = (id: string | undefined) => {
89-
return useSWR<Response<Operation>>(id ? `/copilot/get/${id}` : null)
91+
export interface UseOperationParams {
92+
id?: Operation['id']
93+
suspense?: boolean
94+
}
95+
96+
export const useOperation = ({ id, suspense }: UseOperationParams) => {
97+
return useSWR<Response<Operation>>(id ? `/copilot/get/${id}` : null, {
98+
suspense,
99+
})
90100
}

src/apis/rating.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Response } from 'models/network'
22
import { OpRatingType, Operation } from 'models/operation'
33
import { jsonRequest } from 'utils/fetcher'
44

5-
export const apiPostRating = (id: string, rating: OpRatingType) => {
5+
export const apiPostRating = (id: Operation['id'], rating: OpRatingType) => {
66
return jsonRequest<
77
Response<Pick<Operation, 'id' | 'ratingRatio' | 'ratingType'>>
88
>('/copilot/rating', {

src/components/OperationCard.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const OperationCard = ({
3030
operation: OperationListItem
3131
operationDoc: CopilotDocV1.Operation
3232
}) => {
33-
const levels = useLevels({ suspense: false })?.data?.data || []
33+
const levels = useLevels()?.data?.data || []
3434
const [drawerOpen, setDrawerOpen] = useState(false)
3535
return (
3636
<>
@@ -53,7 +53,7 @@ export const OperationCard = ({
5353
>
5454
<div className="flex items-start">
5555
<H4 className="inline-block pb-1 border-b-2 border-zinc-200 border-solid mb-2">
56-
{operation.title}
56+
{operationDoc.doc.title}
5757
</H4>
5858
<div className="flex-1" />
5959
<div className="flex flex-col items-end">
@@ -102,7 +102,6 @@ export const OperationCard = ({
102102
<H5 className="flex items-center text-slate-900 -mt-3">
103103
<EDifficultyLevel
104104
level={
105-
operation.level ||
106105
findLevelByStageName(levels, operationDoc.stageName) ||
107106
createCustomLevel(operationDoc.stageName)
108107
}
@@ -112,7 +111,7 @@ export const OperationCard = ({
112111
<div className="flex">
113112
<div className="text-gray-700 leading-normal w-1/2">
114113
{/* <div className="text-sm text-zinc-600 mb-2 font-bold">作业描述</div> */}
115-
<Paragraphs content={operation.detail} linkify />
114+
<Paragraphs content={operationDoc.doc.details} linkify />
116115
</div>
117116
<div className="w-1/2 ml-4">
118117
<div className="text-sm text-zinc-600 mb-2 font-bold">

0 commit comments

Comments
 (0)