mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-07 12:23:00 +08:00
use thunk to get targetName
This commit is contained in:
parent
af002ad3e5
commit
8db0ed3fe1
@ -4,7 +4,7 @@ import {
|
|||||||
} from '@arco-design/web-react';
|
} from '@arco-design/web-react';
|
||||||
import useForm from '@arco-design/web-react/es/Form/useForm';
|
import useForm from '@arco-design/web-react/es/Form/useForm';
|
||||||
import { IconInfoCircle } from '@arco-design/web-react/icon';
|
import { IconInfoCircle } from '@arco-design/web-react/icon';
|
||||||
import { useAppSelector } from '../../app/hooks';
|
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
||||||
import { selectPlatformConf } from '../globalConf/globalConfSlice';
|
import { selectPlatformConf } from '../globalConf/globalConfSlice';
|
||||||
import { CategoryConfig, SubscribeConfig } from '../../utils/type';
|
import { CategoryConfig, SubscribeConfig } from '../../utils/type';
|
||||||
import getTargetName from '../targetName/targetNameReq';
|
import getTargetName from '../targetName/targetNameReq';
|
||||||
@ -67,6 +67,7 @@ function SubscribeModal({
|
|||||||
const platformConf = useAppSelector(selectPlatformConf);
|
const platformConf = useAppSelector(selectPlatformConf);
|
||||||
const [updateSub] = useUpdateSubMutation();
|
const [updateSub] = useUpdateSubMutation();
|
||||||
const [newSub] = useNewSubMutation();
|
const [newSub] = useNewSubMutation();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
form.validate().then((value: SubscribeConfig) => {
|
form.validate().then((value: SubscribeConfig) => {
|
||||||
@ -115,7 +116,7 @@ function SubscribeModal({
|
|||||||
setPlatformStates(platform);
|
setPlatformStates(platform);
|
||||||
form.setFieldValue('cats', []);
|
form.setFieldValue('cats', []);
|
||||||
if (!platformConf[platform].hasTarget) {
|
if (!platformConf[platform].hasTarget) {
|
||||||
getTargetName(platform, 'default').then((res) => {
|
dispatch(getTargetName(platform, 'default')).then((res) => {
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
targetName: res,
|
targetName: res,
|
||||||
target: '',
|
target: '',
|
||||||
@ -168,7 +169,7 @@ function SubscribeModal({
|
|||||||
{ required: hasTarget, message: '请输入账号' },
|
{ required: hasTarget, message: '请输入账号' },
|
||||||
{
|
{
|
||||||
validator: (value, callback) => new Promise<void>((resolve) => {
|
validator: (value, callback) => new Promise<void>((resolve) => {
|
||||||
getTargetName(form.getFieldValue('platformName'), value)
|
dispatch(getTargetName(form.getFieldValue('platformName'), value))
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
import { RootState, store } from '../../app/store';
|
import { AppThunk } from '../../app/store';
|
||||||
import { baseUrl } from '../../utils/urls';
|
import { baseUrl } from '../../utils/urls';
|
||||||
|
|
||||||
export default async function getTargetName(platformName: string, target: string) {
|
// eslint-disable-next-line
|
||||||
const url = `${baseUrl}target_name?platformName=${platformName}&target=${target}`;
|
export const getTargetName =
|
||||||
const state = store.getState() as RootState;
|
(platformName: string, target: string): AppThunk<Promise<string>> => async (_, getState) => {
|
||||||
const authToken = state.auth.token;
|
const url = `${baseUrl}target_name?platformName=${platformName}&target=${target}`;
|
||||||
const res = await fetch(url, {
|
const state = getState();
|
||||||
headers: {
|
const authToken = state.auth.token;
|
||||||
Authorization: `Bearer ${authToken}`,
|
const res = await fetch(url, {
|
||||||
},
|
headers: {
|
||||||
});
|
Authorization: `Bearer ${authToken}`,
|
||||||
const resObj = await res.json();
|
},
|
||||||
return resObj.targetName as string;
|
});
|
||||||
}
|
const resObj = await res.json();
|
||||||
|
return resObj.targetName as string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getTargetName;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user