diff --git a/src/admin/api.ts b/src/admin/api.ts index 9812223..af14c12 100644 --- a/src/admin/api.ts +++ b/src/admin/api.ts @@ -297,6 +297,17 @@ export function deleteComment(id: number) { return http.delete("admin/comment", { params: { id } }) } +export function getReactionStats( + offset = 0, + limit = 10, + problem: string, + ordering: string, +) { + return http.get("admin/reaction", { + params: { offset, limit, problem, ordering }, + }) +} + export async function getTutorialList() { const res = await http.get("admin/tutorial") return res.data diff --git a/src/oj/api.ts b/src/oj/api.ts index 1ded8b3..531dbfb 100644 --- a/src/oj/api.ts +++ b/src/oj/api.ts @@ -3,6 +3,7 @@ import { filterResult } from "oj/transforms" import type { Exercise, Problem, + ReactionKey, Submission, SubmissionListPayload, SubmitCodePayload, @@ -241,6 +242,14 @@ export function getCommentStatistics(problemID: number) { return http.get("comment/statistics", { params: { problem_id: problemID } }) } +export function getReaction(problemID: number) { + return http.get("reaction", { params: { problem_id: problemID } }) +} + +export function setReaction(problemID: number, types: ReactionKey[]) { + return http.post("reaction", { problem_id: problemID, types }) +} + // TODO: 这个API有问题 export function refreshUserProblemDisplayIds() { return http.get("profile/fresh_display_id") diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 1c7ad81..e64e1fa 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,4 +1,4 @@ -import type { AchievementRarity, SUBMISSION_RESULT } from "./types" +import type { AchievementRarity, SUBMISSION_RESULT, ReactionKey } from "./types" export enum SubmissionStatus { compile_error = -2, @@ -346,3 +346,27 @@ export const USERNAME_CLASS_RE = new RegExp( /** 班级号作为数字时的上下界,给 n-input-number 用 */ export const CLASS_NAME_MIN_VALUE = 10 ** (CLASS_NAME_MIN_DIGITS - 1) export const CLASS_NAME_MAX_VALUE = 10 ** CLASS_NAME_MAX_DIGITS - 1 + +export const REACTIONS: { + key: ReactionKey + label: string + icon: string +}[] = [ + { + key: "too_easy", + label: "太简单", + icon: "fluent-emoji:smiling-face-with-sunglasses", + }, + { key: "too_hard", label: "太难了", icon: "fluent-emoji:exploding-head" }, + { + key: "confusing", + label: "没看懂", + icon: "fluent-emoji:face-with-spiral-eyes", + }, + { key: "buggy", label: "题目有错", icon: "fluent-emoji:bug" }, + { key: "learned", label: "学到了", icon: "fluent-emoji:light-bulb" }, + { key: "interesting", label: "有意思", icon: "fluent-emoji:star-struck" }, + { key: "want_explain", label: "想听讲解", icon: "fluent-emoji:books" }, +] + +export const MAX_REACTIONS = 3 diff --git a/src/utils/types.ts b/src/utils/types.ts index 571f2ec..efafcff 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -606,6 +606,28 @@ export interface Comment { user: SampleUser } +export type ReactionKey = + | "too_easy" + | "too_hard" + | "confusing" + | "buggy" + | "learned" + | "interesting" + | "want_explain" + +export type ReactionCounts = Record + +export interface ReactionState { + mine: ReactionKey[] + counts: ReactionCounts | null +} + +export interface ReactionStatsRow extends ReactionCounts { + pid: string + title: string + users: number +} + export interface Tutorial { id: number title: string