Skip to content

Commit

Permalink
Perf for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Oct 2, 2023
1 parent 49ed9ae commit da54e87
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/components/ProblemTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ProblemTableProps {
data: ProblemServiceModel.ProblemInfo[];
showActions?: boolean;
enableNavigation?: boolean;
className?: string;
}

const ProblemTable: React.FC<ProblemTableProps> = (props) => {
Expand All @@ -50,7 +51,7 @@ const ProblemTable: React.FC<ProblemTableProps> = (props) => {
);

return (
<Table aria-label="Problem Table">
<Table className={props.className} aria-label="Problem Table">
<TableHeader
columns={columns.filter((col) => {
if (!props.showActions) {
Expand Down
8 changes: 6 additions & 2 deletions src/layouts/LanguageMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import { LanguageIcon } from "@heroicons/react/24/outline";
import { changeLanguage } from "i18next";
import { LANGUAGE_SELECTIONS } from "../i18n/i18n";

const LanguageMenu: React.FC = () => {
interface LanguageMenuProps {
className?: string;
}

const LanguageMenu: React.FC<LanguageMenuProps> = (props) => {
const { t } = useTranslation();

return (
<>
{/* Profile dropdown */}
<Menu as="div" className="relative">
<Menu as="div" className={joinClasses("relative", props.className)}>
<Menu.Button className="flex items-center p-1.5">
<span className="sr-only">Open user menu</span>
<LanguageIcon className="h-5 w-5" />
Expand Down
54 changes: 25 additions & 29 deletions src/layouts/userLayout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Fragment } from "react";
import { Disclosure } from "@headlessui/react";
import {
Bars3Icon,
BellIcon,
XMarkIcon,
TrophyIcon,
ListBulletIcon,
Expand All @@ -12,6 +11,7 @@ import { joinClasses } from "../../utils/common";
import LanguageMenu from "../LanguageMenu";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { Divider } from "@nextui-org/react";

const iconPath = `${import.meta.env.BASE_URL}images/oj-lab-icon.svg`;

Expand Down Expand Up @@ -108,24 +108,6 @@ export default function Header() {
</div>

<Disclosure.Panel className="sm:hidden">
<div className="space-y-1 pb-3 pt-2">
{navigation.map((item) => (
<Disclosure.Button
key={item.name}
className={joinClasses(
item.current
? "border-indigo-500 bg-indigo-50 text-indigo-700"
: "border-transparent text-gray-600 hover:border-gray-300 hover:bg-gray-50 hover:text-gray-800",
"block cursor-pointer border-l-4 py-2 pl-3 pr-4 text-base font-medium",
)}
onClick={() => {
navigate(item.href);
}}
>
{t(item.name)}
</Disclosure.Button>
))}
</div>
<div className="border-t border-gray-200 pb-3 pt-4">
<div className="flex items-center px-4">
<div className="flex-shrink-0">
Expand All @@ -143,27 +125,41 @@ export default function Header() {
{user.email}
</div>
</div>
<button
type="button"
className="ml-auto flex-shrink-0 rounded-full bg-white p-1 text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
>
<span className="sr-only">View notifications</span>
<BellIcon className="h-6 w-6" aria-hidden="true" />
</button>
<LanguageMenu className="ml-auto" />
</div>
<div className="mt-3 space-y-1">
{userNavigation.map((item) => (
<Disclosure.Button
key={item.name}
as="a"
href={item.href}
className="block px-4 py-2 text-base font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800"
className="block cursor-pointer px-4 py-2 text-base font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800"
onClick={() => {
navigate(item.href);
}}
>
{item.name}
</Disclosure.Button>
))}
</div>
</div>
<Divider />
<div className="space-y-1 pb-3 pt-2">
{navigation.map((item) => (
<Disclosure.Button
key={item.name}
className={joinClasses(
item.current
? "border-indigo-500 bg-indigo-50 text-indigo-700"
: "border-transparent text-gray-600 hover:border-gray-300 hover:bg-gray-50 hover:text-gray-800",
"block w-full cursor-pointer border-l-4 py-2 pl-3 pr-4 text-base font-medium",
)}
onClick={() => {
navigate(item.href);
}}
>
{t(item.name)}
</Disclosure.Button>
))}
</div>
</Disclosure.Panel>
</>
)}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Problem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const Problem: React.FC = () => {

return (
<UserLayout title={getProblem()?.title}>
<div className="flex">
<div className="w-1/2 flex-1 ">
<div className="flex flex-col sm:flex-row">
<div className="w-full flex-1 sm:w-1/2">
<MarkdownRender
content={getProblem()?.description || ""}
rehypePlugin="rehypeKatex"
/>
</div>
<div className="flex w-1/2 flex-col gap-4">
<div className="flex w-full flex-col gap-4 sm:w-1/2">
<CodeEditor
className="h-96 w-full overflow-hidden"
value={defaultCode}
Expand Down
17 changes: 8 additions & 9 deletions src/pages/ProblemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ const ProblemList: React.FC = () => {

return (
<UserLayout>
<div className="flex gap-8">
<div className="w-2/3">
<ProblemTable
data={getProblemInfoList()}
showActions={false}
enableNavigation
/>
</div>
<div className="w-1/3">
<div className="flex w-full flex-auto flex-col gap-8 px-4 sm:flex-row">
<ProblemTable
data={getProblemInfoList()}
showActions={false}
enableNavigation
className="w-full sm:w-2/3"
/>
<div className="w-full sm:w-1/3">
<NewsCard />
</div>
</div>
Expand Down

0 comments on commit da54e87

Please sign in to comment.