Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: services types optimize

shuai734537773ee7
diff --git a/ui/src/pages/QuestionDetail/components/Answer/index.tsx b/ui/src/pages/QuestionDetail/components/Answer/index.tsx
index dff94850..5d59c8ca 100644
--- a/ui/src/pages/QuestionDetail/components/Answer/index.tsx
+++ b/ui/src/pages/QuestionDetail/components/Answer/index.tsx
@@ -13,10 +13,10 @@ import {
import { acceptanceAnswer } from '@answer/api';
import { scrollTop } from '@answer/utils';
-import { AnswerContent } from '@/services/types';
+import { AnswerItem } from '@/services/types';
interface Props {
- data: AnswerContent;
+ data: AnswerItem;
/** router answer id */
aid?: string;
/** is author */
diff --git a/ui/src/pages/QuestionDetail/index.tsx b/ui/src/pages/QuestionDetail/index.tsx
index 62039d0c..a33962e7 100644
--- a/ui/src/pages/QuestionDetail/index.tsx
+++ b/ui/src/pages/QuestionDetail/index.tsx
@@ -5,9 +5,9 @@ import { useParams, useSearchParams } from 'react-router-dom';
import { questionDetail, getAnswers } from '@answer/api';
import { Pagination, PageTitle } from '@answer/components';
import type {
- AnswerRes,
+ ListResult,
QuDetailRes,
- AnswerContent,
+ AnswerItem,
} from '@answer/services/types';
import { userInfoStore } from '@answer/stores';
import { scrollTop } from '@answer/utils';
@@ -31,7 +31,7 @@ const Index = () => {
const page = Number(urlSearch.get('page') || 0);
const order = urlSearch.get('order') || '';
const [question, setQuestion] = useState<QuDetailRes | null>(null);
- const [answers, setAnswers] = useState<AnswerRes>({
+ const [answers, setAnswers] = useState<ListResult<AnswerItem>>({
count: -1,
list: [],
});
@@ -82,7 +82,7 @@ const Index = () => {
requestAnswers();
};
- const writeAnswerCallback = (obj: AnswerContent) => {
+ const writeAnswerCallback = (obj: AnswerItem) => {
setAnswers({
count: answers.count + 1,
list: [...answers.list, obj],
diff --git a/ui/src/services/client/notification.ts b/ui/src/services/client/notification.ts
index 8f40cddb..64aa40e3 100644
--- a/ui/src/services/client/notification.ts
+++ b/ui/src/services/client/notification.ts
@@ -10,7 +10,7 @@ export const useQueryNotifications = (params) => {
skipNulls: true,
})}`;
- const { data, error, mutate } = useSWR<Type.RecordResult>(
+ const { data, error, mutate } = useSWR<Type.ListResult>(
apiUrl,
request.instance.get,
);
diff --git a/ui/src/services/common.ts b/ui/src/services/common.ts
index 36884d36..913a8fab 100644
--- a/ui/src/services/common.ts
+++ b/ui/src/services/common.ts
@@ -19,7 +19,7 @@ export const useQueryQuestionByTitle = (title) => {
};
export const useQueryTags = (params) => {
- return useSWR<Type.RecordResult>(
+ return useSWR<Type.ListResult>(
`/answer/api/v1/tags/page?${qs.stringify(params, {
skipNulls: true,
})}`,
@@ -39,7 +39,7 @@ export const useQueryComments = (params) => {
params.query_cond = 'vote';
params.page = 1;
}
- return useSWR<Type.RecordResult>(
+ return useSWR<Type.ListResult>(
`/answer/api/v1/comment/page?${qs.stringify(params, {
skipNulls: true,
})}`,
@@ -172,7 +172,7 @@ export const languages = () => {
export const getAnswers = (params: Type.AnswersReq) => {
const apiUrl = `/answer/api/v1/answer/page?${qs.stringify(params)}`;
- return request.get<Type.AnswerRes>(apiUrl);
+ return request.get<Type.ListResult<Type.AnswerItem>>(apiUrl);
};
export const postAnswer = (params: Type.PostAnswerReq) => {
diff --git a/ui/src/services/types.ts b/ui/src/services/types.ts
index 546368b0..642c3326 100644
--- a/ui/src/services/types.ts
+++ b/ui/src/services/types.ts
@@ -1,3 +1,8 @@
+export interface Paging {
+ page: number;
+ page_size?: number;
+}
+
export type ReportType = 'question' | 'answer' | 'comment' | 'user';
export type ReportAction = 'close' | 'flag' | 'review';
export interface ReportParams {
@@ -10,18 +15,19 @@ export interface TagBase {
slug_name: string;
}
-export interface SynonymsTag {
- display_name: string;
- slug_name: string;
- tag_id: string;
- tag?: string;
+export interface Tag extends TagBase {
+ main_tag_slug_name?: string;
original_text?: string;
parsed_text?: string;
}
-export interface TagInfo {
+
+export interface SynonymsTag extends Tag {
+ tag_id: string;
+ tag?: string;
+}
+
+export interface TagInfo extends TagBase {
tag_id: string;
- slug_name: string;
- display_name: string;
original_text: string;
parsed_text: string;
follow_count: number;
@@ -40,27 +46,9 @@ export interface QuestionParams {
tags: Tag[];
}
-export interface Tag {
- display_name?: string;
- slug_name: string;
- main_tag_slug_name?: string;
- original_text?: string;
- parsed_text?: string;
-}
-
-export interface Paging {
- page: number;
- page_size: number;
-}
-
-export interface RecordResult extends Paging {
- list: any[];
- count: number;
-}
-
-export interface ListResult {
+export interface ListResult<T = any> {
count: number;
- list: any[];
+ list: T[];
}
export interface AnswerParams {
@@ -87,6 +75,7 @@ export interface ModifyPassReq {
pass: string;
}
+/** User */
export interface ModifyUserReq {
display_name: string;
username?: string;
@@ -98,33 +87,28 @@ export interface ModifyUserReq {
}
export interface UserInfoBase {
+ avatar: string;
username: string;
- rank: number;
display_name: string;
- avatar: string;
+ rank: number;
website: string;
location: string;
ip_info?: string;
+ /** 'forbidden' | 'normal' | 'delete'
+ */
+ status?: string;
+ /** roles */
+ is_admin?: true;
}
-export interface UserInfoRes {
- /** input name */
- avatar: string;
- id: number;
- username: string;
- rank: number;
+export interface UserInfoRes extends UserInfoBase {
bio: string;
bio_html: string;
- location: string;
- website: string;
create_time?: string;
- display_name?: string;
/** value = 1 active; value = 2 inactivated
*/
mail_status: number;
e_mail?: string;
- /** roles */
- is_admin?: true;
[prop: string]: any;
}
@@ -170,7 +154,7 @@ export interface QuDetailRes {
last_answer_id: string;
create_time: string;
update_time: string;
- user_info: User;
+ user_info: UserInfoBase;
answered: boolean;
collected: boolean;
@@ -182,36 +166,18 @@ export interface AnswersReq extends Paging {
question_id: string;
}
-export interface User {
- username: string;
- rank: string;
- display_name: string;
- avatar: string;
- website: string;
- location: string;
-
- [prop: string]: any;
-}
-
-export interface AnswerContent {
+export interface AnswerItem {
id: string;
question_id: string;
content: string;
html: string;
create_time: string;
update_time: string;
- user_info: User;
+ user_info: UserInfoBase;
[prop: string]: any;
}
-export interface AnswerRes {
- count: number;
- list: AnswerContent[];
- page?: number;
- total_page?: number;
-}
-
export interface PostAnswerReq {
content: string;
html: string;
@@ -327,8 +293,6 @@ export interface SearchResItem {
tags: TagBase[];
};
}
-export interface SearchRes {
- count: number;
+export interface SearchRes extends ListResult<SearchResItem> {
extra: any;
- list: SearchResItem[];
}
diff --git a/ui/src/stores/userInfo.ts b/ui/src/stores/userInfo.ts
index cc728d11..d18e2d30 100644
--- a/ui/src/stores/userInfo.ts
+++ b/ui/src/stores/userInfo.ts
@@ -10,7 +10,6 @@ interface UserInfoStore {
}
const initUser: UserInfoRes = {
- id: 0,
username: '',
avatar: '',
rank: 0,
@@ -19,6 +18,7 @@ const initUser: UserInfoRes = {
display_name: '',
location: '',
website: '',
+ status: '',
mail_status: 0,
};