feat(reaction): 前端表情常量、类型与 API

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-06 03:19:39 -06:00
parent 8a46bae27d
commit d16e3dddb8
4 changed files with 67 additions and 1 deletions

View File

@@ -297,6 +297,17 @@ export function deleteComment(id: number) {
return http.delete("admin/comment", { params: { id } }) 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() { export async function getTutorialList() {
const res = await http.get<Tutorial[]>("admin/tutorial") const res = await http.get<Tutorial[]>("admin/tutorial")
return res.data return res.data

View File

@@ -3,6 +3,7 @@ import { filterResult } from "oj/transforms"
import type { import type {
Exercise, Exercise,
Problem, Problem,
ReactionKey,
Submission, Submission,
SubmissionListPayload, SubmissionListPayload,
SubmitCodePayload, SubmitCodePayload,
@@ -241,6 +242,14 @@ export function getCommentStatistics(problemID: number) {
return http.get("comment/statistics", { params: { problem_id: problemID } }) 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有问题 // TODO: 这个API有问题
export function refreshUserProblemDisplayIds() { export function refreshUserProblemDisplayIds() {
return http.get("profile/fresh_display_id") return http.get("profile/fresh_display_id")

View File

@@ -1,4 +1,4 @@
import type { AchievementRarity, SUBMISSION_RESULT } from "./types" import type { AchievementRarity, SUBMISSION_RESULT, ReactionKey } from "./types"
export enum SubmissionStatus { export enum SubmissionStatus {
compile_error = -2, compile_error = -2,
@@ -346,3 +346,27 @@ export const USERNAME_CLASS_RE = new RegExp(
/** 班级号作为数字时的上下界,给 n-input-number 用 */ /** 班级号作为数字时的上下界,给 n-input-number 用 */
export const CLASS_NAME_MIN_VALUE = 10 ** (CLASS_NAME_MIN_DIGITS - 1) 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 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

View File

@@ -606,6 +606,28 @@ export interface Comment {
user: SampleUser user: SampleUser
} }
export type ReactionKey =
| "too_easy"
| "too_hard"
| "confusing"
| "buggy"
| "learned"
| "interesting"
| "want_explain"
export type ReactionCounts = Record<ReactionKey, number>
export interface ReactionState {
mine: ReactionKey[]
counts: ReactionCounts | null
}
export interface ReactionStatsRow extends ReactionCounts {
pid: string
title: string
users: number
}
export interface Tutorial { export interface Tutorial {
id: number id: number
title: string title: string