145 lines
3.2 KiB
TypeScript
145 lines
3.2 KiB
TypeScript
import type { Action } from "../Action";
|
|
import type { RequestState, SearchResult } from "./state";
|
|
import type { Category, Reply, CreateRequestParams } from "../../api/models";
|
|
|
|
export const SET_LOADING = "set_loading";
|
|
export const SET_CATEGORIES = "set_categories";
|
|
export const SET_CATEGORY_ID = "set_category_id";
|
|
export const SET_KEYWORD = "set_keyword";
|
|
export const SET_PAGE_INDEX = "set_page_index";
|
|
export const SET_IS_SEARCHING = "set_is_searching";
|
|
export const SET_SEARCH_RESULT = "set_search_result";
|
|
export const SET_REPLIES = "set_replies";
|
|
export const TOGGLE_ORDER_BY_PUBLISH_TIME = "toggle_order_by_publish_time";
|
|
export const TOGGLE_ORDER_BY_CATEGORY_ID = "toggle_order_by_category_id";
|
|
export const TOGGLE_ORDER_BY_REPLY_AMOUNT = "toggle_order_by_reply_amount";
|
|
export const SET_IS_PUBLISH = "set_is_publish";
|
|
export const SET_REQUEST_PUBLISH = "set_request_publish";
|
|
|
|
export type ActionsType =
|
|
| typeof SET_LOADING
|
|
| typeof SET_CATEGORIES
|
|
| typeof SET_CATEGORY_ID
|
|
| typeof SET_KEYWORD
|
|
| typeof SET_PAGE_INDEX
|
|
| typeof SET_IS_SEARCHING
|
|
| typeof SET_SEARCH_RESULT
|
|
| typeof SET_REPLIES
|
|
| typeof TOGGLE_ORDER_BY_PUBLISH_TIME
|
|
| typeof TOGGLE_ORDER_BY_CATEGORY_ID
|
|
| typeof TOGGLE_ORDER_BY_REPLY_AMOUNT
|
|
| typeof SET_IS_PUBLISH
|
|
| typeof SET_REQUEST_PUBLISH;
|
|
|
|
export type RequestAction = Action<ActionsType, RequestState>;
|
|
|
|
export function setLoading(isLoading: boolean): RequestAction {
|
|
return {
|
|
type: "set_loading",
|
|
payload: {
|
|
isLoading,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function setCategories(categories: Array<Category>): RequestAction {
|
|
return {
|
|
type: "set_categories",
|
|
payload: {
|
|
categories,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function setCategoryId(categoryId: number): RequestAction {
|
|
return {
|
|
type: "set_category_id",
|
|
payload: {
|
|
categoryId,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function setKeyword(keyword: string): RequestAction {
|
|
return {
|
|
type: "set_keyword",
|
|
payload: {
|
|
keyword,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function setPageIndex(pageIndex: number): RequestAction {
|
|
return {
|
|
type: "set_page_index",
|
|
payload: {
|
|
pageIndex,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function setIsSearch(isSearching: boolean): RequestAction {
|
|
return {
|
|
type: "set_is_searching",
|
|
payload: {
|
|
isSearching,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function setSearchResult(result: SearchResult): RequestAction {
|
|
return {
|
|
type: "set_search_result",
|
|
payload: {
|
|
...result,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function setReplies(replies: Array<Reply> | null): RequestAction {
|
|
return {
|
|
type: "set_replies",
|
|
payload: {
|
|
replies,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function toggleOrderByPublishTime(): RequestAction {
|
|
return {
|
|
type: "toggle_order_by_publish_time",
|
|
};
|
|
}
|
|
|
|
export function toggleOrderByCategoryId(): RequestAction {
|
|
return {
|
|
type: "toggle_order_by_category_id",
|
|
};
|
|
}
|
|
|
|
export function toggleOrderByReplyAmount(): RequestAction {
|
|
return {
|
|
type: "toggle_order_by_reply_amount",
|
|
};
|
|
}
|
|
|
|
export function setIsPublish(isPublish: boolean): RequestAction {
|
|
return {
|
|
type: "set_is_publish",
|
|
payload: {
|
|
isPublish,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function setRequestPublish(
|
|
requestPublish: Partial<CreateRequestParams>,
|
|
): RequestAction {
|
|
return {
|
|
type: "set_request_publish",
|
|
payload: {
|
|
requestPublish,
|
|
},
|
|
};
|
|
}
|