Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mobile adjust #51

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { cn, getMenu } from "@/lib/utils";
import { Footer } from "@/components/footer";
import Header from "@/components/Header";
import { Suspense } from "react";
import { headers } from "next/headers";
import Loading from "./loading";
import { isMobile } from "../lib/isMobile";

const fontSans = FontSans({
subsets: ["latin"],
Expand All @@ -24,7 +26,8 @@ export default async function RootLayout({
children: React.ReactNode;
}>) {
const menu = await getMenu();

const userAgent = headers().get("user-agent") || "";
const isMobileDevice = isMobile(userAgent);
return (
<html lang="en">
<body
Expand All @@ -34,7 +37,7 @@ export default async function RootLayout({
)}
>
<AntdRegistry>
<Header menu={menu} />
<Header menu={menu} isMobileDevice={isMobileDevice} />
<Suspense fallback={<Loading />}>{children}</Suspense>
<Footer />
</AntdRegistry>
Expand Down
26 changes: 16 additions & 10 deletions app/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { Skeleton } from "@/components/ui/skeleton";
import { headers } from "next/headers";
import { isMobile } from "../lib/isMobile";

export default function Loading() {
const userAgent = headers().get("user-agent") || "";
const isMobileDevice = isMobile(userAgent);
return (
<div className="flex-1 px-4 sm:px-6 lg:px-8">
<div className="grid gap-8 py-8 min-h-[calc(100vh-225px)] grid-cols-[300px_1fr]">
<div className="">
<nav className="space-y-4">
<Skeleton className="h-6 w-32" />
<Skeleton className="h-6 w-32" />
<Skeleton className="h-6 w-32" />
<Skeleton className="h-6 w-32" />
<Skeleton className="h-6 w-32" />
<Skeleton className="h-6 w-32" />
</nav>
</div>
{!isMobileDevice && (
<div className="">
<nav className="space-y-4">
<Skeleton className="h-6 w-32" />
<Skeleton className="h-6 w-32" />
<Skeleton className="h-6 w-32" />
<Skeleton className="h-6 w-32" />
<Skeleton className="h-6 w-32" />
<Skeleton className="h-6 w-32" />
</nav>
</div>
)}
<div className="space-y-8 mt-[60px]">
<div>
<Skeleton className="h-8 w-64" />
Expand Down
8 changes: 4 additions & 4 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ export default async function Home() {
configObj[ele.fields.key!] = ele.fields.value;
});
return (
<main className="p-8 container min-h-[calc(100vh-225px)]">
<div className="mt-[60px] bg-white">
<div className="relative w-full h-[322px] mb-6">
<main className="pt-8 container min-h-[calc(100vh-225px)]">
<div className="sm:mt-[60px] mt-10 bg-white">
<div className="relative w-full sm:h-[322px] h-[82px] mb-6">
<Image
src={configObj.image}
alt="Banner Image"
layout="fill"
objectFit="cover"
objectFit="fill"
/>
</div>
<h1 className="text-4xl font-bold mb-4">{configObj.title}</h1>
Expand Down
6 changes: 5 additions & 1 deletion app/wiki/[...id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ import Sidebar from "@/components/sidebar/index";
import Breadcrumb from "@/components/Breadcrumb";
import { Suspense } from "react";
import Loading from "./loading";
import { headers } from "next/headers";
import { isMobile } from "../../../lib/isMobile";

export default async function WikiLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const menu = await getMenu();
const userAgent = headers().get("user-agent") || "";
const isMobileDevice = isMobile(userAgent);
return (
<main>
<div className="border-b flex">
<div className="flex w-full">
<Sidebar menu={menu} />
{!isMobileDevice && <Sidebar menu={menu} />}
<div className="container pt-[60px] min-h-[calc(100vh-225px)] break-words">
<Breadcrumb menu={menu}></Breadcrumb>
<Suspense fallback={<Loading />}>{children}</Suspense>
Expand Down
44 changes: 38 additions & 6 deletions app/wiki/[...id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import { FormLoading } from "@/components/form-loading";
import { DateModified } from "@/components/date-modified";
import { Admin } from "@/components/admin";
import { NodesData } from "@/services/larkServices";

import { headers } from "next/headers";
import { isMobile } from "../../../lib/isMobile";
import { Collapse, ConfigProvider } from "antd";
interface Props {
params: {
id: string[];
Expand Down Expand Up @@ -59,10 +61,21 @@ export default async function Document({ params }: Props) {

console.log("revalidating", id, docx_token);
}

const userAgent = headers().get("user-agent") || "";
const isMobileDevice = isMobile(userAgent);
const contentItems = [
{
key: "1",
label: "On this page",
children: <TableOfContents allItems={data} />,
},
];
const ifShowCollapse = data.filter(i =>
[3, 4, 5, 6, 7, 8, 9, 10, 11].includes(i.block_type)
).length;
return (
<main className="flex overflow-x-hidden">
<div className="w-2/3">
<main className="flex overflow-x-hidden flex-col-reverse sm:flex-row">
<div className="sm:w-2/3 w-full">
{data?.map((item: AnyItem) => (
<Renderer
key={item.block_id}
Expand All @@ -83,8 +96,27 @@ export default async function Document({ params }: Props) {
</form>
</Admin>
</div>
<aside className="w-1/3">
<TableOfContents allItems={data} />
<aside className="sm:w-1/3 w-full">
{isMobileDevice ? (
ifShowCollapse ? (
<ConfigProvider
theme={{
components: {
Collapse: {
contentPadding: "2px",
},
},
}}
>
<Collapse
className="wiki-collapse-container !mb-4"
items={contentItems}
></Collapse>
</ConfigProvider>
) : null
) : (
<TableOfContents allItems={data} />
)}
</aside>
</main>
);
Expand Down
68 changes: 0 additions & 68 deletions components/Header.tsx

This file was deleted.

18 changes: 18 additions & 0 deletions components/Header/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.home-drawer-content {
a {
color: black;
}
}
.wiki-drawer-content {
.ant-menu-inline {
width: 100% !important;
border-inline-end: 0 !important;
}
}
.ant-drawer {
.header-drawer-container {
.ant-drawer-body {
padding: 10px;
}
}
}
Loading