{
+ onClick?.(event)
+ if (!event.defaultPrevented) {
+ handleClick(event)
+ }
+ }}
+ onKeyUp={noop}
+ {...props}
+ />
+ )
+}
diff --git a/src/components/Suggest.tsx b/src/components/Suggest.tsx
index fce98a3c..17cd9d5b 100644
--- a/src/components/Suggest.tsx
+++ b/src/components/Suggest.tsx
@@ -1,26 +1,38 @@
import { Suggest2, Suggest2Props } from '@blueprintjs/select'
-import { useEffect, useMemo, useState } from 'react'
+import { noop } from 'lodash-es'
+import { useEffect, useMemo, useRef, useState } from 'react'
import { ControllerFieldState } from 'react-hook-form'
import { FieldResetButton } from './FieldResetButton'
interface SuggestProps
extends Suggest2Props {
debounce?: number // defaults to 100(ms), set to 0 to disable
+ updateQueryOnSelect?: boolean
fieldState?: ControllerFieldState
onReset?: () => void
}
export const Suggest = ({
debounce = 100,
+ updateQueryOnSelect,
fieldState,
onReset,
items,
itemListPredicate,
+ selectedItem,
+ inputValueRenderer,
inputProps,
...suggest2Props
}: SuggestProps) => {
+ // 禁用掉 focus 自动选中输入框文字的功能
+ // https://github.com/palantir/blueprint/blob/b41f668461e63e2c20caf54a3248181fe01161c4/packages/select/src/components/suggest/suggest2.tsx#L229
+ const ref = useRef>(null)
+ if (ref.current && ref.current['selectText'] !== noop) {
+ ref.current['selectText'] = noop
+ }
+
const [query, setQuery] = useState('')
const [debouncedQuery, setDebouncedQuery] = useState('')
@@ -46,11 +58,20 @@ export const Suggest = ({
}
}, [fieldState?.isTouched])
+ useEffect(() => {
+ if (updateQueryOnSelect && selectedItem) {
+ setQuery(inputValueRenderer(selectedItem))
+ }
+ }, [updateQueryOnSelect, selectedItem, inputValueRenderer])
+
return (
+ ref={ref}
items={filteredItems}
query={query}
onQueryChange={setQuery}
+ selectedItem={selectedItem}
+ inputValueRenderer={inputValueRenderer}
inputProps={{
onKeyDown: (event) => {
// prevent form submission
@@ -60,7 +81,13 @@ export const Suggest = ({
},
rightElement: (
{
setQuery('')
setDebouncedQuery('')
diff --git a/src/components/Suspensable.tsx b/src/components/Suspensable.tsx
index 420d79c9..1cf84ed1 100644
--- a/src/components/Suspensable.tsx
+++ b/src/components/Suspensable.tsx
@@ -11,6 +11,7 @@ interface SuspensableProps {
pendingTitle?: string
fetcher?: () => void
+ errorFallback?: (params: { error: Error }) => JSX.Element | undefined
}
export const Suspensable: FCC = ({
@@ -18,6 +19,7 @@ export const Suspensable: FCC = ({
retryDeps = [],
pendingTitle = '加载中',
fetcher,
+ errorFallback,
}) => {
const resetError = useRef<() => void>()
@@ -30,13 +32,18 @@ export const Suspensable: FCC = ({
return (
{
+ const fallback = errorFallback?.({ error })
+ if (fallback !== undefined) {
+ return fallback
+ }
+
resetError.current = _resetError
return (
= ({
+ className,
+ userId,
+ children,
+}) => {
+ return (
+
+ {children}
+
+ )
+}
diff --git a/src/components/drawer/OperationDrawer.tsx b/src/components/drawer/OperationDrawer.tsx
index a5a06119..0d660b2f 100644
--- a/src/components/drawer/OperationDrawer.tsx
+++ b/src/components/drawer/OperationDrawer.tsx
@@ -1,5 +1,6 @@
import { Drawer, DrawerSize } from '@blueprintjs/core'
+import { SyntheticEvent } from 'react'
import { useSearchParams } from 'react-router-dom'
import { OperationSetViewer } from 'components/viewer/OperationSetViewer'
@@ -10,14 +11,24 @@ export function OperationDrawer() {
const operationId = +(searchParams.get('op') || NaN) || undefined
const operationSetId = +(searchParams.get('opset') || NaN) || undefined
- const closeOperation = () => {
+ const closeOperation = (e?: SyntheticEvent) => {
+ // 如果是通过鼠标点击外面来触发的关闭,那么只在左键点击时关闭,避免用后退键点击时关闭后又立即打开的问题
+ // (原因是后退键会先触发关闭,然后触发浏览器的后退操作,使页面回到上一个 URL,导致又触发打开)
+ if (e?.nativeEvent instanceof MouseEvent && e.nativeEvent.button !== 0) {
+ return
+ }
+
setSearchParams((params) => {
params.delete('op')
return params
})
}
- const closeOperationSet = () => {
+ const closeOperationSet = (e?: SyntheticEvent) => {
+ if (e?.nativeEvent instanceof MouseEvent && e.nativeEvent.button !== 0) {
+ return
+ }
+
setSearchParams((params) => {
params.delete('opset')
return params
diff --git a/src/components/editor/operator/EditorOperator.tsx b/src/components/editor/operator/EditorOperator.tsx
index 3fde316e..ba2116a4 100644
--- a/src/components/editor/operator/EditorOperator.tsx
+++ b/src/components/editor/operator/EditorOperator.tsx
@@ -26,6 +26,8 @@ const createArbitraryOperator = (name: string): OperatorInfo => ({
alias: '',
alt_name: '',
subProf: '',
+ prof: '',
+ rarity: 0,
})
export const EditorOperatorName = ({
@@ -134,11 +136,13 @@ export const EditorOperatorName = ({
export const OperatorAvatar = ({
id,
name,
+ rarity = 0,
size,
className,
}: {
id?: string
name?: string
+ rarity?: number
size?: 'small' | 'medium' | 'large'
className?: string
}) => {
@@ -154,17 +158,33 @@ export const OperatorAvatar = ({
})()
const sizingClassName =
+ size &&
{
small: 'h-5 w-5',
medium: 'h-6 w-6',
large: 'h-8 w-8',
- }[size || 'medium'] || 'h-6 w-6'
+ }[size]
- const commonClassName = 'rounded-md object-cover bp4-elevation-1 bg-slate-100'
+ const colorClassName =
+ rarity === 6
+ ? ['bg-orange-200', 'ring-orange-300']
+ : rarity === 5
+ ? ['bg-yellow-100', 'ring-yellow-200']
+ : rarity === 4
+ ? ['bg-purple-100', 'ring-purple-200']
+ : ['bg-slate-100', 'ring-slate-200']
+
+ const commonClassName =
+ 'ring-inset ring-2 border-solid rounded-md object-cover'
return foundId ? (
,
)
- const error = submitError || listError
+ const error =
+ submitError || listError || (!auth.userId ? '未登录' : undefined)
const operationSetList = onlyShowAdded
? operationSets?.filter(
diff --git a/src/components/viewer/OperationSetViewer.tsx b/src/components/viewer/OperationSetViewer.tsx
index 2c48c960..57d5b025 100644
--- a/src/components/viewer/OperationSetViewer.tsx
+++ b/src/components/viewer/OperationSetViewer.tsx
@@ -34,6 +34,7 @@ import { authAtom } from 'store/auth'
import { wrapErrorMessage } from 'utils/wrapErrorMessage'
import { formatError } from '../../utils/error'
+import { UserName } from '../UserName'
const ManageMenu: FC<{
operationSet: OperationSet
@@ -225,9 +226,12 @@ function OperationSetViewerInner({
-
+
{operationSet.creator}
-
+