Skip to content

Commit

Permalink
modal window only appears if the problem is solved
Browse files Browse the repository at this point in the history
  • Loading branch information
dbence2002 committed Sep 26, 2023
1 parent 7d8d28f commit f095322
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 37 deletions.
2 changes: 1 addition & 1 deletion frontend/src/RoutingComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function RoutingComponent() {
const routeIndex = findRouteIndex(routes, location.pathname);
if (routeIndex !== -1) {
const params = extractParams(location.pathname, routes[routeIndex]);
console.log(params)
console.log(params);
document.title = t(titles[routes[routeIndex]], { params });
} else {
document.title = "njudge";
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/container/TagListFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function LinkTag({ data }) {
}

function TagListFrame({ title, titleComponent, tag: Tag = DefaultTag, tags }) {
console.log(tags)
console.log("nigga")
console.log(tags);
console.log("nigga");
const tagsContent = tags.map((item, index) => (
<div className="flex m-1" key={index}>
<Tag data={item} key={index} />
Expand Down
33 changes: 22 additions & 11 deletions frontend/src/components/container/modal/Modal.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faClose } from "@fortawesome/free-solid-svg-icons";

function Modal({children, isOpen, onClose}) {
function Modal({ children, isOpen, onClose }) {
return (
<>
{isOpen &&
<div className="z-40 fixed inset-0 bg-black opacity-50" onClick={onClose}>
<button onClick={onClose} className="flex items-center justify-center absolute top-2 right-2 p-2 rounded-full bg-transparent hover:bg-grey-100 dark:hover:bg-grey-800">
<FontAwesomeIcon icon={faClose} className="w-6 h-6 text-white" />
{isOpen && (
<div
className="z-40 fixed inset-0 bg-black opacity-50"
onClick={onClose}>
<button
onClick={onClose}
className="flex items-center justify-center absolute top-2 right-2 p-2 rounded-full bg-transparent hover:bg-grey-100 dark:hover:bg-grey-800">
<FontAwesomeIcon
icon={faClose}
className="w-6 h-6 text-white"
/>
</button>
</div>}
{isOpen &&
<div className="z-50 fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2" onClick={(event) => event.stopPropagation()}>
</div>
)}
{isOpen && (
<div
className="z-50 fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
onClick={(event) => event.stopPropagation()}>
{children}
</div>}
</div>
)}
</>
)
);
}

export default Modal
export default Modal;
32 changes: 22 additions & 10 deletions frontend/src/components/container/modal/TagModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,39 @@ import TagDropdown from "../../input/TagDropdown";
import SVGTitleComponent from "../../svg/SVGTitleComponent";
import JudgeDataContext from "../../../contexts/judgeData/JudgeDataContext";

function TagModal({isOpen, onClose}) {
const { t } = useTranslation()
const { judgeData } = useContext(JudgeDataContext)
function TagModal({ isOpen, onClose }) {
const { t } = useTranslation();
const { judgeData } = useContext(JudgeDataContext);
const titleComponent = (
<SVGTitleComponent svg={<FontAwesomeIcon icon={faTags} className="w-5 h-5 mr-2" />} title={t("tag_modal.title")} />
)
<SVGTitleComponent
svg={<FontAwesomeIcon icon={faTags} className="w-5 h-5 mr-2" />}
title={t("tag_modal.title")}
/>
);
return (
<Modal isOpen={isOpen} onClose={onClose}>
<RoundedFrame titleComponent={titleComponent} cls="shadow-md">
<div className="w-96 px-6 py-5">
<div className="mb-5">
<TagDropdown itemNames={judgeData.tags.map(t)} initTags={[0, 1]} />
<TagDropdown
itemNames={judgeData.tags.map(t)}
initTags={[0, 1]}
/>
</div>
<div className="flex justify-center">
<button className="w-full btn-indigo padding-btn-default mr-2">{t("tag_modal.save")}</button>
<button className="w-full btn-gray padding-btn-default" onClick={onClose}>{t("tag_modal.cancel")}</button>
<button className="w-full btn-indigo padding-btn-default mr-2">
{t("tag_modal.save")}
</button>
<button
className="w-full btn-gray padding-btn-default"
onClick={onClose}>
{t("tag_modal.cancel")}
</button>
</div>
</div>
</RoundedFrame>
</Modal>
)
);
}

export default TagModal
export default TagModal;
2 changes: 1 addition & 1 deletion frontend/src/components/input/TagDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function TagDropdown({ id, label, itemNames, initTags = [], onChange }) {
const [tags, setTags] = useState(initTags);
useEffect(() => {
if (onChange) {
onChange(tags)
onChange(tags);
}
}, [onChange, tags]);

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/config/RouteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export const routeMap = {
admin: "/user/admin/",
};

const apiRoot = "https://127.0.0.1:5555/api/v2"
const apiRoot = "https://127.0.0.1:5555/api/v2";

export function apiRoute(route) {
console.log(`${apiRoot}${route}`)
return `${apiRoot}${route}`
console.log(`${apiRoot}${route}`);
return `${apiRoot}${route}`;
}
2 changes: 1 addition & 1 deletion frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
}

#root {
@apply h-full antialiased bg-grey-900 text-textcol
@apply h-full antialiased bg-grey-900 text-textcol;
}

.padding-btn-default {
Expand Down
33 changes: 25 additions & 8 deletions frontend/src/pages/problem/ProblemStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import TagModal from "../../components/container/modal/TagModal";

function ProblemInfo({ info }) {
const { t } = useTranslation();
const { theme } = useContext(ThemeContext)
const [isModalOpen, setModalOpen] = useState(false)
const { theme } = useContext(ThemeContext);
const [isModalOpen, setModalOpen] = useState(false);
const tagsContent = (
<div className="flex-col">
<div className="flex flex-wrap mb-4">
Expand All @@ -42,9 +42,17 @@ function ProblemInfo({ info }) {
{t(tagName)}
</span>
))}
<button className="tag flex items-center" key={info.tags.length} onClick={() => setModalOpen(true)}>
<FontAwesomeIcon icon={theme === "light"? faPenToSquare: faEdit} className="w-3 h-3" />
</button>
{info.isSolved && (
<button
className="tag flex items-center"
key={info.tags.length}
onClick={() => setModalOpen(true)}>
<FontAwesomeIcon
icon={theme === "light" ? faPenToSquare : faEdit}
className="w-3 h-3"
/>
</button>
)}
</div>
</div>
);
Expand All @@ -56,7 +64,12 @@ function ProblemInfo({ info }) {
);
return (
<>
<TagModal isOpen={isModalOpen} onClose={() => setModalOpen(false)}/>
{info.isSolved && (
<TagModal
isOpen={isModalOpen}
onClose={() => setModalOpen(false)}
/>
)}
<MapDataFrame
titleComponent={titleComponent}
data={[
Expand Down Expand Up @@ -212,7 +225,9 @@ function ProblemAttachment({ type, name, href }) {
<li>
<a
className="link no-underline flex items-start my-0.5"
href={apiRoute(href)} download="statement.pdf" target="_blank">
href={apiRoute(href)}
download="statement.pdf"
target="_blank">
{type === "file" && (
<SVGAttachmentFile cls="w-5 h-5 mr-2 shrink-0" />
)}
Expand Down Expand Up @@ -280,7 +295,9 @@ function ProblemStatement({ data }) {
<div className="w-full px-4 py-3 sm:px-6 sm:py-5 flex">
<div className="w-full mr-3 min-w-0">
<DropdownMenu
itemNames={data.attachments.statements.map(item => item.name)}
itemNames={data.attachments.statements.map(
(item) => item.name,
)}
onChange={setStatementIndex}
/>
</div>
Expand Down

0 comments on commit f095322

Please sign in to comment.