Skip to content

Commit

Permalink
refactor: rename tag into category
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Sep 13, 2024
1 parent 81b1e13 commit 4238c5e
Show file tree
Hide file tree
Showing 47 changed files with 1,956 additions and 284 deletions.
32 changes: 16 additions & 16 deletions src/GZCTF/ClientApp/src/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,12 @@ export interface ChallengeModel {
id?: number;
/** 题目名称 */
title?: string;
/** 题目标签 */
tag?: ChallengeTag;
/** 题目类别 */
category?: ChallengeCategory;
}

/** 题目标签 */
export enum ChallengeTag {
/** 题目类别 */
export enum ChallengeCategory {
Misc = "Misc",
Crypto = "Crypto",
Pwn = "Pwn",
Expand Down Expand Up @@ -875,8 +875,8 @@ export interface ChallengeEditDetailModel {
title: string;
/** 题目内容 */
content?: string;
/** 题目标签 */
tag: ChallengeTag;
/** 题目类别 */
category: ChallengeCategory;
/** 题目类型 */
type: ChallengeType;
/** 题目提示 */
Expand Down Expand Up @@ -1023,8 +1023,8 @@ export interface ChallengeInfoModel {
* @minLength 1
*/
title: string;
/** 题目标签 */
tag?: ChallengeTag;
/** 题目类别 */
category?: ChallengeCategory;
/** 题目类型 */
type?: ChallengeType;
/** 是否启用题目 */
Expand Down Expand Up @@ -1060,8 +1060,8 @@ export interface ChallengeUpdateModel {
* @maxLength 120
*/
flagTemplate?: string | null;
/** 题目标签 */
tag?: ChallengeTag | null;
/** 题目类别 */
category?: ChallengeCategory | null;
/** 题目提示 */
hints?: string[] | null;
/** 是否启用题目 */
Expand Down Expand Up @@ -1376,8 +1376,8 @@ export interface ChallengeInfo {
id?: number;
/** 题目名称 */
title?: string;
/** 题目标签 */
tag?: ChallengeTag;
/** 题目类别 */
category?: ChallengeCategory;
/**
* 题目分值
* @format int32
Expand Down Expand Up @@ -1509,8 +1509,8 @@ export interface ChallengeTrafficModel {
* @minLength 1
*/
title: string;
/** 题目标签 */
tag?: ChallengeTag;
/** 题目类别 */
category?: ChallengeCategory;
/** 题目类型 */
type?: ChallengeType;
/** 是否启用题目 */
Expand Down Expand Up @@ -1640,8 +1640,8 @@ export interface ChallengeDetailModel {
title?: string;
/** 题目内容 */
content?: string;
/** 题目标签 */
tag?: ChallengeTag;
/** 题目类别 */
category?: ChallengeCategory;
/** 题目提示 */
hints?: string[] | null;
/**
Expand Down
14 changes: 7 additions & 7 deletions src/GZCTF/ClientApp/src/components/ChallengeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import cx from 'clsx'
import dayjs from 'dayjs'
import { FC } from 'react'
import { Trans } from 'react-i18next'
import { BloodsTypes, PartialIconProps, useChallengeTagLabelMap } from '@Utils/Shared'
import { BloodsTypes, PartialIconProps, useChallengeCategoryLabelMap } from '@Utils/Shared'
import { ChallengeInfo, SubmissionType } from '@Api'
import classes from '@Styles/ChallengeCard.module.css'
import hoverClasses from '@Styles/HoverCard.module.css'
Expand All @@ -35,8 +35,8 @@ interface ChallengeCardProps {

const ChallengeCard: FC<ChallengeCardProps> = (props: ChallengeCardProps) => {
const { challenge, solved, onClick, iconMap, teamId, colorMap } = props
const challengeTagLabelMap = useChallengeTagLabelMap()
const tagData = challengeTagLabelMap.get(challenge.tag!)
const challengeCategoryLabelMap = useChallengeCategoryLabelMap()
const cateData = challengeCategoryLabelMap.get(challenge.category!)
const theme = useMantineTheme()

return (
Expand All @@ -53,7 +53,7 @@ const ChallengeCard: FC<ChallengeCardProps> = (props: ChallengeCardProps) => {
{challenge.title}
</Text>
</Group>
<Divider size="sm" color={tagData?.color} />
<Divider size="sm" color={cateData?.color} />
<Group wrap="nowrap" justify="space-between" align="center" gap={2}>
<Text ta="center" fw="bold" fz="lg" ff="monospace">
{challenge.score}&nbsp;pts
Expand Down Expand Up @@ -113,11 +113,11 @@ const ChallengeCard: FC<ChallengeCardProps> = (props: ChallengeCardProps) => {
</Stack>
</Group>
</Stack>
{tagData && (
{cateData && (
<Icon
size={4}
path={tagData.icon}
color={alpha(theme.colors[tagData?.color][7], 0.3)}
path={cateData.icon}
color={alpha(theme.colors[cateData?.color][7], 0.3)}
className={classes.icon}
/>
)}
Expand Down
12 changes: 6 additions & 6 deletions src/GZCTF/ClientApp/src/components/ChallengeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { FC, useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import InstanceEntry from '@Components/InstanceEntry'
import Markdown, { InlineMarkdown } from '@Components/MarkdownRenderer'
import { ChallengeTagItemProps } from '@Utils/Shared'
import { ChallengeCategoryItemProps } from '@Utils/Shared'
import { ChallengeDetailModel, ChallengeType } from '@Api'
import classes from '@Styles/ChallengeModal.module.css'

export interface ChallengeModalProps extends ModalProps {
challenge?: ChallengeDetailModel
tagData: ChallengeTagItemProps
cateData: ChallengeCategoryItemProps
solved?: boolean
disabled?: boolean
flag: string
Expand All @@ -39,7 +39,7 @@ export interface ChallengeModalProps extends ModalProps {
const ChallengeModal: FC<ChallengeModalProps> = (props) => {
const {
challenge,
tagData,
cateData,
solved,
disabled,
flag,
Expand Down Expand Up @@ -72,8 +72,8 @@ const ChallengeModal: FC<ChallengeModalProps> = (props) => {
<Stack gap="xs">
<Group wrap="nowrap" w="100%" justify="space-between" gap="sm">
<Group wrap="nowrap" gap="sm">
{tagData && (
<Icon path={tagData.icon} size={1.2} color={theme.colors[tagData?.color][5]} />
{cateData && (
<Icon path={cateData.icon} size={1.2} color={theme.colors[cateData?.color][5]} />
)}
<Title w="calc(100% - 1.5rem)" order={4} lineClamp={1}>
{challenge?.title ?? ''}
Expand All @@ -83,7 +83,7 @@ const ChallengeModal: FC<ChallengeModalProps> = (props) => {
{challenge?.score ?? 0} pts
</Text>
</Group>
<Divider size="md" color={tagData?.color} />
<Divider size="md" color={cateData?.color} />
</Stack>
)

Expand Down
22 changes: 13 additions & 9 deletions src/GZCTF/ClientApp/src/components/ChallengePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import ChallengeCard from '@Components/ChallengeCard'
import Empty from '@Components/Empty'
import GameChallengeModal from '@Components/GameChallengeModal'
import WriteupSubmitModal from '@Components/WriteupSubmitModal'
import { useChallengeTagLabelMap, SubmissionTypeIconMap } from '@Utils/Shared'
import { useChallengeCategoryLabelMap, SubmissionTypeIconMap } from '@Utils/Shared'
import { useGame, useGameTeamInfo } from '@Utils/useGame'
import { ChallengeInfo, ChallengeTag, SubmissionType } from '@Api'
import { ChallengeInfo, ChallengeCategory, SubmissionType } from '@Api'
import classes from '@Styles/ChallengePanel.module.css'

const ChallengePanel: FC = () => {
Expand All @@ -38,8 +38,8 @@ const ChallengePanel: FC = () => {

const { game } = useGame(numId)

const tags = Object.keys(challenges ?? {})
const [activeTab, setActiveTab] = useState<ChallengeTag | 'All'>('All')
const categories = Object.keys(challenges ?? {})
const [activeTab, setActiveTab] = useState<ChallengeCategory | 'All'>('All')
const [hideSolved, setHideSolved] = useLocalStorage({
key: 'hide-solved',
defaultValue: false,
Expand All @@ -60,7 +60,7 @@ const ChallengePanel: FC = () => {
const [detailOpened, setDetailOpened] = useState(false)
const { iconMap, colorMap } = SubmissionTypeIconMap(0.8)
const [writeupSubmitOpened, setWriteupSubmitOpened] = useState(false)
const challengeTagLabelMap = useChallengeTagLabelMap()
const challengeCategoryLabelMap = useChallengeCategoryLabelMap()
const { t } = useTranslation()

// skeleton for loading
Expand Down Expand Up @@ -157,7 +157,7 @@ const ChallengePanel: FC = () => {
orientation="vertical"
variant="pills"
value={activeTab}
onChange={(value) => setActiveTab(value as ChallengeTag)}
onChange={(value) => setActiveTab(value as ChallengeCategory)}
classNames={{
list: classes.tabList,
tabLabel: classes.tabLabel,
Expand All @@ -175,8 +175,8 @@ const ChallengePanel: FC = () => {
</Text>
</Group>
</Tabs.Tab>
{tags.map((tab) => {
const data = challengeTagLabelMap.get(tab as ChallengeTag)!
{categories.map((tab) => {
const data = challengeCategoryLabelMap.get(tab as ChallengeCategory)!
return (
<Tabs.Tab
key={tab}
Expand Down Expand Up @@ -268,7 +268,11 @@ const ChallengePanel: FC = () => {
onClose={() => setDetailOpened(false)}
gameEnded={dayjs(game?.end) < dayjs()}
status={teamInfo?.rank?.solvedChallenges?.find((c) => c.id === challenge?.id)?.type}
tagData={challengeTagLabelMap.get((challenge?.tag as ChallengeTag) ?? ChallengeTag.Misc)!}
cateData={
challengeCategoryLabelMap.get(
(challenge?.category as ChallengeCategory) ?? ChallengeCategory.Misc
)!
}
title={challenge?.title ?? ''}
score={challenge?.score ?? 0}
challengeId={challenge.id}
Expand Down
8 changes: 4 additions & 4 deletions src/GZCTF/ClientApp/src/components/GameChallengeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import React, { FC, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import ChallengeModal from '@Components/ChallengeModal'
import { showErrorNotification } from '@Utils/ApiHelper'
import { ChallengeTagItemProps } from '@Utils/Shared'
import { ChallengeCategoryItemProps } from '@Utils/Shared'
import api, { AnswerResult, ChallengeType, SubmissionType } from '@Api'

interface GameChallengeModalProps extends ModalProps {
gameId: number
gameEnded: boolean
tagData: ChallengeTagItemProps
cateData: ChallengeCategoryItemProps
title: string
score: number
challengeId: number
status?: SubmissionType
}

const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
const { gameId, gameEnded, challengeId, tagData, status, title, score, ...modalProps } = props
const { gameId, gameEnded, challengeId, cateData, status, title, score, ...modalProps } = props

const { data: challenge, mutate } = api.game.useGameGetChallenge(gameId, challengeId, {
refreshInterval: 120 * 1000,
Expand Down Expand Up @@ -216,7 +216,7 @@ const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
<ChallengeModal
{...modalProps}
challenge={challenge ?? { title, score }}
tagData={tagData}
cateData={cateData}
solved={status !== SubmissionType.Unaccepted && status !== undefined}
flag={flag}
setFlag={setFlag}
Expand Down
12 changes: 6 additions & 6 deletions src/GZCTF/ClientApp/src/components/MobileScoreboardItemModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ const MobileScoreboardItemModal: FC<ScoreboardItemModalProps> = (props) => {

const indicator =
challenges &&
Object.keys(challenges).map((tag) => ({
name: tag,
scoreSum: challenges[tag].reduce((sum, chal) => sum + (!chal.solved ? 0 : chal.score!), 0),
Object.keys(challenges).map((cate) => ({
name: cate,
scoreSum: challenges[cate].reduce((sum, chal) => sum + (!chal.solved ? 0 : chal.score!), 0),
max: 1,
}))

const values = indicator?.map((ind) => {
const solvedChallenges = item?.solvedChallenges?.filter(
(chal) => challengeIdMap?.get(chal.id!)?.tag === ind.name
(chal) => challengeIdMap?.get(chal.id!)?.category === ind.name
)
const tagScore = solvedChallenges?.reduce((sum, chal) => sum + chal.score!, 0) ?? 0
return Math.min(tagScore / ind.scoreSum, 1)
const cateScore = solvedChallenges?.reduce((sum, chal) => sum + chal.score!, 0) ?? 0
return Math.min(cateScore / ind.scoreSum, 1)
})

return (
Expand Down
14 changes: 7 additions & 7 deletions src/GZCTF/ClientApp/src/components/ScoreboardItemModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ const ScoreboardItemModal: FC<ScoreboardItemModalProps> = (props) => {

const indicator =
challenges &&
Object.keys(challenges).map((tag) => ({
name: tag,
scoreSum: challenges[tag].reduce((sum, chal) => sum + (!chal.solved ? 0 : chal.score!), 0),
Object.keys(challenges).map((cate) => ({
name: cate,
scoreSum: challenges[cate].reduce((sum, chal) => sum + (!chal.solved ? 0 : chal.score!), 0),
max: 1,
}))

const values = indicator?.map((ind) => {
const solvedChallenges = item?.solvedChallenges?.filter(
(chal) => challengeIdMap?.get(chal.id!)?.tag === ind.name
(chal) => challengeIdMap?.get(chal.id!)?.category === ind.name
)
const tagScore = solvedChallenges?.reduce((sum, chal) => sum + chal.score!, 0) ?? 0
return Math.min(tagScore / ind.scoreSum, 1)
const cateScore = solvedChallenges?.reduce((sum, chal) => sum + chal.score!, 0) ?? 0
return Math.min(cateScore / ind.scoreSum, 1)
})

return (
Expand Down Expand Up @@ -166,7 +166,7 @@ const ScoreboardItemModal: FC<ScoreboardItemModalProps> = (props) => {
/>
</Table.Td>
<Table.Td ff="monospace" fz="sm">
{info.tag}
{info.category}
</Table.Td>
<Table.Td ff="monospace" fz="sm">
{chal.score}
Expand Down
Loading

0 comments on commit 4238c5e

Please sign in to comment.