Skip to content

Commit

Permalink
fix: birthday and tags commit bug
Browse files Browse the repository at this point in the history
  • Loading branch information
BIYUEHU committed Jun 16, 2024
1 parent 16465d1 commit d65a65d
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 179 deletions.
1 change: 1 addition & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@moehub/common": "workspace:^",
"antd": "^5.18.1",
"axios": "^1.7.2",
"dayjs": "^1.11.11",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.23.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/http/character.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MoehubApiBase, MoehubApiCharacter, MoehubApiCharacters, MoehubDataCharacter } from '@moehub/common';
import { MoehubApiBase, MoehubApiCharacter, MoehubApiCharacters, MoehubDataCharacterSubmit } from '@moehub/common';
import http from './http';

export function getCharacter(id: number): Promise<MoehubApiCharacter> {
Expand All @@ -9,11 +9,11 @@ export function getCharacters(): Promise<MoehubApiCharacters> {
return http.get('/character');
}

export function createCharacter(character: MoehubDataCharacter): Promise<MoehubApiBase<201>> {
export function createCharacter(character: MoehubDataCharacterSubmit): Promise<MoehubApiBase<201>> {
return http.post('/character', character);
}

export function updateCharacter(id: number, character: MoehubDataCharacter): Promise<MoehubApiBase<204>> {
export function updateCharacter(id: number, character: MoehubDataCharacterSubmit): Promise<MoehubApiBase<204>> {
return http.put(`/character/${id}`, character);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/http/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
url: 'http://localhost:5000/api'
url: 'https://m.hotaru.icu/api'
};
1 change: 1 addition & 0 deletions packages/client/src/http/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './http';
export * from './character';
export * from './other';
10 changes: 10 additions & 0 deletions packages/client/src/http/other.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { MoehubApiSeries, MoehubApiTags } from '@moehub/common';
import http from './http';

export function getTags(): Promise<MoehubApiTags> {
return http.get('/tag');
}

export function getSeries(): Promise<MoehubApiSeries> {
return http.get('/series');
}
128 changes: 41 additions & 87 deletions packages/client/src/views/Admin/Create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
import React from 'react';
import { Button, Card, Collapse, DatePicker, Flex, Form, Input, InputNumber, Radio, Space, notification } from 'antd';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import React, { useEffect, useState } from 'react';
import {
Button,
Card,
Collapse,
DatePicker,
Flex,
Form,
Input,
InputNumber,
Radio,
Select,
SelectProps,
Space,
notification
} from 'antd';
import { MoehubDataCharacter } from '@moehub/common';
import dayjs from 'dayjs';
import styles from '../styles.module.css';
import { createCharacter } from '../../../http';
import { createCharacter, getTags } from '../../../http';

const CreateView: React.FC = () => {
const [form] = Form.useForm();

const onFinish = (values: MoehubDataCharacter) => {
createCharacter(values).then(() => notification.success({ message: '角色创建成功' }));
const onFinish = (values: Omit<MoehubDataCharacter, 'birthday'> & { birthday: dayjs.Dayjs }) => {
const data = { ...values, birthday: values.birthday ? new Date(values.birthday.toString()).getTime() : undefined };
createCharacter(data).then(() => notification.success({ message: '角色创建成功' }));
};

const [tagOptions, setTagOptions] = useState<SelectProps['options']>([]);

useEffect(() => {
getTags().then(({ data }) => {
setTagOptions(data.map((tag) => ({ label: tag.name, value: tag.name })));
});
}, []);

return (
<div>
<h1>角色创建</h1>
Expand Down Expand Up @@ -45,46 +68,12 @@ const CreateView: React.FC = () => {
</Radio.Group>
</Form.Item>
<hr />
<Form.List name="alias">
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field) => (
<>
<Form.Item {...field} rules={[{ required: true }]}>
<Input />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</>
))}
<Form.Item>
<Button type="dashed" onClick={() => add()} icon={<PlusOutlined />}>
添加别名
</Button>
<Form.ErrorList errors={errors} />
</Form.Item>
</>
)}
</Form.List>
<Form.List name="images">
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field) => (
<>
<Form.Item {...field} rules={[{ required: true }]}>
<Input />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</>
))}
<Form.Item>
<Button type="dashed" onClick={() => add()} icon={<PlusOutlined />}>
添加图片
</Button>
<Form.ErrorList errors={errors} />
</Form.Item>
</>
)}
</Form.List>
<Form.Item name="alias" label="角色别名">
<Select mode="tags"></Select>
</Form.Item>
<Form.Item name="images" label="相关图片">
<Select mode="tags"></Select>
</Form.Item>
<Form.Item name="description" label="描述">
<Input />
</Form.Item>
Expand All @@ -97,26 +86,9 @@ const CreateView: React.FC = () => {
<Form.Item name="comment" label="个人评价">
<Input />
</Form.Item>
<Form.List name="tags">
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field) => (
<>
<Form.Item {...field} rules={[{ required: true }]}>
<Input />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</>
))}
<Form.Item>
<Button type="dashed" onClick={() => add()} icon={<PlusOutlined />}>
添加萌点
</Button>
<Form.ErrorList errors={errors} />
</Form.Item>
</>
)}
</Form.List>
<Form.Item name="tags" label="萌点">
<Select mode="tags" options={tagOptions}></Select>
</Form.Item>
<hr />
<Collapse>
<Collapse.Panel header="其它信息" key="1">
Expand Down Expand Up @@ -152,27 +124,9 @@ const CreateView: React.FC = () => {
<Radio value="O">O 型</Radio>
</Radio.Group>
</Form.Item>

<Form.List name="url">
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field) => (
<>
<Form.Item {...field} rules={[{ required: true }]}>
<Input />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</>
))}
<Form.Item>
<Button type="dashed" onClick={() => add()} icon={<PlusOutlined />}>
添加链接
</Button>
<Form.ErrorList errors={errors} />
</Form.Item>
</>
)}
</Form.List>
<Form.Item name="url" label="相关链接">
<Select mode="tags"></Select>
</Form.Item>
</Collapse.Panel>
</Collapse>
<br />
Expand Down
130 changes: 43 additions & 87 deletions packages/client/src/views/Admin/Edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import React, { useEffect, useState } from 'react';
import { Button, Card, Collapse, DatePicker, Flex, Form, Input, InputNumber, Radio, Space, notification } from 'antd';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import {
Button,
Card,
Collapse,
DatePicker,
Flex,
Form,
Input,
InputNumber,
Radio,
Select,
SelectProps,
Space,
notification
} from 'antd';
import { MoehubDataCharacter } from '@moehub/common';
import { useNavigate, useParams } from 'react-router-dom';
import dayjs from 'dayjs';
import styles from '../styles.module.css';
import { getCharacter, updateCharacter } from '../../../http';
import { getCharacter, getTags, updateCharacter } from '../../../http';
import Loading from '../../../components/loading';

const EditView: React.FC = () => {
Expand All @@ -20,14 +34,25 @@ const EditView: React.FC = () => {

const [form] = Form.useForm();

const onFinish = (values: MoehubDataCharacter) => {
updateCharacter(Number(characterId), values).then(() => notification.success({ message: '角色编辑成功' }));
const onFinish = (values: Omit<MoehubDataCharacter, 'birthday'> & { birthday: dayjs.Dayjs }) => {
const data = { ...values, birthday: values.birthday ? new Date(values.birthday.toString()).getTime() : undefined };
updateCharacter(Number(characterId), data).then(() => notification.success({ message: '角色编辑成功' }));
};

const [tagOptions, setTagOptions] = useState<SelectProps['options']>([]);

useEffect(() => {
getCharacter(Number(characterId))
.then((res) => form.setFieldsValue(res.data))
.then((res) => {
const { data } = res;
if (data.birthday) (data.birthday as unknown as dayjs.Dayjs) = dayjs(data.birthday);
form.setFieldsValue(data);
})
.finally(() => setIsLoading(false));

getTags().then(({ data }) => {
setTagOptions(data.map((tag) => ({ label: tag.name, value: tag.name })));
});
}, []);

return (
Expand Down Expand Up @@ -66,46 +91,12 @@ const EditView: React.FC = () => {
</Radio.Group>
</Form.Item>
<hr />
<Form.List name="alias">
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field) => (
<>
<Form.Item {...field} rules={[{ required: true }]}>
<Input />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</>
))}
<Form.Item>
<Button type="dashed" onClick={() => add()} icon={<PlusOutlined />}>
添加别名
</Button>
<Form.ErrorList errors={errors} />
</Form.Item>
</>
)}
</Form.List>
<Form.List name="images">
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field) => (
<>
<Form.Item {...field} rules={[{ required: true }]}>
<Input />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</>
))}
<Form.Item>
<Button type="dashed" onClick={() => add()} icon={<PlusOutlined />}>
添加图片
</Button>
<Form.ErrorList errors={errors} />
</Form.Item>
</>
)}
</Form.List>
<Form.Item name="alias" label="角色别名">
<Select mode="tags"></Select>
</Form.Item>
<Form.Item name="images" label="相关图片">
<Select mode="tags"></Select>
</Form.Item>
<Form.Item name="description" label="描述">
<Input />
</Form.Item>
Expand All @@ -118,26 +109,9 @@ const EditView: React.FC = () => {
<Form.Item name="comment" label="个人评价">
<Input />
</Form.Item>
<Form.List name="tags">
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field) => (
<>
<Form.Item {...field} rules={[{ required: true }]}>
<Input />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</>
))}
<Form.Item>
<Button type="dashed" onClick={() => add()} icon={<PlusOutlined />}>
添加萌点
</Button>
<Form.ErrorList errors={errors} />
</Form.Item>
</>
)}
</Form.List>
<Form.Item name="tags" label="萌点">
<Select mode="tags" options={tagOptions}></Select>
</Form.Item>
<hr />
<Collapse>
<Collapse.Panel header="其它信息" key="1">
Expand Down Expand Up @@ -173,27 +147,9 @@ const EditView: React.FC = () => {
<Radio value="O">O 型</Radio>
</Radio.Group>
</Form.Item>

<Form.List name="url">
{(fields, { add, remove }, { errors }) => (
<>
{fields.map((field) => (
<>
<Form.Item {...field} rules={[{ required: true }]}>
<Input />
</Form.Item>
<MinusCircleOutlined onClick={() => remove(field.name)} />
</>
))}
<Form.Item>
<Button type="dashed" onClick={() => add()} icon={<PlusOutlined />}>
添加链接
</Button>
<Form.ErrorList errors={errors} />
</Form.Item>
</>
)}
</Form.List>
<Form.Item name="url" label="相关链接">
<Select mode="tags"></Select>
</Form.Item>
</Collapse.Panel>
</Collapse>
<br />
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/views/Character/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const CharacterView: React.FC = () => {
<Card hoverable className={`card cardFixed`}>
{data.hitokoto ? <div className={styles.hitokoto}>{data.hitokoto}</div> : null}
{data.images && data.images.length > 1 ? (
<Carousel arrows infinite={false}>
<Carousel arrows infinite={false} autoplay>
{data.images.map((item, index) => (
<Image className={styles.content} src={item} key={index} />
))}
Expand Down
Loading

0 comments on commit d65a65d

Please sign in to comment.