|
1 | 1 | "use client"; |
2 | | - |
3 | | -import { Tab, Tabs } from "@mui/material"; |
4 | 2 | import { useState } from "react"; |
5 | | -import { NavigateByAuthState } from "~/components/common/NavigateByAuthState"; |
6 | | -import Matchings from "~/components/match/matching"; |
7 | | -import Requests from "~/components/match/requests"; |
8 | 3 |
|
9 | | -export default function Friends() { |
10 | | - const [open, setOpen] = useState(0); |
| 4 | +// https://nextjs.org/docs/messages/react-hydration-error#solution-2-disabling-ssr-on-specific-components |
| 5 | +import dynamic from "next/dynamic"; |
| 6 | +const NoSSRMatchings = dynamic(() => import("~/components/match/matching"), { |
| 7 | + ssr: false, |
| 8 | +}); |
| 9 | +const NoSSRRequests = dynamic(() => import("~/components/match/requests"), { |
| 10 | + ssr: false, |
| 11 | +}); |
11 | 12 |
|
12 | | - const handleChange = (_event: React.SyntheticEvent, newOpen: number) => { |
13 | | - setOpen(newOpen); |
14 | | - }; |
| 13 | +export default function Friends() { |
| 14 | + const [activeTab, setActiveTab] = useState("matching"); |
15 | 15 |
|
16 | 16 | return ( |
17 | | - <NavigateByAuthState type="toLoginForUnauthenticated"> |
18 | | - <div className="fixed z-50 w-full border-gray-200 border-b-[1px] bg-white"> |
19 | | - <Tabs value={open} onChange={handleChange} variant="fullWidth"> |
20 | | - <Tab label="マッチ中" {...a11yProps(0)} sx={{ width: "50%" }} /> |
21 | | - <Tab label="リクエスト" {...a11yProps(1)} sx={{ width: "50%" }} /> |
22 | | - </Tabs> |
23 | | - </div> |
24 | | - <div className="absolute top-9 right-0 left-0 overflow-y-auto"> |
25 | | - <TabPanel open={open}> |
26 | | - {open === 0 ? <Matchings /> : open === 1 ? <Requests /> : null} |
27 | | - </TabPanel> |
| 17 | + <div className="w-full"> |
| 18 | + <div className="flex w-full border-gray-200 border-b"> |
| 19 | + <button |
| 20 | + type="button" |
| 21 | + className={`relative flex-1 py-2 text-center ${ |
| 22 | + activeTab === "matching" ? "text-primary" : "text-gray-600" |
| 23 | + }`} |
| 24 | + onClick={() => setActiveTab("matching")} |
| 25 | + > |
| 26 | + <span>マッチ中</span> |
| 27 | + {activeTab === "matching" && ( |
| 28 | + <span className="absolute bottom-0 left-0 h-1 w-full bg-primary" /> |
| 29 | + )} |
| 30 | + </button> |
| 31 | + |
| 32 | + <button |
| 33 | + type="button" |
| 34 | + className={`relative flex-1 py-2 text-center ${ |
| 35 | + activeTab === "request" ? "text-primary" : "text-gray-600" |
| 36 | + }`} |
| 37 | + onClick={() => setActiveTab("request")} |
| 38 | + > |
| 39 | + <span>リクエスト</span> |
| 40 | + {activeTab === "request" && ( |
| 41 | + <span className="absolute bottom-0 left-0 h-1 w-full bg-primary" /> |
| 42 | + )} |
| 43 | + </button> |
28 | 44 | </div> |
29 | | - </NavigateByAuthState> |
30 | | - ); |
31 | | -} |
32 | 45 |
|
33 | | -function TabPanel({ |
34 | | - open, |
35 | | - children, |
36 | | -}: { |
37 | | - open: number; |
38 | | - children: React.ReactNode; |
39 | | -}) { |
40 | | - return ( |
41 | | - <div |
42 | | - // role="tabpanel" // FIXME: biome says it should not be a div, but I couldn't find a proper html elem |
43 | | - id={`tabpanel-${open}`} |
44 | | - aria-labelledby={`tab-${open}`} |
45 | | - > |
46 | | - <div>{children}</div> |
| 46 | + {/* コンテンツ部分 */} |
| 47 | + <div className="mt-4 text-center text-gray-700 text-lg"> |
| 48 | + {activeTab === "matching" ? <NoSSRMatchings /> : <NoSSRRequests />} |
| 49 | + </div> |
47 | 50 | </div> |
48 | 51 | ); |
49 | 52 | } |
50 | | - |
51 | | -function a11yProps(index: number) { |
52 | | - return { |
53 | | - id: `tab-${index}`, |
54 | | - "aria-controls": `tabpanel-${index}`, |
55 | | - }; |
56 | | -} |
0 commit comments