Skip to content

Commit

Permalink
prettifying
Browse files Browse the repository at this point in the history
  • Loading branch information
dbence2002 committed Sep 25, 2023
1 parent bee5910 commit 88ec160
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 48 deletions.
43 changes: 26 additions & 17 deletions frontend/src/components/concrete/other/ProblemFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,32 @@ function ProblemFilter() {
const navigate = useNavigate();

const parseTitle = (title) => {
return title? title: ""
}
return title ? title : "";
};
const parseCategory = (category) => {
if (category === undefined) {
return -1
return -1;
}
const categoryInt = parseInt(category)
return judgeData.categories.findIndex(item => item.value === categoryInt)
}
const categoryInt = parseInt(category);
return judgeData.categories.findIndex(
(item) => item.value === categoryInt,
);
};
const parseTags = (tags) => {
if (tags === undefined) {
return []
return [];
}
const tokens = tags.split(",").map(parseInt)
if (tokens.some(elem => isNaN(elem) || elem <= -1 || elem >= judgeData.tags.length)) {
return []
const tokens = tags.split(",").map(parseInt);
if (
tokens.some(
(elem) =>
isNaN(elem) || elem <= -1 || elem >= judgeData.tags.length,
)
) {
return [];
}
return tokens
}
return tokens;
};
const qData = queryString.parse(location.search);
const [title, setTitle] = useState(parseTitle(qData.title));
const [tags, setTags] = useState(parseTags(qData.tags));
Expand All @@ -58,9 +65,7 @@ function ProblemFilter() {
[
title,
tags.join(","),
category === -1
? -1
: judgeData.categories[category].value,
category === -1 ? -1 : judgeData.categories[category].value,
],
["title", "tags", "category"],
null,
Expand Down Expand Up @@ -97,10 +102,14 @@ function ProblemFilter() {
<TextBoxDropdown
id="filterCategory"
label={t("problem_filter.category")}
initText={category === -1? "": judgeData.categories[category].label}
initText={
category === -1
? ""
: judgeData.categories[category].label
}
initSelected={category}
fillSelected={true}
itemNames={judgeData.categories.map(x => x.label)}
itemNames={judgeData.categories.map((x) => x.label)}
onChange={handleCategoryChange}
/>
</div>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/concrete/table/ProblemsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ function ProblemsTable({ problems }) {
</th>
</tr>
</thead>
<tbody className="divide-y divide-dividecol">{problemsContent}</tbody>
<tbody className="divide-y divide-dividecol">
{problemsContent}
</tbody>
</RoundedTable>
);
}
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/input/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ function Checkbox({ id, label, initChecked, onChange }) {
className={`flex border items-center justify-center ${
checked
? `border-transparent ${
hovered
? "bg-indigo-500"
: "bg-indigo-600"
hovered ? "bg-indigo-500" : "bg-indigo-600"
}`
: `${
hovered ? "bg-grey-825" : "bg-grey-850"
Expand Down
16 changes: 9 additions & 7 deletions frontend/src/components/input/TagDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ function TagDropdown({ id, label, itemNames, initTags = [], onChange }) {

const tagsContent = tags.map((tag, index) => {
const handleRemoveTag = () => {
setTags(prevTags =>
prevTags.filter(prevTag => prevTag !== tag),
setTags((prevTags) =>
prevTags.filter((prevTag) => prevTag !== tag),
);
};
return <Tag title={itemNames[tag]} onClick={handleRemoveTag} key={index} />;
return (
<Tag title={itemNames[tag]} onClick={handleRemoveTag} key={index} />
);
});
const handleAddTag = (selected, title) => {
const remaining = _.range(itemNames.length).filter(
index => !tags.includes(index),
)
const tag = remaining[selected]
setTags(prevTags =>
(index) => !tags.includes(index),
);
const tag = remaining[selected];
setTags((prevTags) =>
prevTags.includes(tag) ? prevTags : [...prevTags, tag],
);
};
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/components/input/TextBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ function TextBox({
</label>
<div
className={`border-b-1 ${
focused
? "border-indigo-600"
: "border-transparent"
focused ? "border-indigo-600" : "border-transparent"
} w-full mt-1`}>
<div
className={`border-b-1 ${
focused
? "border-indigo-600"
: "border-bordercol"
focused ? "border-indigo-600" : "border-bordercol"
} w-full`}>
<input
id={id}
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/contexts/theme/ThemeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ function ThemeProvider({ children }) {
return;
}
setTheme(newTheme);
const doc = document.documentElement
const doc = document.documentElement;
if (newTheme !== "light") {
doc.classList.remove("light")
doc.classList.remove("light");
}
if (newTheme !== "dark") {
doc.classList.remove("dark")
doc.classList.remove("dark");
}
doc.setAttribute("data-theme", newTheme)
doc.classList.add(newTheme)
doc.setAttribute("data-theme", newTheme);
doc.classList.add(newTheme);
localStorage.setItem("theme", newTheme);
};
return (
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/pages/Submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ function CompileErrorFrame({ message }) {
const titleComponent = (
<SVGTitleComponent
title={t("submission.compilation_error")}
svg={
<SVGWrongSimple cls="w-6 h-6 mr-2 text-red-600" />
}
svg={<SVGWrongSimple cls="w-6 h-6 mr-2 text-red-600" />}
/>
);

Expand Down
8 changes: 2 additions & 6 deletions frontend/src/pages/profile/ProfileMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ function ProfileMain({ data }) {
const { t } = useTranslation();
const titleComponentCorrect = (
<SVGTitleComponent
svg={
<SVGCorrectSimple cls="w-6 h-6 text-green-600 mr-2" />
}
svg={<SVGCorrectSimple cls="w-6 h-6 text-green-600 mr-2" />}
title={t("profile_main.solved_problems")}
/>
);
const titleComponentWrong = (
<SVGTitleComponent
svg={
<SVGWrongSimple cls="w-6 h-6 text-red-600 mr-2" />
}
svg={<SVGWrongSimple cls="w-6 h-6 text-red-600 mr-2" />}
title={t("profile_main.unsolved_problems")}
/>
);
Expand Down

0 comments on commit 88ec160

Please sign in to comment.