Skip to content

Commit

Permalink
Merge pull request #303 from MaaAssistantArknights/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
guansss authored Jun 19, 2024
2 parents 5f34b64 + 9361b2d commit 7743c79
Show file tree
Hide file tree
Showing 44 changed files with 466 additions and 82 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 2024-06-19

- 修复了不能通过神秘代码搜索作业集的问题 [@guansss](https://github.com/guansss)
- 增加了对未激活账号的提示 [@guansss](https://github.com/guansss)
- 在作业编辑器中添加了额外的提交按钮 [@aojunhao123](https://github.com/aojunhao123)
- 添加了 Google Analytics [@AlisaAkiron](https://github.com/AlisaAkiron)
- 改善了 SEO [@HauKuen](https://github.com/HauKuen)
- 修复暗黑模式下干员筛选标签背景色 [@aojunhao123](https://github.com/aojunhao123)
- 搜索时填写的包含/排除干员将会自动保存 [@zhangchi0104](https://github.com/zhangchi0104)
- 修复了切换搜索模式时输入框显示不正常的问题 [@guansss](https://github.com/guansss)
- 修复了暗黑模式的一些显示问题 [@ssoda01](https://github.com/ssoda01)

## 2024-04-03

- 修复了因部分作业缺少动作列表而渲染失败的问题
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="MAA作业站 — 为MAA用户提供JSON作业" />
<meta name="keywords" content="明日方舟,作业站,自动刷图,明日方舟作业站" />
<title>MAA Copilot</title>

<link
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"prettier": "^3.2.5",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-ga-neo": "^2.2.0",
"react-hook-form": "^7.33.1",
"react-markdown": "^8.0.5",
"react-rating": "^2.0.5",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/operator-avatars/char_4131_odda.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/operator-avatars/char_446_aroma.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 58 additions & 1 deletion src/apis/operation-set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useAtomValue } from 'jotai'
import { noop } from 'lodash-es'
import {
CopilotSetPageRes,
CopilotSetQuery,
Expand All @@ -11,6 +12,8 @@ import { authAtom } from 'store/auth'
import { OperationSetApi } from 'utils/maa-copilot-client'
import { useSWRRefresh } from 'utils/swr'

import { parseShortCode } from '../models/shortCode'

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

export interface UseOperationSetsParams {
Expand Down Expand Up @@ -81,7 +84,61 @@ export function useOperationSets({

export function useRefreshOperationSets() {
const refresh = useSWRRefresh()
return () => refresh((key) => key.includes('operationSets'))
return () =>
refresh(
(key) =>
key.includes('operationSets') ||
(key.includes('operationSet') && key.includes('fromList')),
)
}

export function useOperationSetSearch({
keyword,
suspense,
disabled,
...params
}: UseOperationSetsParams) {
if (!suspense) {
throw new Error('useOperationSetSearch must be used with suspense')
}
if (disabled) {
throw new Error('useOperationSetSearch cannot be disabled')
}

let id: number | undefined

if (keyword) {
const shortCodeContent = parseShortCode(keyword)

if (shortCodeContent) {
id = shortCodeContent.id
}
}

const { data: operationSet } = useOperationSet({ id, suspense })

const listResponse = useOperationSets({
keyword,
suspense,
...params,

// disable the list query if we are fetching a single operation set
disabled: !!id,
})

if (id) {
return {
operationSets: [operationSet],
isReachingEnd: true,
setSize: noop,

// these are fixed values in suspense mode
error: undefined,
isValidating: false,
}
}

return listResponse
}

interface UseOperationSetParams {
Expand Down
16 changes: 11 additions & 5 deletions src/apis/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useSWRInfinite from 'swr/infinite'

import { toCopilotOperation } from 'models/converter'
import { OpRatingType, Operation } from 'models/operation'
import { parseShortCode } from 'models/shortCode'
import { ShortCodeContent, parseShortCode } from 'models/shortCode'
import { OperationApi } from 'utils/maa-copilot-client'
import { useSWRRefresh } from 'utils/swr'

Expand Down Expand Up @@ -48,15 +48,21 @@ export function useOperations({
return null // reached the end
}

// 用户输入 maa://xxxxxx 时,只传这个 id,其他参数都不传
// 用户输入神秘代码时,只传这个 id,其他参数都不传
if (keyword) {
const id = parseShortCode(keyword)
let content: ShortCodeContent | null = null

if (id) {
try {
content = parseShortCode(keyword)
} catch (e) {
console.warn(e)
}

if (content) {
return [
'operations',
{
copilotIds: [id],
copilotIds: [content.id],
} satisfies QueriesCopilotRequest,
]
}
Expand Down
12 changes: 10 additions & 2 deletions src/components/AccountManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@blueprintjs/core'
import { Popover2 } from '@blueprintjs/popover2'

import { useAtom, useSetAtom } from 'jotai'
import { useAtom } from 'jotai'
import { ComponentType, FC, useState } from 'react'

import { LoginPanel } from 'components/account/LoginPanel'
Expand All @@ -30,7 +30,7 @@ import { EditDialog } from './account/EditDialog'
import { RegisterPanel } from './account/RegisterPanel'

const AccountMenu: FC = () => {
const setAuthState = useSetAtom(authAtom)
const [authState, setAuthState] = useAtom(authAtom)
const [logoutDialogOpen, setLogoutDialogOpen] = useState(false)
const [editDialogOpen, setEditDialogOpen] = useState(false)

Expand Down Expand Up @@ -64,6 +64,14 @@ const AccountMenu: FC = () => {
/>

<Menu>
{!authState.activated && (
<MenuItem
disabled
icon="warning-sign"
text="账号未激活,请在退出登录后,以重置密码的方式激活"
/>
)}

<MenuItem
shouldDismissPopover={false}
icon="edit"
Expand Down
4 changes: 2 additions & 2 deletions src/components/ActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ const InlineCondition: FCC<{
title?: string
}> = ({ title, children }) => (
<div className="min-w-[5em] text-lg leading-none">
<span className="text-zinc-500 mr-0.5 tabular-nums font-bold">
<span className="text-zinc-500 dark:text-slate-100 mr-0.5 tabular-nums font-bold">
{children}
</span>
<span className="text-zinc-400 text-xs">{title}</span>
<span className="text-zinc-400 dark:text-slate-200 text-xs">{title}</span>
</div>
)
4 changes: 2 additions & 2 deletions src/components/FactItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const FactItem: FCC<{
className,
)}
>
{icon && <Icon icon={icon} className="mr-2 text-zinc-500" />}
<div className="text-sm mr-2 text-zinc-500">{title}</div>
{icon && <Icon icon={icon} className="mr-2 text-zinc-500 dark:text-slate-100" />}
<div className="text-sm mr-2 text-zinc-500 dark:text-slate-100">{title}</div>
{children}
</div>
)
2 changes: 1 addition & 1 deletion src/components/HelperText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const HelperText: FCC<{
}

return (
<div className={clsx('flex text-gray-600 text-xs items-center', className)}>
<div className={clsx('flex text-gray-600 dark:text-zinc-400 text-xs items-center', className)}>
<Icon icon="info-sign" size={12} className="mr-1.5" />
<div>{child()}</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/components/OperationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button, Card, Elevation, H4, H5, Icon, Tag } from '@blueprintjs/core'
import { Tooltip2 } from '@blueprintjs/popover2'

import clsx from 'clsx'
import { handleCopyShortCode, handleDownloadJSON } from 'services/operation'
import { copyShortCode, handleDownloadJSON } from 'services/operation'

import { ReLink } from 'components/ReLink'
import { RelativeTime } from 'components/RelativeTime'
Expand Down Expand Up @@ -61,7 +61,7 @@ export const NeoOperationCard = ({ operation }: { operation: Operation }) => {
/>
</div>
<div>
<div className="text-sm text-zinc-600 mb-2 font-bold">
<div className="text-sm text-zinc-600 dark:text-slate-100 mb-2 font-bold">
干员/干员组
</div>
<OperatorTags operation={operation} />
Expand Down Expand Up @@ -187,7 +187,7 @@ export const OperationCard = ({ operation }: { operation: Operation }) => {
/>
</div>
<div className="md:w-1/2">
<div className="text-sm text-zinc-600 mb-2 font-bold">
<div className="text-sm text-zinc-600 dark:text-slate-100 mb-2 font-bold">
干员/干员组
</div>
<OperatorTags operation={operation} />
Expand Down Expand Up @@ -263,7 +263,7 @@ const CardActions = ({
<Button
small
icon="clipboard"
onClick={() => handleCopyShortCode(operation)}
onClick={() => copyShortCode(operation)}
/>
</Tooltip2>
<Tooltip2
Expand Down
4 changes: 2 additions & 2 deletions src/components/OperationSetCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Card, Elevation, H4, Icon, Tag } from '@blueprintjs/core'
import { Tooltip2 } from '@blueprintjs/popover2'

import { handleCopyShortCode } from 'services/operation'
import { copyShortCode } from 'services/operation'

import { ReLink } from 'components/ReLink'
import { RelativeTime } from 'components/RelativeTime'
Expand Down Expand Up @@ -163,7 +163,7 @@ const CardActions = ({
icon="clipboard"
onClick={(e) => {
e.stopPropagation()
handleCopyShortCode(operationSet)
copyShortCode(operationSet)
}}
/>
</Tooltip2>
Expand Down
7 changes: 5 additions & 2 deletions src/components/OperationSetList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Button, NonIdealState } from '@blueprintjs/core'

import { UseOperationSetsParams, useOperationSets } from 'apis/operation-set'
import {
UseOperationSetsParams,
useOperationSetSearch,
} from 'apis/operation-set'
import { useAtomValue } from 'jotai'
import { ComponentType, ReactNode } from 'react'

Expand All @@ -15,7 +18,7 @@ export const OperationSetList: ComponentType<UseOperationSetsParams> =
const neoLayout = useAtomValue(neoLayoutAtom)

const { operationSets, setSize, isValidating, isReachingEnd } =
useOperationSets({ ...props, suspense: true })
useOperationSetSearch({ ...props, suspense: true })

// make TS happy: we got Suspense out there
if (!operationSets) throw new Error('unreachable')
Expand Down
32 changes: 21 additions & 11 deletions src/components/Operations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@ import {
} from '@blueprintjs/core'

import { UseOperationsParams } from 'apis/operation'
import { useAtom } from 'jotai'
import { useAtom, useAtomValue } from 'jotai'
import { debounce } from 'lodash-es'
import { ComponentType, useMemo, useState } from 'react'

import { CardTitle } from 'components/CardTitle'
import { OperationList } from 'components/OperationList'
import { OperationSetList } from 'components/OperationSetList'
import { neoLayoutAtom } from 'store/pref'
import {
selectedOperatorQueryAtom,
selectedOperatorsAtom,
} from 'store/selectedOperators'

import { authAtom } from '../store/auth'
import { OperatorSelect } from './OperatorSelect'
import { withSuspensable } from './Suspensable'

export const Operations: ComponentType = withSuspensable(() => {
const [queryParams, setQueryParams] = useState<UseOperationsParams>({
const [queryParams, setQueryParams] = useState<
Omit<UseOperationsParams, 'operator'>
>({
orderBy: 'hot',
})
const [selectedOperators, setSelectedOperators] = useAtom(
selectedOperatorsAtom,
)
const selectedOperatorQuery = useAtomValue(selectedOperatorQueryAtom)
const debouncedSetQueryParams = useMemo(
() => debounce(setQueryParams, 500),
[],
Expand Down Expand Up @@ -95,7 +105,7 @@ export const Operations: ComponentType = withSuspensable(() => {
<div className="flex mr-4">
<FormGroup
helperText={
queryParams.operator?.length
selectedOperators.length
? '点击干员标签以标记为排除该干员'
: undefined
}
Expand All @@ -109,6 +119,7 @@ export const Operations: ComponentType = withSuspensable(() => {
large
type="search"
enterKeyHint="search"
defaultValue={queryParams.keyword}
onChange={(e) =>
debouncedSetQueryParams((old) => ({
...old,
Expand All @@ -135,13 +146,8 @@ export const Operations: ComponentType = withSuspensable(() => {
/>
<OperatorSelect
className="mt-2"
operators={queryParams.operator?.split(',') || []}
onChange={(operators) =>
setQueryParams((old) => ({
...old,
operator: operators.join(','),
}))
}
operators={selectedOperatorQuery.split(',')}
onChange={setSelectedOperators}
/>
</FormGroup>
</div>
Expand Down Expand Up @@ -194,6 +200,7 @@ export const Operations: ComponentType = withSuspensable(() => {
large
type="search"
enterKeyHint="search"
defaultValue={queryParams.keyword}
onChange={(e) =>
debouncedSetQueryParams((old) => ({
...old,
Expand All @@ -210,9 +217,12 @@ export const Operations: ComponentType = withSuspensable(() => {
</Card>

<div className="tabular-nums">
{listMode === 'operation' && <OperationList {...queryParams} />}
{listMode === 'operation' && (
<OperationList {...queryParams} operator={selectedOperatorQuery} />
)}
{listMode === 'operationSet' && <OperationSetList {...queryParams} />}
</div>
</>
)
})
Operations.displayName = 'Operations'
5 changes: 3 additions & 2 deletions src/components/OperatorSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface OperatorSelectProps {
onChange: (operators: string[]) => void
}

type OperatorInfo = typeof OPERATORS[number]
type OperatorInfo = (typeof OPERATORS)[number]

interface OperatorEntry {
name: string
Expand Down Expand Up @@ -122,11 +122,12 @@ export const OperatorSelect: FC<OperatorSelectProps> = ({
leftIcon: 'person',
className: '!flex !p-0 !pl-[5px]',
large: true,
tagProps(value, index) {
tagProps(_value, index) {
const operator = operators[index]

return {
interactive: true,
className: operator.exclude ? 'line-through' : undefined,
intent: operator?.exclude ? 'danger' : 'primary',
onClick: () => setExclude(index, !operator?.exclude),
}
Expand Down
Loading

0 comments on commit 7743c79

Please sign in to comment.