Skip to content

Commit

Permalink
fix(frontend): challenge modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Jun 2, 2024
1 parent 81a0be2 commit 3a65b31
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 33 deletions.
34 changes: 4 additions & 30 deletions web/src/components/modals/ChallengeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
ActionIcon,
ModalProps,
Modal,
LoadingOverlay,
} from "@mantine/core";
import MDIcon from "@/components/ui/MDIcon";
import FirstBloodIcon from "@/components/icons/hexagons/FirstBloodIcon";
Expand All @@ -37,29 +36,23 @@ import {
} from "@/utils/notification";
import { useForm } from "@mantine/form";
import { useTeamStore } from "@/stores/team";
import { useChallengeApi } from "@/api/challenge";

interface ChallengeModalProps extends ModalProps {
challengeID?: number;
challenge?: Challenge;
gameID?: number;
setRefresh: () => void;
mode?: "practice" | "game";
}

export default function ChallengeModal(props: ChallengeModalProps) {
const { challengeID, gameID, setRefresh, mode, ...modalProps } = props;
const { challenge, gameID, setRefresh, mode, ...modalProps } = props;

const { colorScheme } = useMantineColorScheme();
const podApi = usePodApi();
const challengeApi = useChallengeApi();
const submissionApi = useSubmissionApi();
const authStore = useAuthStore();
const teamStore = useTeamStore();

const [challenge, setChallenge] = useState<Challenge>();

const [loading, setLoading] = useState<boolean>(true);

const [pod, setPod] = useState<Pod>();
const [podCreateLoading, setPodCreateLoading] = useState(false);

Expand All @@ -70,25 +63,10 @@ export default function ChallengeModal(props: ChallengeModalProps) {
},
});

function getChallenge() {
setLoading(true);
challengeApi
.getChallenges({
id: challengeID,
})
.then((res) => {
const r = res.data;
setChallenge(r.data?.[0]);
})
.finally(() => {
setLoading(false);
});
}

function getPod() {
podApi
.getPods({
challenge_id: challengeID,
challenge_id: challenge?.id,
user_id: mode === "practice" ? authStore?.user?.id : undefined,
team_id:
mode === "game" ? teamStore?.selectedTeamID : undefined,
Expand Down Expand Up @@ -170,7 +148,7 @@ export default function ChallengeModal(props: ChallengeModalProps) {

submissionApi
.createSubmission({
challenge_id: challengeID,
challenge_id: challenge?.id,
flag: flag,
team_id:
mode === "game" ? teamStore?.selectedTeamID : undefined,
Expand Down Expand Up @@ -226,9 +204,6 @@ export default function ChallengeModal(props: ChallengeModalProps) {

useEffect(() => {
form.reset();
if (modalProps.opened) {
getChallenge();
}
}, [modalProps.opened]);

return (
Expand All @@ -254,7 +229,6 @@ export default function ChallengeModal(props: ChallengeModalProps) {
justifyContent: "space-between",
}}
>
<LoadingOverlay visible={loading} />
<Box>
<Box
sx={{
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/modals/TeamEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ export default function TeamEditModal(props: TeamEditModalProps) {
<Flex mt={20} justify={"end"} gap={10}>
<Button
leftSection={
<MDIcon color="red">
<MDIcon c={"white"}>
swap_horiz
</MDIcon>
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/challenges/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default function Page() {
opened={opened}
onClose={close}
centered
challengeID={selectedChallenge?.id}
challenge={selectedChallenge}
setRefresh={() => setRefresh((prev) => prev + 1)}
mode="practice"
/>
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/games/[id]/challenges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ function Page() {
onClose={close}
centered
setRefresh={() => setRefresh((prev) => prev + 1)}
challengeID={selectedChallenge?.challenge_id}
challenge={selectedChallenge?.challenge}
gameID={selectedChallenge?.game_id}
mode="game"
/>
Expand Down

0 comments on commit 3a65b31

Please sign in to comment.