Skip to content

Commit

Permalink
Implement contest review Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
dongzoolee committed Sep 17, 2024
1 parent 58231cf commit c2f49f4
Show file tree
Hide file tree
Showing 26 changed files with 234 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { createContext, useContext, useEffect, useState } from "react";

import { type THistoryData } from "../../../contexts/history-data-context";

type TSelectedHistoryContext = {
export type TSelectedHistoryContext = {
year: number;
setYear: React.Dispatch<React.SetStateAction<number>>;
data: THistoryData["all"][number];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ import { styled } from "styled-components";
import { Section } from "@ui/section/section";
import { Table } from "@ui/table/table";
import { AwardBadge, TAwardBadgeVariant } from "@ui/award-badge/award-badge";
import { OpenInANewTab } from "@ui/open-in-a-new-tab";

import { useSelectedHistoryContext } from "./contexts/selected-history-context";

const LinksWrapper = styled.ul`
margin-top: 16px;
`;
import { useSelectedHistoryContext } from "../contexts/selected-history-context";
import { LinksAndReviews } from "./links-and-reviews";

const _HistoryDisplay = ({ className }: { className?: string }) => {
const selectedHistory = useSelectedHistoryContext();

return (
<div className={className}>
{selectedHistory.data.contests.map(
({ title, columns, data, award, links }) => (
({ title, columns, data, award, links, review }) => (
<Section key={title}>
<Section.Title>{title}</Section.Title>
<Section.Body>
Expand Down Expand Up @@ -56,16 +52,7 @@ const _HistoryDisplay = ({ className }: { className?: string }) => {
</Table.Body>
</Table>
</Table.Wrapper>
<LinksWrapper>
{links?.map((link) => {
return (
<li key={link[1]}>
<OpenInANewTab href={link[1]}>{link[0]}</OpenInANewTab>
</li>
);
})}
{/* TODO: Show Review Table */}
</LinksWrapper>
<LinksAndReviews links={links} review={review} />
</Section.Body>
</Section>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { useState } from "react";
import { styled } from "styled-components";

import { OpenInANewTab } from "@ui/open-in-a-new-tab";
import { Modal } from "@ui/modal/modal";
import { Table } from "@ui/table/table";
import { OpenInANewTabButton } from "@ui/button/open-in-a-new-tab-button";
import { Button } from "@ui/button/button";

import { TSelectedHistoryContext } from "../contexts/selected-history-context";
const ReviewTable = styled(Table)`
min-width: unset;
margin-top: 12px;
`;
const LinksWrapper = styled.div`
display: flex;
gap: 8px;
margin-top: 16px;
`;
const ReviewLinkCell = styled(Table.Cell)`
word-break: break-all;
`;

export const LinksAndReviews = ({
className,
links,
review,
}: {
className?: string;
links: TSelectedHistoryContext["data"]["contests"][number]["links"];
review: TSelectedHistoryContext["data"]["contests"][number]["review"];
}) => {
const [showModal, setShowModal] = useState(false);

return (
<div className={className}>
<LinksWrapper>
{links.map((link) => {
return (
<OpenInANewTabButton key={link[1]} href={link[1]}>
{link[0]}
</OpenInANewTabButton>
);
})}
{review.length > 0 ? (
<Button onClick={() => setShowModal(true)}>대회 후기</Button>
) : null}
<Modal
show={showModal}
onClose={() => setShowModal(false)}
header="대회 후기"
body={
<Table.Wrapper>
<ReviewTable>
<Table.Header>
<Table.Row>
<Table.Head>작성자</Table.Head>
<Table.Head>링크</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{review.map((r) => (
<Table.Row key={r[0]}>
<Table.Cell>{r[0]}</Table.Cell>
<ReviewLinkCell>
<OpenInANewTab href={r[1]}>{r[1]}</OpenInANewTab>
</ReviewLinkCell>
</Table.Row>
))}
</Table.Body>
</ReviewTable>
</Table.Wrapper>
}
footer={<></>}
/>
</LinksWrapper>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ScoreboardImage from "./assets/scoreboard.jpg";
import { HistoryTab } from "./history-tab";
import { useHistoryDataContext } from "../../contexts/history-data-context";
import { SelectedHistoryContextProvider } from "./contexts/selected-history-context";
import { HistoryDisplay } from "./history-display";
import { HistoryDisplay } from "./history-display/history-display";
import constants from "../../contexts/assets/constants";

const GrayText = styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const Button = styled.button`
display: inline-flex;
align-items: center;
height: 42px;
line-height: 42px;
padding: 12px 16px;
height: 36px;
line-height: 36px;
padding: 0 12px;
border: 1px solid #b60005;
border-radius: 12px;
Expand Down
47 changes: 47 additions & 0 deletions sogang-icpc-team.github.io-react/src/common/ui/modal/modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Modal as AntdModal } from "antd";
import { useEffect, useState } from "react";
import { createGlobalStyle } from "styled-components";

const ModalStyles = createGlobalStyle`
.ant-modal-mask {
background-color: transparent !important;
backdrop-filter: blur(1px);
}
`;
export const Modal = ({
show,
onClose,
header,
body,
footer,
}: {
show: boolean;
onClose: () => void;
header?: React.ReactNode;
body: React.ReactNode;
footer?: React.ReactNode;
}) => {
const [open, setOpen] = useState(false);

useEffect(() => {
setOpen(show);
}, [show]);

const handleClose = () => {
onClose();
};

return (
<>
<ModalStyles />
<AntdModal
open={open}
onClose={handleClose}
onCancel={handleClose}
title={header}
children={body}
footer={footer}
/>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
data: [["9", "-", "Weird-OS", "김영욱, 심재은, 이한승"]],
award: ["bronze"],
links: [["공식 사이트", "http://icpckorea.org/2005-seoul/regional"]],
review: [],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
data: [["-", "-", "IHS", "김영욱, 김우현, 최병현"]],
award: [""],
links: [["공식 사이트", "http://icpckorea.org/2006-seoul/regional"]],
review: [],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
data: [["6", "-", "Kuru", "김우현, 안재원, 최백준"]],
award: ["silver"],
links: [["공식 사이트", "http://icpckorea.org/2007-seoul/regional"]],
review: [],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ export default {
data: [["8", "-", "Coderani", "김우현, 안재원, 최백준"]],
award: ["silver"],
links: [["공식 사이트", "http://icpckorea.org/2008-seoul/regional"]],
review: [],
},
{
title: "2008 ACM-ICPC Asia Kuala Lumpur Regional Contest",
columns: ["#", "=", "팀", "멤버"],
data: [["14", "-", "Greenzilla", "김우현, 안재원, 최백준"]],
award: [""],
links: [["공식 사이트", "http://icpckorea.org/2008-seoul/regional"]],
review: [],
},
{
title: "Google Code Jam APAC Semifinal 2008",
Expand All @@ -26,6 +28,7 @@ export default {
"https://code.google.com/codejam/contest/32005/dashboard",
],
],
review: [],
},
{
title: "Google Code Jam Round 3 2008",
Expand All @@ -38,6 +41,7 @@ export default {
"https://code.google.com/codejam/contest/32002/dashboard",
],
],
review: [],
},
{
title: "Google Code Jam Round 2 2008",
Expand All @@ -50,6 +54,7 @@ export default {
"https://code.google.com/codejam/contest/32001/dashboard",
],
],
review: [],
},
{
title: "Google Code Jam Round 1B 2008",
Expand All @@ -62,12 +67,15 @@ export default {
"https://code.google.com/codejam/contest/32017/dashboard",
],
],
review: [],
},
{
title: "Java Algorithm Contest",
columns: ["#", "팀", "멤버"],
data: [["3", "C#", "김우현, 안재원, 최백준"]],
award: ["bronze"],
links: [],
review: [],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {
],
award: ["silver", "", ""],
links: [["공식 사이트", "http://icpckorea.org/2009-seoul/regional"]],
review: [],
},
{
title: "2009 ACM-ICPC Asia Amritapuri Regional Contest",
Expand All @@ -23,12 +24,15 @@ export default {
"https://icpc.baylor.edu/regionals/finder/amritapuri-2009",
],
],
review: [],
},
{
title: "Java Algorithm Contest",
columns: ["#", "팀", "멤버"],
data: [["3", "KTX", "최백준 (+ 타교생 2인)"]],
award: [""],
links: [],
review: [],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default {
links: [
["공식 사이트", "https://icpc.baylor.edu/community/results-2010"],
],
review: [],
},
{
title: "2010 ACM-ICPC Asia Daejeon Regional Contest",
Expand All @@ -19,6 +20,7 @@ export default {
],
award: ["", ""],
links: [["공식 사이트", "http://icpckorea.org/2010-daejeon/regional"]],
review: [],
},
{
title: "2010 ACM-ICPC Asia Daejeon Preliminary Contest",
Expand Down Expand Up @@ -54,6 +56,7 @@ export default {
"",
],
links: [["공식 사이트", "http://icpckorea.org/2010-daejeon/regional"]],
review: [],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default {
],
award: ["silver", "", "", ""],
links: [["공식 사이트", "http://icpckorea.org/2011-daejeon/regional"]],
review: [],
},
{
title: "2011 ACM-ICPC Asia Daejeon Preliminary Contest",
Expand Down Expand Up @@ -39,6 +40,7 @@ export default {
"",
],
links: [["공식 사이트", "http://icpckorea.org/2011-daejeon/regional"]],
review: [],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
],
award: ["silver", "", "", "", ""],
links: [["공식 사이트", "http://icpckorea.org/2012-daejeon/regional"]],
review: [],
},
{
title: "2012 ACM-ICPC Asia Daejeon Preliminary Contest",
Expand All @@ -38,13 +39,15 @@ export default {
"",
],
links: [["공식 사이트", "http://icpckorea.org/2012-daejeon/regional"]],
review: [],
},
{
title: "SK Planet Code Spring Round 1",
columns: ["#", "이름"],
data: [["3", "최백준"]],
award: [""],
links: [],
review: [],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
],
award: ["silver", "", "", "", ""],
links: [["공식 사이트", "http://icpckorea.org/2013-daejeon/regional"]],
review: [],
},
{
title: "2013 ACM-ICPC Asia Daejeon Preliminary Contest",
Expand Down Expand Up @@ -48,6 +49,7 @@ export default {
"",
],
links: [["공식 사이트", "http://icpckorea.org/2013-daejeon/regional"]],
review: [],
},
],
};
Loading

0 comments on commit c2f49f4

Please sign in to comment.